zeep.wsdl

The wsdl module is responsible for parsing the WSDL document. This includes the bindings and messages.

The structure and naming of the modules and classses closely follows the WSDL 1.1 specification.

The serialization and deserialization of the SOAP/HTTP messages is done by the zeep.wsdl.messages modules.

zeep.wsdl.wsdl

class zeep.wsdl.wsdl.Definition(wsdl, doc, location)

The Definition represents one wsdl:definition within a Document.

Parameters:wsdl – The wsdl
parse_binding(doc)

Parse the binding elements and return a dict of bindings.

Currently supported bindings are Soap 1.1, Soap 1.2., HTTP Get and HTTP Post. The detection of the type of bindings is done by the bindings themselves using the introspection of the xml nodes.

Definition:

<wsdl:definitions .... >
    <wsdl:binding name="nmtoken" type="qname"> *
        <-- extensibility element (1) --> *
        <wsdl:operation name="nmtoken"> *
           <-- extensibility element (2) --> *
           <wsdl:input name="nmtoken"? > ?
               <-- extensibility element (3) -->
           </wsdl:input>
           <wsdl:output name="nmtoken"? > ?
               <-- extensibility element (4) --> *
           </wsdl:output>
           <wsdl:fault name="nmtoken"> *
               <-- extensibility element (5) --> *
           </wsdl:fault>
        </wsdl:operation>
    </wsdl:binding>
</wsdl:definitions>
Parameters:doc (lxml.etree._Element) – The source document
Returns:Dictionary with binding name as key and Binding instance as value
Return type:dict
parse_imports(doc)

Import other WSDL definitions in this document.

Note that imports are non-transitive, so only import definitions which are defined in the imported document and ignore definitions imported in that document.

This should handle recursive imports though:

A -> B -> A A -> B -> C -> A
Parameters:doc (lxml.etree._Element) – The source document
parse_messages(doc)

Definition:

<definitions .... >
    <message name="nmtoken"> *
        <part name="nmtoken" element="qname"? type="qname"?/> *
    </message>
</definitions>
Parameters:doc (lxml.etree._Element) – The source document
parse_ports(doc)

Return dict with PortType instances as values

Definition:

<wsdl:definitions .... >
    <wsdl:portType name="nmtoken">
        <wsdl:operation name="nmtoken" .... /> *
    </wsdl:portType>
</wsdl:definitions>
Parameters:doc (lxml.etree._Element) – The source document
parse_service(doc)

Definition:

<wsdl:definitions .... >
    <wsdl:service .... > *
        <wsdl:port name="nmtoken" binding="qname"> *
           <-- extensibility element (1) -->
        </wsdl:port>
    </wsdl:service>
</wsdl:definitions>
Parameters:doc (lxml.etree._Element) – The source document
parse_types(doc)

Return an xsd.Schema() instance for the given wsdl:types element.

If the wsdl:types contain multiple schema definitions then a new wrapping xsd.Schema is defined with xsd:import statements linking them together.

If the wsdl:types doesn’t container an xml schema then an empty schema is returned instead.

Definition:

<definitions .... >
    <types>
        <xsd:schema .... />*
    </types>
</definitions>
Parameters:doc (lxml.etree._Element) – The source document
resolve_imports()

Resolve all root elements (types, messages, etc).

class zeep.wsdl.wsdl.Document(location, transport, base=None, strict=True)

A WSDL Document exists out of one or more definitions.

There is always one ‘root’ definition which should be passed as the location to the Document. This definition can import other definitions. These imports are non-transitive, only the definitions defined in the imported document are available in the parent definition. This Document is mostly just a simple interface to the root definition.

After all definitions are loaded the definitions are resolved. This resolves references which were not yet available during the initial parsing phase.

Parameters:
  • location (string) – Location of this WSDL
  • transport (zeep.transports.Transport) – The transport object to be used
  • base (str) – The base location of this document
  • strict (bool) – Indicates if strict mode is enabled

zeep.wsdl.definitions

A WSDL document exists out of a number of definitions. There are 6 major definitions, these are:

  • types
  • message
  • portType
  • binding
  • port
  • service

This module defines the definitions which occur within a WSDL document,

class zeep.wsdl.definitions.AbstractMessage(name)

Messages consist of one or more logical parts.

Each part is associated with a type from some type system using a message-typing attribute. The set of message-typing attributes is extensible. WSDL defines several such message-typing attributes for use with XSD:

  • element: Refers to an XSD element using a QName.
  • type: Refers to an XSD simpleType or complexType using a QName.
class zeep.wsdl.definitions.AbstractOperation(name, input_message=None, output_message=None, fault_messages=None, parameter_order=None)

Abstract operations are defined in the wsdl’s portType elements.

