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

Learn what soap client libraries exist for python, and where is the documentation for them? with practical examples, diagrams, and best practices. Covers python, soap, soap-client development techn...

Python SOAP Client Libraries: A Comprehensive Guide

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

Explore the leading Python libraries for interacting with SOAP web services, understand their features, and find essential documentation to get started.

SOAP (Simple Object Access Protocol) is an XML-based messaging protocol for exchanging structured information in the implementation of web services. While RESTful APIs have gained significant popularity, many legacy systems and enterprise applications still rely on SOAP. For Python developers, several robust libraries facilitate SOAP client interactions, allowing you to consume and integrate with these services effectively. This article will guide you through the most prominent Python SOAP client libraries, their key features, and where to find their documentation.

Understanding SOAP Communication Flow

Before diving into specific libraries, it's helpful to visualize the typical SOAP communication process. A client sends a SOAP request (an XML message) to a server, which processes the request and returns a SOAP response (also an XML message). This interaction often involves WSDL (Web Services Description Language) files, which describe the operations offered by a web service, their parameters, and return types. Python SOAP clients typically use WSDL to generate proxy objects or methods that simplify calling remote functions.

sequenceDiagram
    participant Client
    participant Server

    Client->>Server: HTTP POST (SOAP Request)
    Note over Server: Parse SOAP Envelope
    Server->>Server: Process Request (e.g., call internal method)
    Server->>Client: HTTP 200 OK (SOAP Response)
    Note over Client: Parse SOAP Envelope
    Client->>Client: Process Response Data

Typical SOAP client-server communication flow

Two libraries stand out as the most widely used and well-maintained options for SOAP client development in Python: suds-py3 and zeep. Both offer comprehensive features, but they approach WSDL parsing and API design differently.

1. Zeep: Modern and Robust

zeep is a modern, Python 3 native SOAP client that aims to be simple to use and robust. It fully supports WSDL 1.1 and 2.0, WS-Addressing, WS-Security, and more. zeep automatically generates Python classes from your WSDL, making it feel very Pythonic to interact with SOAP services. It's generally recommended for new projects due to its active development and comprehensive feature set.

from zeep import Client

# URL to the WSDL file
wsdl_url = 'http://www.dneonline.com/calculator.asmx?wsdl'

# Create a Zeep client
client = Client(wsdl_url)

# Call a SOAP operation (e.g., 'Add')
result = client.service.Add(10, 5)

print(f"The sum is: {result}")

# You can also inspect available services and operations
# print(client.service._operations)

Basic usage of Zeep to call a SOAP service

Documentation: The official zeep documentation is excellent and can be found at https://docs.python-zeep.org/en/master/. It covers installation, basic usage, advanced features like WS-Security, custom headers, and more.

2. suds-py3: Python 3 Fork of a Classic

suds-py3 is a fork of the original suds library, updated to support Python 3. suds was one of the earliest and most popular SOAP clients for Python 2. suds-py3 maintains much of the original API, making it a good choice if you're migrating a Python 2 suds project or prefer its API style. It also parses WSDL and creates Python objects for service interaction.

from suds.client import Client

# URL to the WSDL file
wsdl_url = 'http://www.dneonline.com/calculator.asmx?wsdl'

# Create a suds-py3 client
client = Client(wsdl_url)

# Call a SOAP operation (e.g., 'Add')
# Note: suds-py3 often requires keyword arguments for operations
result = client.service.Add(intA=10, intB=5)

print(f"The sum is: {result}")

# You can also inspect available services and operations
# print(client.sd().services[0].ports[0].methods)

Basic usage of suds-py3 to call a SOAP service

Documentation: While suds-py3 itself doesn't have a dedicated, comprehensive documentation site separate from the original suds, the original suds documentation is largely applicable for understanding its API. You can find it at https://fedorahosted.org/suds/wiki/Documentation. For suds-py3 specific installation and Python 3 considerations, refer to its PyPI page: https://pypi.org/project/suds-py3/.

Choosing the Right Library

The choice between zeep and suds-py3 often comes down to project requirements and personal preference:

  • For new projects: zeep is generally the recommended choice due to its modern design, active development, and robust feature set for Python 3.
  • For migrating Python 2 suds projects: suds-py3 might offer a smoother transition due to API similarity.
  • For specific WSDL complexities: Sometimes one library handles a particular WSDL better than the other. It's not uncommon to try both if you encounter issues.

Both libraries provide mechanisms for handling authentication (e.g., HTTP Basic Auth, WS-Security), custom headers, and logging, which are crucial for real-world SOAP integrations.