What Soap Client Libraries Exist for Python, and Where Is the Documentation for Them

What SOAP client libraries exist for Python, and where is the documentation for them?

Update (2016):

If you only need SOAP client, there is well maintained library called zeep. It supports both Python 2 and 3 :)


Update:

Additionally to what is mentioned above, I will refer to Python WebServices page which is always up-to-date with all actively maintained and recommended modules to SOAP and all other webservice types.


Unfortunately, at the moment, I don't think there is a "best" Python SOAP library. Each of the mainstream ones available has its own pros and cons.

Older libraries:

  • SOAPy: Was the "best," but no longer maintained. Does not work on Python 2.5+

  • ZSI: Very painful to use, and development is slow. Has a module called "SOAPpy", which is different than SOAPy (above).

"Newer" libraries:

  • SUDS: Very Pythonic, and easy to create WSDL-consuming SOAP clients. Creating SOAP servers is a little bit more difficult. (This package does not work with Python3. For Python3 see SUDS-py3)

  • SUDS-py3: The Python3 version of SUDS

  • spyne: Creating servers is easy, creating clients a little bit more challenging. Documentation is somewhat lacking.

  • ladon: Creating servers is much like in soaplib (using a decorator). Ladon exposes more interfaces than SOAP at the same time without extra user code needed.

  • pysimplesoap: very lightweight but useful for both client and server - includes a web2py server integration that ships with web2py.

  • SOAPpy: Distinct from the abandoned SOAPpy that's hosted at the ZSI link above, this version was actually maintained until 2011, now it seems to be abandoned too.
  • soaplib: Easy to use python library for writing and calling soap web services. Webservices written with soaplib are simple, lightweight, work well with other SOAP implementations, and can be deployed as WSGI applications.
  • osa: A fast/slim easy to use SOAP python client library.

Of the above, I've only used SUDS personally, and I liked it a lot.

python soap client library

The server's WSDL schema seems to be broken - it references named objects without importing them.

See the suds documentation on fixing broken schemas on how to work around that with suds.

Also see this question for more details.

This seems to work for me:

from suds.xsd.doctor import Import
from suds.xsd.doctor import ImportDoctor
from suds.client import Client

url = 'https://personyze.com/site/service/service/social_archive/'
tns = 'urn:SocialArchiveServiceProviderwsdl'

imp = Import('http://schemas.xmlsoap.org/soap/encoding/', 'http://schemas.xmlsoap.org/soap/encoding/')
imp.filter.add(tns)
client = Client(url,plugins=[ImportDoctor(imp)])

print client.service.select({"server_id":123456, "api_key":123456}, "user_id")

Which python SOAP libraries are still maintained?

TL;DR:

zeep is in PyPi with docs here

Long answer:

I was going to post an updated request as of 2016 as it looks like some of the above have now also dropped off the radar.

According to Python WebServices there are a number of SOAP clients:

ZSI (Zolera Soap Infrastructure) - a version of the actively maintained Python Web Services project; ZSI-2.0 Released on 2007-02-02 provides both client and server SOAP libraries. Newly added was proper WSDL consumption of complex types into python classes.

soaplib - Soaplib is an easy to use python library for writing and calling soap web services. Webservices written with soaplib are simple, lightweight, work well with other SOAP implementations, and can be deployed as WSGI applications.

suds - Suds is a lightweight SOAP python client that provides a service proxy for Web Services.

pysimplesoap - PySimpeSoap is a simple and functional client/server. It goals are: ease of use and flexibility (no classes, autogenerated code or xml is required), WSDL introspection and generation, WS-I standard compliance, compatibility (including Java AXIS, .NET and Jboss WS). It is included into Web2Py to enable full-stack solutions (complementing other supported protocols as XML_RPC, JSON, AMF-RPC, etc.).

osa - osa is a fast/slim easy to use SOAP python client library.

Ladon Ladon is a multiprotocol approach to creating a webservice. Create one service and expose it to several service protocols including SOAP. Unlike most other Python based SOAP Service implementations Ladon dynamically generates WSDL files for your webservices. This is possible because the parameter types for each webservice method are defined via the ladonize decorator. Furthermore it should be mentioned that Ladon offers python 3 support.