class zeep.wsdl.definitions.Binding(wsdl, name, port_name)

Base class for the various bindings (SoapBinding / HttpBinding)

class zeep.wsdl.definitions.MessagePart(element, type)
element

Alias for field number 0

type

Alias for field number 1

class zeep.wsdl.definitions.Operation(name, binding)

Concrete operation

Contains references to the concrete messages

classmethod parse(wsdl, xmlelement, binding)

Definition:

<wsdl:operation name="nmtoken"> *
   <-- extensibility element (2) --> *
   <wsdl:input name="nmtoken"? > ?
       <-- extensibility element (3) -->
   </wsdl:input>
   <wsdl:output name="nmtoken"? > ?
       <-- extensibility element (4) --> *
   </wsdl:output>
   <wsdl:fault name="nmtoken"> *
       <-- extensibility element (5) --> *
   </wsdl:fault>
</wsdl:operation>
class zeep.wsdl.definitions.Port(name, binding_name, xmlelement)

Specifies an address for a binding, thus defining a single communication endpoint.

class zeep.wsdl.definitions.Service(name)

Used to aggregate a set of related ports.

zeep.wsdl.parse

zeep.wsdl.parse.parse_abstract_message(wsdl, xmlelement)

Create an AbstractMessage object from a xml element.

Definition:

<definitions .... >
    <message name="nmtoken"> *
        <part name="nmtoken" element="qname"? type="qname"?/> *
    </message>
</definitions>
Parameters:
Return type:

zeep.wsdl.definitions.AbstractMessage

zeep.wsdl.parse.parse_abstract_operation(wsdl, xmlelement)

Create an AbstractOperation object from a xml element.

This is called from the parse_port_type function since the abstract operations are part of the port type element.

Definition:

<wsdl:operation name="nmtoken">*
   <wsdl:documentation .... /> ?
   <wsdl:input name="nmtoken"? message="qname">?
       <wsdl:documentation .... /> ?
   </wsdl:input>
   <wsdl:output name="nmtoken"? message="qname">?
       <wsdl:documentation .... /> ?
   </wsdl:output>
   <wsdl:fault name="nmtoken" message="qname"> *
       <wsdl:documentation .... /> ?
   </wsdl:fault>
</wsdl:operation>
Parameters:
Return type:

zeep.wsdl.definitions.AbstractOperation

zeep.wsdl.parse.parse_port(wsdl, xmlelement)

Create a Port object from a xml element.

This is called via the parse_service function since ports are part of the service xml elements.

Definition:

<wsdl:port name="nmtoken" binding="qname"> *
   <wsdl:documentation .... /> ?
   <-- extensibility element -->
</wsdl:port>
Parameters:
Return type:

zeep.wsdl.definitions.Port

zeep.wsdl.parse.parse_port_type(wsdl, xmlelement)

Create a PortType object from a xml element.

Definition:

<wsdl:definitions .... >
    <wsdl:portType name="nmtoken">
        <wsdl:operation name="nmtoken" .... /> *
    </wsdl:portType>
</wsdl:definitions>
Parameters:
Return type:

zeep.wsdl.definitions.PortType

zeep.wsdl.parse.parse_service(wsdl, xmlelement)

Definition:

<wsdl:service name="nmtoken"> *
    <wsdl:documentation .... />?
    <wsdl:port name="nmtoken" binding="qname"> *
       <wsdl:documentation .... /> ?
       <-- extensibility element -->
    </wsdl:port>
    <-- extensibility element -->
</wsdl:service>

Example:

<service name="StockQuoteService">
  <documentation>My first service</documentation>
  <port name="StockQuotePort" binding="tns:StockQuoteBinding">
    <soap:address location="http://example.com/stockquote"/>
  </port>
</service>
Parameters:
Return type:

zeep.wsdl.definitions.Service

Basic implementation to support SOAP-Attachments

See https://www.w3.org/TR/SOAP-attachments

class zeep.wsdl.bindings.soap.SoapBinding(wsdl, name, port_name, transport, default_style)

Soap 1.1/1.2 binding

classmethod match(node)

Check if this binding instance should be used to parse the given node.

Parameters:node (lxml.etree._Element) – The node to match against
classmethod parse(definitions, xmlelement)

Definition:

<wsdl:binding name="nmtoken" type="qname"> *
    <-- extensibility element (1) --> *
    <wsdl:operation name="nmtoken"> *
       <-- extensibility element (2) --> *
       <wsdl:input name="nmtoken"? > ?
           <-- extensibility element (3) -->
       </wsdl:input>
       <wsdl:output name="nmtoken"? > ?
           <-- extensibility element (4) --> *
       </wsdl:output>
       <wsdl:fault name="nmtoken"> *
           <-- extensibility element (5) --> *
       </wsdl:fault>
    </wsdl:operation>
