views:

896

answers:

7

I'd like to write a python library to wrap a REST-style API offered by a particular Web service. Does anyone know of any good learning resources for such work, preferably aimed at intermediate Python programmers?

I'd like a good article on the subject, but I'd settle for nice, clear code examples.

CLARIFICATION: What I'm looking to do is write a Python client to interact with a Web service -- something to construct HTTP requests and parse XML/JSON responses, all wrapped up in Python objects.

A: 

This article might help http://www.ibm.com/developerworks/linux/library/l-wrap/ - its about creating interfaces to library C code, but the principles can be applied.

Python extensions in C++ might also help, this might help get you started: http://www.geocities.com/foetsch/python/extending_python.htm

xan
+1  A: 

I can't point you to any article on how to do it, but I think there are a few libraries that can be good models on how to design your own.

PyAws for example. I didn't see the source code so I can't tell you how good it is as code example, but the features and the usage examples in their website should be a useful design model

Universal Feed Parser is not a wrapper for a webservice (it's an RSS parser library), but it's a great example of a design that prioritizes usage flexibility and hiding implementation details. I think you can get very good usage ideas for your wrapper there.

Ricardo Reyes
feedparser looks nice, indeed.
J.F. Sebastian
A: 

My favorite combination is httplib2 (or pycurl for performance) and simplejson. As REST is more "a way of design" then a real "protocol" there is not really a reusable thing (that I know of). On Ruby you have something like ActiveResource. And to be honest, even that would just expose some tables as a webservice, whereas the power of xml/json is that they are more like "views" that can contain multiple objects optimized for your application. I hope this makes sense :-)

Koen Bok
Correct, there's nothing reusable, because REST is an architecture.
Wahnfrieden
+1  A: 

This tutorial page could be a good starting place (but it doesn't contain everything you need).

A: 

You should take a look at PyFacebook. This is a python wrapper for the Facebook API, and it's one of the most nicely done API's I have ever used.

Dan Lorenc
A: 

It would help to know about the service API you want to interface with. You say "REST-style" but that can mean many things these days, since almost no one actually means REST when they say it. The way you'd consume a real REST API is very different from the much more common RPC APIs.

Wahnfrieden
A: 

You could checkout pythenic jobs, a nice, simple, but well-formed "Python wrapper around the Authentic Jobs ... API" as a good example. That's what I'm doing now :)

Christopher Scott