Monday, July 13, 2009

Google-App-Engine-Django Tutorial, Part 1 - Background

So, you decided to join the latest buzz train going to the cloud, and check out Google App Engine (GAE from now on). In this post I'll try to demonstrate how to develop an GAE application using Python, the Django framework (or a subset of), Google App Engine SDK, And Google App engine Django helper.

I did the development for the write-up on an Ubuntu Linux machine so some of the instructions are specific to that environment. Most of them are easily translatable to other platforms.

The Players


Googe App Engine


Google App engine allows you to run web applications written in selected languages on Google's servers cloud. You are also provided with some API for using other google infrastructure: A Data Store (which is NOT a relational database, but on most applications will play the database role), Mailer, MemCache, etc.
It's important to understand that GAE is not like setting up you own physical or virtual server, be it your own servers, or a virtualization service like Amazone EC2. With programming to use GAE off the shelf scalability, you're being limited to:

  • Using the targeted runtimes: For now it is Python 2.5 or Java bytecode (in Beta)

  • Not installing any software, just upload code (yours and libraries). If your code or libraries have dependencies for things that are not supported by GAE, tough luck. As a result, you have to use GAE stack provided by their API to replace usual components.

  • Not usingg file system writes, opening sockets, spawning and multi-threading, others...


I'll try not to get into the scope of the GAE, there is plenty of information about it on the web.

Python


Python is a dynamic programming language. It's elegant, and it's supported by GAE.

Google App Engine SDK for python


The Python GAE SDK is a set of python libraries and programs that lets you develop your GAE application locally, using a GAE compatible local web server, and manage your application (i.e. uploading it to GAE)

Django


Django is a web framework written in python (and used by writing python code). It's considered an MVC framework, though they changed the common terminology for the Controller and View.
Typically Django runs on a web server (i.e. Apache), and uses a single relational database server (PostgresSQL, MySql).
Many parts of django can't run on GAE, since they rely on Django model, which relies on a relational DB backend, which isn't provided by GAE. Most applications written for django (for example django.contrib.auth, django-registration) won't and can't work on GAE without some very serious modifications to the model.
Still, many parts of it can be used: Its template system, Url Front controller, forms processing, etc. And indeed, GAE currently included and supports out of the box some django components or ports of them: namely the templates and forms.
However, it can be quite complicated to try and run an application based on Django in GAE, even if avoiding the unsupported componenets. And there comes...

google-app-engine-django


google-app-engine-django (let's call it GAE-D, ok?) provides a helper which comes to help with the complication listed below. It provides the following thing:
1) A template for quickly starting a django based GAE application.
2) Classes and Wrappers for some core Django componenets that allows using them on GAE.
3) Modified manage.py, the Django Management utility, adopting it to GAE an extending g it to handle GAE operations which are not part of Django.

Those are the different parts we're going to fit together in order to create a first GAE application. I didn't plan on giving this introduction about GAE, Django, etc, but it happened so. The original plan was just detailing the

On the next post I'll try provide the actual HOW-TO and steps for creating a very basic application. Feeling hungry?

No comments:

Post a Comment