Suds-py3

1.4.5.0 · active · verified Sun Apr 12

Suds-py3 is a lightweight Python SOAP client that provides a service proxy for Web Services, originally forked from the unmaintained Python 2 `suds` library to support Python 3. It allows users to interact with SOAP-based web services without deep concerns about WSDL complexities, presenting an RPC-like interface. The current version is 1.4.5.0, with releases focused on bug fixes and Python 3 compatibility, though its maintenance status has been flagged as low by OpenSSF scorecard.

Warnings

Install

Imports

Quickstart

The quickstart demonstrates connecting to a SOAP web service using `suds-py3`'s `Client` and invoking a simple method. It includes an example with a public temperature conversion WSDL. For services requiring authentication, username and password can be passed to the Client constructor. Enabling debug logging for `suds.client` is recommended for troubleshooting SOAP message exchanges.

import os
from suds.client import Client

# Replace with your WSDL URL. Use a placeholder for demonstration.
# A public WSDL for testing temperature conversion:
# wsdl_url = "http://www.w3schools.com/xml/tempconvert.asmx?WSDL"
wsdl_url = os.environ.get('SOAP_WSDL_URL', 'http://www.w3schools.com/xml/tempconvert.asmx?WSDL')

try:
    # Initialize the SOAP client
    client = Client(wsdl_url)
    print(f"Connected to SOAP service at: {wsdl_url}")

    # Optionally, print available services and methods
    # print(client)
    # print("Available services:", client.service)
    # print("Available factory types:", client.factory)

    # Example: Call a method (assuming TemperatureConvert service)
    # If the WSDL had authentication, you'd pass username/password to Client constructor
    # client = Client(wsdl_url, username=os.environ.get('SOAP_USERNAME', ''), password=os.environ.get('SOAP_PASSWORD', ''))

    # Convert Fahrenheit to Celsius
    fahrenheit_temp = 32.0
    celsius_temp = client.service.FahrenheitToCelsius(fahrenheit_temp)
    print(f"{fahrenheit_temp}°F is {celsius_temp}°C")

    # Convert Celsius to Fahrenheit
    celsius_temp_input = 0.0
    fahrenheit_temp_output = client.service.CelsiusToFahrenheit(celsius_temp_input)
    print(f"{celsius_temp_input}°C is {fahrenheit_temp_output}°F")

except Exception as e:
    print(f"An error occurred: {e}")
    print("Please ensure the WSDL URL is correct and the service is accessible.")
    print("For debugging, you can enable logging: import logging; logging.getLogger('suds.client').setLevel(logging.DEBUG)")

view raw JSON →