Another Glue Python Framework - MNML

Although still a big fan of Django, but for some problems I’m finding more and more cases where I prefer less code and more freedom. My biggest issue for some types of problems being Django’s assumption that you’ll be using a relational database, or a database at all. Django wasn’t the reason I started using webapp for App Engine stuff, but in doing so I found that webapp often did all that I needed.

So when I small, non appengine project cropped up I started looking at the different options available and played with a few of them.

So, I set about forking MNML to create my own branch. I added extra comments as I was making my way through the code, wrote a few tests to checks thinks worked and allowed for pluggable routing mechanisms. MNML applications look a bit like the following:

pre. from mnml import RegexBasedApplication, RequestHandler, HttpResponse, development_server class HelloWorld(RequestHandler): def GET (self): return HttpResponse(”

Hello World

“) routes = ( (r’^/$‘, HelloWorld), ) application = RegexBasedApplication(routes) if name == ‘main‘: development_server(application)

If you want to use the token based routing you would substitute in something like the following:

pre. routes = ( (‘/’, Foo), (‘/myview/:stuff/‘, Bar) ) application = TokenBasedApplication(routes)

The best bit is that it’s only about 350 lines of code, a great deal of which is accounted for by comments. It’s also really quite fast - especially using something like spawning to run the WSGI application. The other thing I like is the ease with which you can add WSGI middleware into the mix.

So, if you have a small scale problem where simple and fast beats everything else then have a look and let me know what you think. It will take less time to read the code and tests than it will be read the introductory chapter on whichever larger framework you choose to look at.