Luchita

Ezra -ez- Nugroho’s blog

REST and Python

Posted on | September 29, 2008 | 16 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:

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:

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:

Further reading:

Good luck!

Comments

16 Responses to “REST and Python”

  1. John
    October 1st, 2008 @ 2:09 pm

    Great resources! I recently wrote an article about writing REST apps with web.py.

  2. jhcore.com » Blog Archive » Getting RESTful with web.py
    October 1st, 2008 @ 6:17 pm

    [...] REST and Python Tags: python, rest, web.py [...]

  3. Mohamed
    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.

  4. ezran
    October 1st, 2008 @ 9:35 pm

    Mohamed,

    Thanks for the correction. The href is corrected now.

  5. Keith Chapman
    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.

  6. Keith Chapman
    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.

  7. ezran
    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.

  8. rascunho » Blog Archive » links for 2008-10-10
    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) [...]

  9. omtv
    November 5th, 2008 @ 8:08 pm

    This is quite a useful guide in doing restful python service.
    Thanks for sharing.

  10. Pau Aliagas
    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

  11. Martin
    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

  12. lily
    February 18th, 2010 @ 7:46 am

    newbie in this field…
    What kind of workflow engine you are using?

  13. ezran
    February 19th, 2010 @ 1:45 am

    Try Intalio or Axis2 from WSO

  14. Building Web Services the REST Way | PythonCave Blog
    March 21st, 2012 @ 7:08 am
  15. Confluence: SoftServe - IT Academy
    January 9th, 2013 @ 5:47 am

    Topic 4. Network programming…

    Python. Networking programming REST Python and RES…

  16. REST and Python | Ansible
    September 29th, 2013 @ 12:41 am

Leave a Reply





*