Ian Bicking: the old part of his blog

Do It Yourself

In response to some of the recent activity around Python web frameworks, and some of the new interest in Paste, I thought it would be helpful to write a document about how you write a framework using WSGI. With RhubarbTart coming in at 302 lines (according to sloccount) I figure it's a pretty reasonable to consider writing your own. But really my hope is that this will make people more comfortable with this architectural style. Even if you don't write your own framework, it's nice to know both that you could write your own framework, and that you can probably understand the framework someone else writes, approaching it piece-by-piece.

So, here's the start: A Do-It-Yourself Framework. I still want to talk about configuration and deployment with Paste Deploy, and about packaging your application with setuptools and using entry points, but this is a good start.

Note that I haven't tested the examples. Bad me. Testing tires me out sometimes.

Created 01 Feb '06


Wow, really nice tutorial. Now you've made me want to look more into Paste :) I found one minor mistake while going throughe the code, environ and next_obj are switched in the recursive call:

def find_object(self, obj, environ):
    return self.find_object(environ, next_obj)
# julien

Thanks for the note; now fixed.

# Ian Bicking

two words: tremendously useful!

# Jan-Wijbrand Kolman

I was reading your post on my rss reader (bloglines) and the link got http://pythnopaste.org/do-it-yourself-framework.html note the pythnopaste. What could be the problem?

# Leonardo

That is most bizarre, since I did not edit the post in any way and didn't make that typo...

# Ian Bicking

Could you frame WareWeb in this context, plus maybe compare it to RhubarbTart?

# Bill Seitz

I finnaly got to work through your tutorial. Its brilliant and really illustrates what WSGI is all about. Instead of your object traversal to locate the correct callable for the path I just used a simple dictionary of path names mapped to callables and then on KeyError just return a 404.

# thakadu