2010-03-27

Python web framework of the day

Since there are quite a lot of web application frameworks for Python, I think one more wouldn't hurt.

I was impressed by the compactness of Ruby's Sinatra:

require 'rubygems'
require 'sinatra'
get '/' do
  'Hello world!'
end

My goal was to create something similar for Python, as a proof-of-concept. Here is the equivalent Hello, world web application with my Python syntax:

from wfotd import *
@GET
def _():
  return 'Hello world!'

The Ruby solution looks much more clear and beautiful. Nevertheless, it was a nice Python coding experiment. I named it PYthon Web Framework Of The Day. The source is available at http://code.google.com/p/pts-mini-gpl/source/browse/#svn/trunk/pywfotd.

Here is a larger Python example, demonstrating the scoping and argument passing features of pywfotd:

from wfotd import *
@GET
def _(name=None):
  name = name or 'World'
  return 'Hello, %s!' % name

@GET
def foo():
  return 'This is /foo'

class bar:
  class baz:
    @GET
    def _():
      return 'This is /bar/baz'
    @GET
    def quux():
      return 'This is /bar/baz/quux'

No comments: