REST and Python
Posted on | September 29, 2008 | 15 Comments
As I mentioned here, recently I’ve been doing some research in REST. Specifically, I’ve been looking for ways to implement REST web services for some of our Python-based routines. The idea is to do it in a way that is describable in a WSDL, so that we can control that from a workflow engine in the future.
If you are more or less in the same boat, here is some recommendations to ease your research.
First, read the basics:
- How to Create a REST Protocol – MUST READ
- Building Web Services the REST way – Nice tutorial
- Common REST mistakes
- Yahoo’s example for consuming REST services – Has some implementation concepts that would help you understand how to consume services.
You’d need to find out if you just need to publish your services, or if you also need to consume other people’s services, or both. Yahoo’s guide is really good in showing how you’d consume Yahoo’s (and others) services, while the other two guides explain how to publish.
For us, we need to both publish and consume services. We have decided to implement our producer part of it (the web services provider) using Pylons. Here are Pylons essentials to create RESTfull services:
- Routes Manual, the routing system of Pylons
- Pylons REST decorators – How to map different HTTP verbs to different actions
If frameworks is to limiting, and you would like to roll your own REST publishing engine, look at the following:
- Selector – A python WSGI routing system
- Yaro – A simple but non-restrictive WSGI abstractor for end user
To implement the client part, read the following:
- Httplib2 project page
- Httplib2 reference library
- URLlib2 documentation
- Python-rest-client project page
Further reading:
- A very thorough guide on Python HTTP Web Services, from ‘Dive into Python’
- Web Services Essentials: Chapter 6: WSDL Essentials“
- REST Web Services Security Resources
- Nice presentation about REST security. Do not skip!!
Good luck!
Comments
15 Responses to “REST and Python”
Leave a Reply

October 1st, 2008 @ 2:09 pm
Great resources! I recently wrote an article about writing REST apps with web.py.
October 1st, 2008 @ 6:17 pm
[...] REST and Python Tags: python, rest, web.py [...]
October 1st, 2008 @ 7:15 pm
The href for A very thorough guide on Python HTTP Web Services, from ‘Dive into Python’
is wrong. Thanks for the article.
October 1st, 2008 @ 9:35 pm
Mohamed,
Thanks for the correction. The href is corrected now.
October 2nd, 2008 @ 9:09 pm
I’m not familiar with Pylons ,can it generate a WSDL for you?
Recently we (WSO2) released an alpha version of a Web Services Framework for Jython (WSF/Jython). As of not it does not support REST (its a open source project and we would like people getting involved with it) but its a trivial feature to add. I guess you’ve already seeing how we could do <a href=”http://www.keith-chapman.org/2008/09/restfull-mashup-with-wsdl-20-wso2.html”REST services with Javascript on the WSO2 Mashup Server. We could easily do something similar to this.
BTW we would generate both a WSDL 1.1 and WSDL 2.0 for you too.
October 2nd, 2008 @ 9:09 pm
I’m not familiar with Pylons ,can it generate a WSDL for you?
Recently we (WSO2) released an alpha version of a Web Services Framework for Jython (WSF/Jython). As of not it does not support REST (its a open source project and we would like people getting involved with it) but its a trivial feature to add. I guess you’ve already seeing how we could do REST services with Javascript on the WSO2 Mashup Server. We could easily do something similar to this.
BTW we would generate both a WSDL 1.1 and WSDL 2.0 for you too.
October 8th, 2008 @ 12:19 pm
Keith,
Pylons is really a web framework, not a web-services framework.
It doesn’t generate any WSDL, so we would have to generate our own.
October 10th, 2008 @ 1:05 pm
[...] REST and Python | Luchita Specifically, I’ve been looking for ways to implement REST web services for some of our Python-based routines. (tags: http://www.ezran.org 2008 mes9 dia10 REST Python lista_de_links) [...]
November 5th, 2008 @ 8:08 pm
This is quite a useful guide in doing restful python service.
Thanks for sharing.
December 5th, 2008 @ 3:29 pm
I’ve been checking many clients and they are really simple, as can be seen in the -yahoo link provide above,
I liked particularilly these ones:
1. http://microapps.sourceforge.net/restclient/
2. http://code.google.com/p/python-rest-client
3. http://pypi.python.org/pypi/z3c.rest/0.2.5
They all provide more or less the same, mainly 1 and 2, but 1 seemed a little more mature, although they all were ok.
I hope it helps.
Pau
May 5th, 2009 @ 2:08 am
Hi all,
I started using web.py for programming web services and, although I’m
quite happy with the framework, I couldn’t find an out-of-the-box
solution for what I was looking for. More specifically, I wanted to
select the appropriate representation for the service’s resources in a
RESTful way, i.e. using the HTTP Accept header.
I didn’t like this:
class hello:
def GET(self, name):
if not name: name = ‘world’
message = ‘Hello, %s!’%name
accept_string = web.ctx.env['HTTP_ACCEPT']
mime = find_best_supported_mime(accept_string)
if mime==’application/html’:
return render_html.hello(message)
elif mime==’application/xml’:
return render_xml.hello(message)
elif mime==’application/json’:
return render_json(message)
else:
raise web.internalerror(‘no representation for “%s”‘%mime)
So I made it like this:
@mimerender.represent(
html = render_html.hello,
xml = render_xml.hello,
json = render_json)
def GET(self, name):
if not name: name = ‘world’
message = ‘Hello, %s!’%name
return {‘message’: message}
I’ve made the library open-source and posted it at http://code.google.com/p/mimerender
Hope you find it useful.
Cheers!
Martín
February 18th, 2010 @ 7:46 am
newbie in this field…
What kind of workflow engine you are using?
February 19th, 2010 @ 1:45 am
Try Intalio or Axis2 from WSO
March 21st, 2012 @ 7:08 am
[...] http://www.ezran.org/blog/2008/09/rest-and-python/ [...]
January 9th, 2013 @ 5:47 am
Topic 4. Network programming…
Python. Networking programming REST Python and RES…