Print

Using PySOAP

by Cameron Laird
06/14/2001

You don't have to become expert in XML to use SOAP. For most programmers, SOAP is just a technique for distributed computing. You write a function call on your computer here, and it retrieves a result from a computation there, on a server perhaps half a world away.

With well under an hour of installation and practice, you can learn to write distributed Python programs using SOAP to exchange services and results from programs written in almost any language.

Compared to other distributed programming tools like DCOM or CORBA (or, more properly, the IIOP which transports CORBA,) SOAP is

  • platform-neutral,
  • computing language-independent, and
  • Unicode-ready.

For example, you might use SOAP and Python to write an application for your handheld computer that retrieves data from a mainframe using Cobol. SOAP translates the details of computing language, hardware, and even human-language encoding. Russian-language words appear in proper Cyrillic, and so on.

A growing number of Python programmers are using SOAP. ActiveState Tools Corporation provides product updates using SOAP as a vehicle. Digital Creations Inc.'s Zope is SOAP-enabled. With just a little setup time, you too can experience SOAP's benefits.

Starting with SOAP

Programming with SOAP is easy, but first we must assemble the proper pieces to make SOAP work. In principle, you can use Python 2.0 or later. However, PySOAP depends on the xml.parsers.expat module, which is difficult to install correctly. Installing the Windows binary for Python2.1 final is the easiest way to get PySOAP running. If you work from sources, you'll need expat 1.1 or later.

Once you are able to

import xml.parsers.expat

you're ready to download PySOAP from Sourceforge. For this tutorial, I used version 0.9.5. Unpack it into a local directory, and copy the *.py sources into a standard library location as appropriate. On a Unix-like machine, for example, you might

cp SOAPpy095/SOAP.py /usr/local/lib/python2.0/SOAP.py

This makes SOAP available to all Python2.0 developers on your host. Under Windows you'd want

copy SOAPpy095\SOAP.py \python2.1\lib

Now you're ready to exercise SOAP. Run

import SOAP
  # XMethods.net provides several interesting SOAP
  # services.  See the references below for details.
server = SOAP.SOAPProxy(
  "http://services.xmethods.net/soap/servlet/rpcrouter",
  namespace = "urn:xmethods-Temperature")
  # 47978 is Rensselaer's zip (postal) code.
print server.getTemp("47978")

This returns the temperature in Fahrenheit degrees of a small town in northwest Indiana, in the US Mid-West. You have just begun your career as a SOAP programmer.

Pages: 1, 2

Next Pagearrow