Friday, April 18, 2008

Experiments and thoughts on Google App Engine

I have been experimenting with the Google App Engine (GAE) recently which is a Google hosted Python application server. I am not a native Python programmer (I've written about 5 scripts in my life). Even so, GAE is a great toy to play with.

Python on GAE

There are currently some weaknesses in the implementation of Python available in GAE (re: C libraries, XML parsers, XSLT engines) but this is a preview release and all things considered it is a very impressive offering. Why Python? We are told that "Google are huge fans of Python" and it is evidently used extensively inside Google. One of Google's other "hosted" platforms, Google's Mashup Editor, is a JavaScript application server running on top of Java, so Google obviously have experience in the Java application server area. As a Java programmer, I would get more excited if I could upload WAR files to GAE (even if I had to use proprietary Google Java APIs for some things) but you can't win them all. You never know, Java support could be just around the corner.

I'm new to writing Python web applications and so far it reminds me of writing Perl CGI code. This is not the best way to write web applications and I miss JSP at this point. There must be better ways of doing this using wsgiref and the Django framework which come pre-installed in GAE. These may help me get around the "scriptyness" of my python web application programming. My writing simple python web applications experience has surprised me somewhat as I had been drip fed with the idea that Python was a more efficient language (and hence better!) than Java/JSP (but I suspect I'm not doing it right!). So far it seems that you have to write a lot more Python code than the equivalent in JSP e.g. to get a parameter from an URL:

Python version

from cgi import parse_qs, escape

def hello_world(environ, start_response):
parameters = parse_qs(environ.get('QUERY_STRING', ''))
if 'subject' in parameters:
subject = escape(parameters['subject'][0])
subject = 'World'
start_response('200 OK', [('Content-Type', 'text/html')])
return ['''Hello %(subject)s

Hello %(subject)s!

''' % {'subject': subject}]

JSP version

Hello ${empty param.subject ?  'World' : param.subject}

To be absolutely honest, I have never liked the conditional expression tenary operator (e.g '?' above) syntax and in this case I would prefer something more verbose but this illustrates the potential efficiency inherent in contemporary JSP.

Datastore on GAE

In GAE you are given access to a datastore, although this is not a relational database but an instance of Google's BigTable database. To access this database there is an SQL-like language called GQL available. We are told that the Datastore API is modelled after Django's Database API.

Worries about using GAE as a commercial platform?

If I were a business with an interest in using GAE commercially, storing my valuable data in proprietary Google storage would worry me somewhat. There are open source versions of BigTable available (e.g. HBase, HyperTable) and these owe there existence to Google but as there is not yet a standard "GQL" mechanism, data exit strategies seem limited.

I would be greatly concerned that my applications are hosted by Google and that my Python developers were exposed to Google. GAE could be described as a lobster pot. Getting Google to host your business means that Google are in a prime position to absorb successful businesses, steal talented developers, learn more about your business quicker than you can yourself and learn from your mistakes.

Some fun stuff, an example Google App Engine app

Using GAE, Mark Pilgrim's Universal Feed Parser code and the JavaScript library I have cobbled together a fun example.

See how Google use the domain which is like, nice! I look forward to wikispot etc.

Access the source code here:
Main script:
Download the full app:

I am still having some caching problems, please help!