CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-zeep

A comprehensive Python SOAP client library for consuming SOAP web services with support for SOAP 1.1/1.2, WSSE authentication, and async operations

Overview
Eval results
Files

xsd-types.mddocs/

XSD and Type Handling

XML Schema processing, type conversion, and handling of complex XML structures. Zeep provides comprehensive tools for working with XSD types and converting between Python objects and XML representations.

Capabilities

AnyObject Container

Container for arbitrary XML content that doesn't fit standard XSD types.

class AnyObject:
    def __init__(self, xsd_object, value):
        """
        Create container for arbitrary XML content.

        Parameters:
        - xsd_object: XSD type or element definition
        - value: Python value to wrap
        """

    @property
    def xsd_type(self):
        """XSD type definition for this object."""

    @property  
    def xsd_elm(self):
        """XSD element definition for this object."""

Schema Processing

Core XSD schema processing and type registry.

class Schema:
    def __init__(self, node, location=None, types=None):
        """
        Process XSD schema document.
        
        Parameters:
        - node: XML schema node (lxml.etree._Element)
        - location: Schema location URL
        - types: Parent types registry
        """

    def get_type(self, qname: str):
        """Get XSD type by qualified name."""

    def get_element(self, qname: str):
        """Get XSD element by qualified name."""

Value Objects

Structured value containers for complex XSD types.

class CompoundValue:
    """
    Container for complex type values with attribute access.
    
    Provides dict-like and object-like access to complex type data.
    """
    
    def __getitem__(self, key: str):
        """Dictionary-style access to values."""
        
    def __setitem__(self, key: str, value):
        """Dictionary-style value assignment."""
        
    def __getattr__(self, key: str):
        """Attribute-style access to values."""

XSD Constants

Special values for XSD processing.

# XSD nil value representation
Nil: object

# Skip value placeholder for optional elements
SkipValue: object

Helper Functions

Utility functions for working with XSD objects and serialization.

def serialize_object(obj):
    """
    Serialize zeep objects to plain Python dictionaries.
    
    Parameters:
    - obj: Zeep object to serialize
    
    Returns:
    dict: Plain Python dictionary representation
    """

Usage Examples

Working with Complex Types

from zeep import Client

client = Client('http://example.com/service.wsdl')

# Get complex type definition
person_type = client.get_type('{http://example.com}Person')

# Create instance of complex type
person = person_type(
    name='John Doe',
    age=30,
    address={
        'street': '123 Main St',
        'city': 'Anytown',
        'state': 'CA'
    }
)

# Use in SOAP operation
result = client.service.UpdatePerson(person=person)

AnyObject Usage

from zeep import Client
from zeep.xsd import AnyObject

client = Client('http://example.com/service.wsdl')

# Create AnyObject for arbitrary XML content
any_type = client.get_type('{http://www.w3.org/2001/XMLSchema}anyType')
custom_data = AnyObject(any_type, {
    'custom_field': 'custom_value',
    'nested': {
        'data': 'nested_value'
    }
})

# Use in operation that accepts any content
result = client.service.ProcessAnyData(data=custom_data)

Type Inspection

from zeep import Client

client = Client('http://example.com/service.wsdl')

# Inspect available types
print("Available types:")
for qname in client.wsdl.types.documents[0].types:
    print(f"  {qname}")

# Get type details
address_type = client.get_type('{http://example.com}Address')
print(f"Type signature: {address_type.signature()}")

# Inspect type structure
print("Type elements:")
for element in address_type.elements:
    print(f"  {element.name}: {element.type}")

Element Creation

from zeep import Client

client = Client('http://example.com/service.wsdl')

# Get element definition
address_element = client.get_element('{http://example.com}Address')

# Create element instance
address = address_element(
    street='456 Oak Ave',
    city='Other City',
    state='NY',
    zip='54321'
)

# Use element in operation
result = client.service.ValidateAddress(address)

Handling Nil Values

from zeep import Client
from zeep.xsd import Nil

client = Client('http://example.com/service.wsdl')

# Create object with nil value
person_type = client.get_type('{http://example.com}Person')
person = person_type(
    name='Jane Doe',
    age=25,
    middle_name=Nil,  # Explicitly set to nil
    phone_number=None  # Will be omitted
)

result = client.service.CreatePerson(person=person)

Skip Optional Elements

from zeep import Client
from zeep.xsd import SkipValue

client = Client('http://example.com/service.wsdl')

# Skip optional elements completely
config_type = client.get_type('{http://example.com}Configuration')
config = config_type(
    required_setting='value',
    optional_setting=SkipValue,  # Skip this element entirely
    another_setting='another_value'
)

result = client.service.UpdateConfiguration(config=config)

Custom Type Creation

from zeep import Client
from zeep.xsd import ComplexType, Element, Sequence

client = Client('http://example.com/service.wsdl')

# Create custom type dynamically (advanced usage)
custom_type = ComplexType(
    Sequence([
        Element('name', client.wsdl.types.get_type('{http://www.w3.org/2001/XMLSchema}string')),
        Element('value', client.wsdl.types.get_type('{http://www.w3.org/2001/XMLSchema}int'))
    ])
)

# Create instance
custom_obj = custom_type(name='test', value=42)

Type Conversion and Serialization

from zeep import Client
from zeep.helpers import serialize_object

client = Client('http://example.com/service.wsdl')

# Call operation and get complex result
result = client.service.GetPersonDetails(person_id=123)

# Convert zeep objects to plain Python dict
plain_dict = serialize_object(result)
print(plain_dict)

# Now you can use standard JSON serialization, etc.
import json
json_data = json.dumps(plain_dict, default=str)

Working with Arrays/Lists

from zeep import Client

client = Client('http://example.com/service.wsdl')

# Create list of complex objects  
person_type = client.get_type('{http://example.com}Person')
people = [
    person_type(name='Alice', age=25),
    person_type(name='Bob', age=30),
    person_type(name='Charlie', age=35)
]

# Use list in operation
result = client.service.ProcessPeople(people=people)

# Handle array results
for person in result.processed_people:
    print(f"{person.name}: {person.status}")

Install with Tessl CLI

npx tessl i tessl/pypi-zeep

docs

client-operations.md

exception-handling.md

index.md

plugin-system.md

transport-settings.md

wsse-security.md

xsd-types.md

tile.json