Python Web Frameworks and REST
When I've looked at Web frameworks in the past (not just in Python) I've been disappointed by their lack of a resource-oriented focus.
RESTafarians like myself typically want URIs to map to objects that then simply implement HTTP methods (assuming HTTP is what's being used—REST isn't limited to HTTP).
I was aware of mnot's Tarawa experiment but hadn't seen that sort of approach adopted in any other projects.
In Leonardo, I started down the path of being resource-oriented but it is still somewhat half-assed.
In Demokritos, I wanted it to be a focus from the start. This makes a lot of sense with the Atom Publishing Protocol because APP is really just a subset of HTTP. You have to be able to handle PUT and DELETE verbs, support reading and writing of HTTP headers and be able to return proper HTTP response codes.
(Incidently, my understanding is that something like Ruby on Rails is a bit of disaster in this area.)
Although I haven't released a version with this yet, I've refactored out the general resource-oriented HTTP parts of my Demokritos code. You can take a look in the svn repository at webbase.py for the module and server.py for a specific example of it in use for the Atom Publishing Protocol.
Since I started on Demokritos, web.py has come out. It takes a similar approach, does a bit more (especially in dispatching - where webbase.py currently lacks), but I think I still like webbase.py more.
Very recently, I've started talking to Sylvain Hellegouarch and it sounds like CherryPy might increasingly enable a RESTful approach so there's a possibility at some point that Demokritos could move over to CherryPy (which would probably mean Leonardo would too if Leonardo becomes a layer on top of Demokritos).
In the meantime, check out webbase.py. I welcome feedback on it—especially from other RESTafarian Pythonistas.
UPDATE (2006-02-10): The link to webbase.py above is now incorrect. See pyworks.web.
prev « python » next
prev « atompub » next
prev « leonardo » next
prev « demokritos » next
rest » next
Comments (12)
Sylvain Hellegouarch on Jan. 26, 2006:
CherryPy 3 is currently under brainstorming before being first draft. There some feature we do want such as the ability to change the URL dispatching at will depending on what is required for a given application.
One dispatching rule I do want is the one based on HTTP verbs. So it might take a few months to get there but eventually it will be a built-in :)
- Sylvain
Roman on Jan. 29, 2006:
From my perspective it would be great to have a unified approach to cope with query or filter requests in RESTful Python applications.
Examples:
GET all users that are member of group 'admin' and that have been created before 10/10/2003.
GET all blog entries that match a given fulltext query.
Don't the HTTP verbs lack a verb for search/query/filter?
Doug Winter on Jan. 30, 2006:
Only Zope of the current crop of python app servers would have trouble with RESTful URLs, that I can think - the rest (ha ha) ought to be able to handle them fine?
ToddG on Jan. 30, 2006:
dbt on Jan. 30, 2006:
James Tauber on Jan. 30, 2006:
So instead of /listUsers, /addUser, /deleteUser, /updateUser you have GET /users, POST /users, DELETE /users/[user_id], PUT /users/[user_id]
Andre on Jan. 31, 2006:
James Tauber on Jan. 31, 2006:
Sometimes that can be as simple as understanding the difference between GET and POST. Remember when Google's Web Accelerator came out and broke a bunch of Rails applications?
REST means giving your objects URIs and a uniform interface (such as the one HTTP provides). With a RESTful service built on HTTP, for example, if I know an object's URI, I know how to retrieve the object, I know how to delete it or how to replace it. I can cache it, go through proxies or potentially ask for it in different formats. When things go wrong I get standard error codes. And all of this is without having to know anything specific about the service.
The Atom Publishing Protocol has adopted a RESTful approach. This basically means it only has to do 10% of the work because the other 90% is provided by generic HTTP and the Atom Syndication Format. This also means it's very easy to implement the protocol if you have a good RESTful framework. You'd have to jump through a lot more hoops to implement APP if you're sitting on a framework that doesn't support the RESTful nature inherent in HTTP.
At the very least, implementing something like APP requires a framework that supports PUT and DELETE just as much as GET and POST and a framework that makes returning a 204 or a 201 or a 415 response just as easy as a 200.
Julian Krause on Feb. 13, 2006:
I am currently working on designing a new controller for RhubarbTart that would make creating RESTful resources easier in Python. You would be able to use an object mapping like what CherryPy already does but also put GET, POST, PUT, DELETE, and other methods into the class or attach them onto function names in order to call those functions upon that method being called. I hope you will take a look at it as soon as it is released
James Tauber on Feb. 13, 2006:
c on Aug. 13, 2006:
I was searching for a similar REST + python setup recently. This looks interesting:
http://lukearno.com/projects/selector/
Last Modified: Feb. 9, 2006
Author: jtauber
anders pearson on Jan. 25, 2006:
what i'm using at the moment is my RESTResource mixin, which you can grab out of Tasty's svn (i haven't packaged it up seperately yet, but i plan to): http://tasty.python-hosting.com/file/trunk/tasty/rest_resource.py
it's not perfect but it at least makes it pretty easy to map verbs to methods on resources. i'm not real happy with the API, but i haven't really seen anything else before to compare it with. i plan to take a close look at webbase.py though.