</wsdl:binding>
process_reply(client, operation, response)

Process the XML reply from the server.

Parameters:
  • client (zeep.client.Client) – The client with which the operation was called
  • operation (zeep.wsdl.definitions.Operation) – The operation object from which this is a reply
  • response (requests.Response) – The response object returned by the remote server
send(client, options, operation, args, kwargs)

Called from the service

Parameters:
  • client (zeep.client.Client) – The client with which the operation was called
  • options (dict) – The binding options
  • operation (zeep.wsdl.definitions.Operation) – The operation object from which this is a reply
  • args (tuple) – The args to pass to the operation
  • kwargs (dict) – The kwargs to pass to the operation
class zeep.wsdl.bindings.soap.SoapOperation(name, binding, nsmap, soapaction, style)

Represent’s an operation within a specific binding.

classmethod parse(definitions, xmlelement, binding, nsmap)

Definition:

<wsdl:operation name="nmtoken"> *
    <soap:operation soapAction="uri"? style="rpc|document"?>?
    <wsdl:input name="nmtoken"? > ?
        <soap:body use="literal"/>
   </wsdl:input>
   <wsdl:output name="nmtoken"? > ?
        <-- extensibility element (4) --> *
   </wsdl:output>
   <wsdl:fault name="nmtoken"> *
        <-- extensibility element (5) --> *
   </wsdl:fault>
</wsdl:operation>

Example:

<wsdl:operation name="GetLastTradePrice">
  <soap:operation soapAction="http://example.com/GetLastTradePrice"/>
  <wsdl:input>
    <soap:body use="literal"/>
  </wsdl:input>
  <wsdl:output>
  </wsdl:output>
  <wsdl:fault name="dataFault">
    <soap:fault name="dataFault" use="literal"/>
  </wsdl:fault>
</operation>

zeep.wsdl.messages

The messages are responsible for serializing and deserializing

Inheritance diagram of zeep.wsdl.messages.soap.DocumentMessage, zeep.wsdl.messages.soap.RpcMessage, zeep.wsdl.messages.http.UrlEncoded, zeep.wsdl.messages.http.UrlReplacement, zeep.wsdl.messages.mime.MimeContent, zeep.wsdl.messages.mime.MimeXML, zeep.wsdl.messages.mime.MimeMultipart

zeep.wsdl.messages.base

class zeep.wsdl.messages.base.ConcreteMessage(wsdl, name, operation)

Represents the wsdl:binding -> wsdl:operation -> input/ouput node

class zeep.wsdl.messages.base.SerializedMessage(path, headers, content)
content

Alias for field number 2

headers

Alias for field number 1

path

Alias for field number 0

zeep.wsdl.messages.http

class zeep.wsdl.messages.http.UrlEncoded(wsdl, name, operation)

The urlEncoded element indicates that all the message parts are encoded into the HTTP request URI using the standard URI-encoding rules (name1=value&name2=value...).

The names of the parameters correspond to the names of the message parts. Each value contributed by the part is encoded using a name=value pair. This may be used with GET to specify URL encoding, or with POST to specify a FORM-POST. For GET, the ”?” character is automatically appended as necessary.

class zeep.wsdl.messages.http.UrlReplacement(wsdl, name, operation)

The http:urlReplacement element indicates that all the message parts are encoded into the HTTP request URI using a replacement algorithm.

  • The relative URI value of http:operation is searched for a set of search patterns.
  • The search occurs before the value of the http:operation is combined with the value of the location attribute from http:address.
  • There is one search pattern for each message part. The search pattern string is the name of the message part surrounded with parenthesis “(” and ”)”.
  • For each match, the value of the corresponding message part is substituted for the match at the location of the match.
  • Matches are performed before any values are replaced (replaced values do not trigger additional matches).

Message parts MUST NOT have repeating values. <http:urlReplacement/>

zeep.wsdl.messages.mime

class zeep.wsdl.messages.mime.MimeContent(wsdl, name, operation, content_type, part_name)

WSDL includes a way to bind abstract types to concrete messages in some MIME format.

Bindings for the following MIME types are defined:

  • multipart/related
  • text/xml
  • application/x-www-form-urlencoded
  • Others (by specifying the MIME type string)

The set of defined MIME types is both large and evolving, so it is not a goal for WSDL to exhaustively define XML grammar for each MIME type.

Parameters:
class zeep.wsdl.messages.mime.MimeXML(wsdl, name, operation, part_name)

To specify XML payloads that are not SOAP compliant (do not have a SOAP Envelope), but do have a particular schema, the mime:mimeXml element may be used to specify that concrete schema.

