Glashammer, an alternative framework on Google AppEngine

In his blog, on Friday, August 29, 2008, Johnathan talked about Google AppEngine, and said

the "you can use any web framework you like, as long as it's django" attitude


That may have been true then, it probably isn't true now. Glashammer have been working for the last few weeks on getting the Glashammer framework of Werkzeug and Jinja2 running and easy on Appengine.

Firstly this wasn't hard. Glashammer is very free about what kind of data storage you use, so using Appengine's DataStore was straightforward. Some utility functions for running easily, add a few decorators for controlling what happens for authentication form redirection to limit views for certain users and we are pretty much done.

They have additionally tried to make it easier to install with a little script to get us started. So (since it seems a good start):

gh-admin quickstart_gae


This will generate a starter AppEngine + Glashammer application that is ready to go. It will also fetch all the dependencies for you and build them in the right places in your application for uploading to AppEngine. Now you can deal with that bit yourself with:

gh-admin quickstart_gae nodeps


You will be asked the name of the project directory, and this directory will be created. Within this directory, Glashammer will create components necessary for the application to be both a Glashammer application, and an AppEngine application.

These include an app.yaml with the necessary rules for static files, in the shared directory (handled by AppEngine) and the remaining paths to the WSGI Application built in main.py and the templates directory (handled by Glashammer).

At this point, I should probably just refer you to the respective documentations of Glashammer and AppEngine, but I can't resist a little teaser.

Let's have a look at the generated main.py module:

from glashammer import make_app
from glashammer.bundles import gae

TEMPLATES_DIRECTORY = 'templates'

# Main application setup
def setup(app):
    # add the gae init function
    app.add_setup(gae.setup_gae)

    # setup templates
    app.add_template_searchpath(TEMPLATES_DIRECTORY)

def main():
    gae.make_and_run_gae_app(setup)

if __name__ == '__main__':
    main()


That application doesn't actually do anything, because there are no rules for views, but we could add one:

from glashammer import Response

def do_home(request):
    return Response('Hello World')


and then add it in our application setup function:

def setup(app):
    ...
    app.add_url('/', 'main/index', do_home)


And we have a simple Hello World application.

You can use different components from Glashammer and Appengine, and sometimes you can even choose which bits you want from each. For example, I like using Glashammer's Sessions and Memcached interface, but AppEngine's Django forms.

The real advantages are in having Jinja2 along with hooks to add template filters and globals is ready to go, and Werkzeug with its lovely API. For me, this feels much nicer than the provided API in AppEngine.

There are no monkey-patches or other trickery and all dependencies run out of the box. And since it was released today, roll on over and grab it at http://glashammer.org/downloads.html.

Popular posts from this blog

PyGTK, Py2exe, and Inno setup for single-file Windows installers

ESP-IDF for Arduino Users, Tutorials Part 2: Delay

How to install IronPython2 with Mono on Ubuntu