A todo list on Google App Engine… Python
It seems like everyone is getting crazy those days with the availability of Java for Google App Engine. While this is certainly a great addition to the Google cloud computing offering, I remain a bit puzzled on what it means for Java. Indeed:
- lots of libraries and frameworks need to be tweaked to run on GAE
- there is a whitelist for the classes that you can use, which means no threads, no static files for writing and so on
- datastore entries are bound by a 1Mb limit, which means no big uploads in your applications
- the effort to support specifications like JPA is great, yet I doubt it will be easy to port existing JPA-enabled applications over GAE as the persistence in GAE is not based on a relational model (which is not necessarily a bad idea by itself!).
Should you care about GAE / Java? My take is that it is a nice cloud computing offering, but if you choose to use it then you should expect to develop your applications specifically for it. Making hybrid GAE / normal webapps is probably worth too many headaches
People should not forget that GAE first appeared with Python, a great language by itself. The GAE Python framework is quite simple to use, while the view rendering part is based on the elegant Django templates.
Just to break with the massive trend toward playing with GAE / Java, I wrote a stupid todo lists manager with the Python flavor:
- live at http://jpz-todolists.appspot.com/ (works with your Google account)
- code at http://github.com/jponge/pyappenginetodolist/tree/master
Building the application in Python was relatively simple and painless. The only point that annoyed me a bit is the handling of URL mappings, as you need to specify it in your app.yaml and also in your controller class, which sounds like breaking the DRY principle.
The persisted model definition can't be any simpler:
class TodoEntry(db.Model): user = db.UserProperty() text = db.StringProperty()
db.UserProperty() allows to link with a Google Account.
Fetching one user todo entries is simple:
entries = db.GqlQuery("SELECT * FROM TodoEntry WHERE user = :userid", userid=user)
Handling the authentication is also very simple:
def authenticate(self): user = users.get_current_user() if not user self.redirect(users.create_login_url(self.request.uri)) else: return user
One last excerpt: rendering a view through a Django template:
values = { 'userid': user.nickname(), 'entries': entries, 'logout_url': users.create_logout_url(self.request.uri) } tpl = os.path.join(os.path.dirname(__file__), 'todo.html') self.response.out.write(template.render(tpl, values))
Look at the code, it is quite straightforward and easy to understand, so if you already know Python, don't forget that GAE / Python works just great too
Related posts:
- My IzPack todo list for the week
- Python + mod_python: why use PHP again?
- Google should pay more attention to design
- nose: testing in Python made easy
- DecoratorInjector in Python by Yannick

