suds (community fork)
Suds is a lightweight SOAP-based web service client for Python. This is a community fork of the `suds-jurko` fork, actively maintained to support modern Python versions (>=3.7). It provides an intuitive RPC-like interface to consume web services by objectifying WSDL-defined types without explicit class generation. The latest version is 1.2.0, released in August 2024, with a release cadence that has seen several updates in recent years.
Warnings
- breaking The `suds` project (version 1.x) is a community fork that explicitly supports Python 3.7+ only. Older versions of `suds` (0.4 and prior) were Python 2.x only. Trying to use this `suds` version with Python 2.x or an older Python 3.x interpreter (e.g., <3.7) will result in compatibility errors. Users migrating from the original `suds` or `suds-jurko` must ensure their Python environment is 3.7 or newer.
- gotcha When dealing with complex WSDL types that are subclasses or extensions of other types, directly passing a Python dictionary to represent these objects may cause issues. `suds` might not correctly infer the `xsi:type`, leading the server to reject the request (e.g., trying to instantiate an abstract base type instead of the concrete subclass).
- gotcha By default, `suds` logging is not verbose. It's common to miss crucial debug information (like the actual SOAP request/response XML or HTTP headers) when troubleshooting issues with web service calls.
- breaking Version 0.8.0 introduced a change where objects are no longer instantiated with empty optional attributes by default. This changes the behavior from previous versions where such attributes might have been present as empty lists or `None` without explicit definition.
- gotcha Many WSDLs or their imported schemas can be malformed or follow incorrect import rules, causing `suds` to fail during WSDL parsing or schema digestion. This is a common external factor leading to `suds` errors.
Install
-
pip install suds
Imports
- Client
from suds.client import Client
Quickstart
import logging
import os
from suds.client import Client
# Configure logging to see SOAP requests/responses for debugging
logging.basicConfig(level=logging.INFO)
logging.getLogger('suds.client').setLevel(logging.DEBUG)
# A public WSDL for temperature conversion
wsdl_url = 'http://www.w3schools.com/xml/tempconvert.asmx?WSDL'
try:
# Create a Suds client
client = Client(wsdl_url)
print(f"Connected to SOAP service at: {wsdl_url}")
print("\nAvailable service methods:")
print(client)
# Invoke a method: FahrenheitToCelsius
fahrenheit_temp = 68.0
result = client.service.FahrenheitToCelsius(fahrenheit_temp)
print(f"\n{fahrenheit_temp}°F is {result}°C")
# Invoke another method: CelsiusToFahrenheit
celsius_temp = 20.0
result = client.service.CelsiusToFahrenheit(celsius_temp)
print(f"{celsius_temp}°C is {result}°F")
except Exception as e:
print(f"An error occurred: {e}")
print("Ensure the WSDL URL is correct and reachable, and that the service is active.")