Published on (
 See this if you're having trouble printing code examples

Python News

Wrapping Web Service APIs


There are many approaches to writing XML based web services: SOAP, XML-RPC, REST. If all you want to do is use a service, and there is a Python wrapper for it, you might not care what it was written in. Mark Pilgrim's has wrapped the Google SOAP API. Load up his PyGoogle module and google away. The wrapper takes care of the SOAP for you.

PyGoogle comes with an updated version of originally developed by Cayce Ullman and Brian Matthews. "There are several SOAP libraries in various states of non-development," says Pilgrim. "[] had some problems with 2.2 due to some hard to track down changes in the language. I seem to have fixed them for now." Along with, you will need PyXML for its SAX parser and you also want expat.

Other than the problems with, Pilgrim said the wrapper was easy. "The hardest part was getting it to work initially: downloading Google's documentation, looking through the WSDL file, looking through their .NET and Java examples, and trying to reverse engineer for Python. Once I got an answer from the server, the rest was easy. It only took me a couple of hours. I just happened to get there first."

Pilgrim is optimistic that the Google API, and the Amazon XML API -- also announced recently -- are just the tip of the iceberg. He notes that most web services are implemented privately. For example, RedHat is using XML-RPC to provide updates and security fixes. "The RedHat registration and program for checking for security updates, that's all a Python script. They are using the same XML-RPC library I'm using. That's cool, but it's not public. [Web services] are already being used, it's just hidden mostly. The public stuff we see is just the tip of the iceberg."

If you are interested in developing your own web services with Python, you might also want to take a look at Pilgrim's PyWebServices. "PyWebServices is based on an idea that Dave Winer talked about... He was complaining that the sample code he had seen for developing .NET services had too much overhead the developer had to type in and could therefore get wrong. I wanted to see if I could develop a really, really, really lightweight framework for taking an existing Python module, not written to be a service, but just a model, and without any modification to it all, whether we could expose it over XML-RPC, and I did. It's running on my site now. It isn't much, but the point is it doesn't require any overhead per module that you are trying to make available, trying to expose as a web service."

Next on Pilgrim's list for wrapping is wrapping up Dive Into Python, his free, rapid introduction to Python for programmers. He'll finish off a couple of chapters in progress and write another on regular expressions.


Read more Python News columns.

Return to the Python DevCenter.

Copyright © 2009 O'Reilly Media, Inc.