The part attribute refers to a message part defining the concrete schema of the root XML element. The part attribute MAY be omitted if the message has only a single part. The part references a concrete schema using the element attribute for simple parts or type attribute for composite parts

Parameters:
class zeep.wsdl.messages.mime.MimeMultipart(wsdl, name, operation, part_name)

The multipart/related MIME type aggregates an arbitrary set of MIME formatted parts into one message using the MIME type “multipart/related”.

The mime:multipartRelated element describes the concrete format of such a message:

<mime:multipartRelated>
    <mime:part> *
        <-- mime element -->
    </mime:part>
</mime:multipartRelated>

The mime:part element describes each part of a multipart/related message. MIME elements appear within mime:part to specify the concrete MIME type for the part. If more than one MIME element appears inside a mime:part, they are alternatives.

Parameters:

zeep.wsdl.messages.soap

class zeep.wsdl.messages.soap.DocumentMessage(*args, **kwargs)

In the document message there are no additional wrappers, and the message parts appear directly under the SOAP Body element.

Inheritance diagram of zeep.wsdl.messages.soap.DocumentMessage
Parameters:
  • wsdl (zeep.wsdl.Document) – The main wsdl document
  • name
  • operation (zeep.wsdl.bindings.soap.SoapOperation) – The operation to which this message belongs
  • type (str) – ‘input’ or ‘output’
  • nsmap (dict) – The namespace mapping
deserialize(envelope)

Deserialize the SOAP:Envelope and return a CompoundValue with the result.

parse(definitions, xmlelement, operation, type, nsmap)

Parse a wsdl:binding/wsdl:operation/wsdl:operation for the SOAP implementation.

Each wsdl:operation can contain three child nodes:
  • input
  • output
  • fault

Definition for input/output:

<input>
  <soap:body parts="nmtokens"? use="literal|encoded"
             encodingStyle="uri-list"? namespace="uri"?>

  <soap:header message="qname" part="nmtoken" use="literal|encoded"
               encodingStyle="uri-list"? namespace="uri"?>*
    <soap:headerfault message="qname" part="nmtoken"
                      use="literal|encoded"
                      encodingStyle="uri-list"? namespace="uri"?/>*
  </soap:header>
</input>

And the definition for fault:

<soap:fault name="nmtoken" use="literal|encoded"
            encodingStyle="uri-list"? namespace="uri"?>
resolve(definitions, abstract_message)

Resolve the data in the self._resolve_info dict (set via parse())

This creates three xsd.Element objects:

  • self.header
  • self.body
  • self.envelope (combination of headers and body)

XXX headerfaults are not implemented yet.

serialize(*args, **kwargs)

Create a SerializedMessage for this message

class zeep.wsdl.messages.soap.RpcMessage(wsdl, name, operation, type, nsmap)

In RPC messages each part is a parameter or a return value and appears inside a wrapper element within the body.

The wrapper element is named identically to the operation name and its namespace is the value of the namespace attribute. Each message part (parameter) appears under the wrapper, represented by an accessor named identically to the corresponding parameter of the call. Parts are arranged in the same order as the parameters of the call.

Inheritance diagram of zeep.wsdl.messages.soap.DocumentMessage
Parameters:
  • wsdl (zeep.wsdl.Document) – The main wsdl document
  • name
  • operation (zeep.wsdl.bindings.soap.SoapOperation) – The operation to which this message belongs
  • type (str) – ‘input’ or ‘output’
  • nsmap (dict) – The namespace mapping
deserialize(envelope)

Deserialize the SOAP:Envelope and return a CompoundValue with the result.

parse(definitions, xmlelement, operation, type, nsmap)

Parse a wsdl:binding/wsdl:operation/wsdl:operation for the SOAP implementation.

Each wsdl:operation can contain three child nodes:
  • input
  • output
  • fault

Definition for input/output:

<input>
  <soap:body parts="nmtokens"? use="literal|encoded"
             encodingStyle="uri-list"? namespace="uri"?>

  <soap:header message="qname" part="nmtoken" use="literal|encoded"
               encodingStyle="uri-list"? namespace="uri"?>*
    <soap:headerfault message="qname" part="nmtoken"
                      use="literal|encoded"
                      encodingStyle="uri-list"? namespace="uri"?/>*
  </soap:header>
</input>

And the definition for fault:

<soap:fault name="nmtoken" use="literal|encoded"
            encodingStyle="uri-list"? namespace="uri"?>
resolve(definitions, abstract_message)

Resolve the data in the self._resolve_info dict (set via parse())

This creates three xsd.Element objects:

  • self.header
  • self.body
  • self.envelope (combination of headers and body)

XXX headerfaults are not implemented yet.

serialize(*args, **kwargs)

Create a SerializedMessage for this message

zeep.wsdl.utils