zeep - Zeep is a modern (2016) and high performant SOAP client build on top of lxml and requests. It's compatible with Python 2 and 3.

As of writing this (late 2016) most of these seem to be outdated (only supporting up to SOAP1.1) and, going by commit history, have not been maintained since 2015 or even far earlier. This goes especially for ZSI, osa and suds.

The sole exception seems to zeep, which is actively maintained as of late 2016, offers SOAP1.2 support (and across all Python versions) - and at least in my case, worked perfectly out of the box from the moment I threw some WSDL at it.

UPDATE: While I don't plan on going back and editing this page constantly (I'd invite the author of zeep to do so), I wanted to add that 2 years after my last update zeep is still very actively maintained, with the latest commit December 2018. It supports Python up to 3.7 and is currently in version 3.2.0 (having left the 0.x pre-release versioning a long time ago). It's still my primary library on those rare occasions when I have to use XML-SOAP instead of REST.

zeep is in PyPi with docs here

Python and SOAP

As for a SOAP client, my personal favourite is SUDS https://fedorahosted.org/suds/. It is very Pythonic and easy to use. Also you don't need to generate any code making it very useful for testing.

A simple example from its documentation (https://fedorahosted.org/suds/wiki/Documentation):

from suds.client import Client
url = 'http://localhost:7080/webservices/WebServiceTestBean?wsdl'
client = Client(url)

Now you can simply use client to call services. For instance in order to call getPercentBodyFat service (in the test case):

result = client.service.getPercentBodyFat('jeff', 68, 170)
print result

For more information about different SOAP libraries for Python, please see question 206154

What's the best python soap stack for consuming Amazon Web Services WSDL?

The REST or "Query" APIs are definitely easier to use than SOAP, but unfortunately at least once service (EC2) doesn't provide any alternatives to SOAP. As you've already discovered, Python's existing SOAP implementations are woefully inadequate for most purposes; one workaround approach is to just generate the XML for the SOAP envelope/body directly, instead of going through an intermediate SOAP layer. If you're somewhat familiar with XML / SOAP, this isn't too hard to do in most cases, and allows you to work around any particular idiosyncrasies with the SOAP implementation on the other end; this can be quite important, as just about every SOAP stack out there has its own flavour of bugginess / weirdness to contend with.

Python SOAP Client - use SUDS or something else?

While there isn't a certified standard, if you must use SOAP, Suds is your best choice. Suds can be slow on large WSDLs, and that is something they are working on.

In the meantime, if you don't expect your WSDL to change often, you have two options that can buy you a lot of speed:

  1. Downloading your WSDL to localhost
  2. Using caching

Downloading your WSDL

With large WSDLs part of the problem is that first you must download the WSDL every time, which can add overhead. Suds will take the time to download and parse the entire WSDL on startup to make sure that it hasn't changed.

If you can download it to the local system and then pass it to the Client constructor using a file:// scheme in the URL. Since Suds uses urllib2 for the HTTP transport, this is perfectly legit.

Now, because you're not providing a hostname in your WSDL URL, you will also have to pass a location argument specifying the actual URL of the SOAP application.

Here is an example:

from suds.client import Client

# The service URL
soap_url = 'http://myapp.example.notreal/path/to/soap'

# The WSDL URL, we wont' use this but just illustrating for example. This
# would be the file you download to your system and save as wsdl_file
wsdl_url = 'http://myapp.example.notreal/path/to/soap?wsdl'

# The full path to the downloaded WSDL file on your local system
wsdl_file = '/path/to/myapp.wsdl'
wsdl_url = 'file://' + wsdl_file # Override original wsdl_url

client = Client(url=wsdl_url, location=soap_url)

If you're interested, I have used this approach in my work and have open sourced the code.

Caching your WSDL

The other option is to use Suds' excellent caching feature. You must explicitly create a cache object and then pass that to the constructor using the cache argument. Otherwise it defaults to an ObjectCache with a duration of 1 day.

You might also consider using both of these approaches.

Python Web Services

I'd recommend suds. It is very simple and easy to use.


Simple example:

from suds.client import Client

url = 'http://localhost:7080/webservices/WebServiceTestBean?wsdl'
client = Client(url)
result = client.service.MyMethod(args)

For more examples / tutorial see their documentation page..



Related Topics



Leave a reply



Submit