O'Reilly Network     Published on the O'Reilly Network (http://www.oreillynet.com/)
    http://www.onlamp.com/pub/a/python/2002/05/02/pythonnews.html
    See this if you're having trouble printing code examples


Wrapping Web Service APIs

by Stephen Figgins
05/02/2002

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 SOAP.py originally developed by Cayce Ullman and Brian Matthews. "There are several SOAP libraries in various states of non-development," says Pilgrim. "[SOAP.py] 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 SOAP.py, you will need PyXML for its SAX parser and you also want expat.

Other than the problems with SOAP.py, 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.

Stephen Figgins is an editor with the O'Reilly Network and the network's Python DevCenter bureau chief.

Return to Related Articles from the O'Reilly Network .


Library Navigation Links

oreillynet.com Copyright © 2003 O'Reilly & Associates, Inc.