suds-ews /

Filename Size Date modified Message
358 B
446 B
11.0 KB
23 B
1.1 KB

The "Suds" web services client is a lightweight soap-based client for python. The primary classes in the package are the:

  • ServiceProxy (
  • WSDL (

Basic features:

  • no class generation
  • provides an object-like API.
  • reads wsdl at runtime for encoding/decoding
  • provides for Document-Literal style SOAP binding
  • RPC-Literal (under construction)


By default, the suds package logs at LEVEL=INFO using a console handler. All messages are at level DEBUG or ERROR so, no messages are written unless the user does the following: suds.logger(<desired package>).setLevel(logging.<desired-level>) A common example (show sent/received soap messages): > > suds.logger('suds.serviceproxy').setLevel(logging.DEBUG) >

Basic usage:

You will need to know the url for WSDL for each service used. Simply create a proxy for that service as follows:

> from serviceproxy import ServiceProxy > >myurl = 'http://localhost:7080/webservices/WebServiceTestBean?wsdl' > >myservice = ServiceProxy(url)

You can inspect service object with: __str()__ or __repr()__ as follows to get a list of methods provide by the service:

> >print myservice > service (WebServiceTestBeanService) methods:

addPerson(person{person}) echo(arg0{string}) getPersonByName(name{name}) hello() testExceptions() updatePerson(person{anotherPerson}, name{name})

The sample ouput lists that the service named "WebServiceTestBeanService" has methods such as addPerson() which takes a 'person' argument of type: 'person'. This is listed as:

addPerson(person{person}) where parameter name is listed and followed by it's type as {person}. There is a type (or class) named 'person'.

So, to get person object to pass as an argument we need to get a person argument as follows:

> > person = myservice.get_instance('person') > print person >


phone = [] age = NONE name =

last = NONE first = NONE



As you can see, the object is created as defined by the WSDL. The list of phone number is empty so we'll have to create one:

> > phone = service.get_instance('phone') > phone.npa = 202 > phone.nxx = 555 > phone.number = 1212 >

... and the name and age need to be set and we need to create a name object first:


> name = service.get_instance('name') > name.first = 'Elmer' > name.last = 'Fudd' >

Now, let's set the properties of our person object

> > = name > person.age = 35 > = [phone] >

... and invoke our method named addPerson() as follows:

> > try: > person_added = myservice.addPerson(person) > except WebFault, e: > print e >

It's that easy.

The ServiceProxy can be configured to throw web faults as WebFault or to return a tuple (<status>, <returned-value>) instead as follows:

> > myservice = ServiceProxy(url, faults=False) > result = myservice.addPerson(person) > print result ( 200, person ...)

Enumerations are handled as follows:

Let's say the wsdl defines the following enumeration,

<xs:simpleType name="resourceCategory">
<xs:restriction base="xs:string">
<xs:enumeration value="PLATFORM"/> <xs:enumeration value="SERVER"/> <xs:enumeration value="SERVICE"/>



The service proxy can instantiate the enumeration so it can be used. Misspelled references to elements of the enum will raise a AttrError exception as:


> resourceCategory = myservice.get_enum('resourceCategory') <--- None if not found. > myservice.getResourceByCategory(resourceCategory.PLATFORM) >

The get_instance() method should always be used becuase it returns objects that already have the proper structure and xsi:type="" attribute defined. Since xsd supports nested type definition, so does get_instance() using the (.) dot notation. For example suppose the (name) type was not defined as a top level "named" type but rather defined within the (person) type. In this case creating a (name) object would have to be quanified by it's parent's name using the dot notation as follows:

> > name = service.get_instance('') >


Property object used to provide an object wrapper around a complex dictionary.


{ 'name':{'first':'Elvis', 'middle':'Grant', 'last':'Prestley'},
   'address':{'address':'123 Lakepines Dr.','city':'Memphis', 'state':'TN', 'zip':'87373'},
   'records':[{'name':'Elvis', 'year':'1956'},
                  {'name':'Just for You', 'year':'1957'},
                  {'name':'GI Blues', 'year':'1960'}],
p = Property(data)
p.died = '1977'   # assign value
hair = p.get(haircolor='black') # get value and specify a default.
print p.age
print 'name= %s, %s, %s' % (,,
print 'city=%s' %
print 'state=%s' % p.address.state
print [ for r in p.records]
print 'born %s died %s' % (p.born, p.died)


version-0.1.1 (12-17-07):

This release marks the first release in fedora.

version-0.1.2 (12-18-07):

This release contains an update to property adds:
  • metadata support

  • overrides: __getitem__, __setitem__, __contans__

  • changes property(reader|writer) to use the property.metadata

    to handle namespaces for XML documents.

  • fixes requires.

version-0.1.3 (12-19-07):

  • Fixes problem where nodes marked as a collection (maxOccurs > 1) not

    creating property objects with value=[] when mapped-in with < 2 values by the DocumentReader. Caused by missing the bindings.Document.ReplyHint.stripns() (which uses the DocumentReader.stripns()) conversion to DocumentReader.stripn() now returning a tuple (ns,tag) as of 0.1.2.

version-0.1.4 (12-21-07):

  • Provides for service method parameters to be None.
  • Add proper handling of method params that are lists of property objects.

version-0.1.5( 02-21-08 ):

  • Provides better logging in the modules get logger by hierarchal names.
  • Refactored as needed to truely support other bindings.
  • Add sax module which replaces ElementTree. This is faster, simpler and handles namespaces (prefixes) properly.

version-0.1.6 (03-06-08):

  • Provides proper handling of wsdls that contain schema sections containing

    xsd schema imports: <import namespace="" schemaLocation=""?>. The referenced schemas are imported when a schemaLocation is specified.

  • Raises exceptions for http status codes not already handled.

version-0.1.7 (04-08-08):

  • Added Binding.nil_supported to controls how property values (out) = None and empty tag (in) are processed. * service.binding.nil_supported = True -- means that property values = None are marshalled (out) as

    <x xsi:nil=true/> and <x/> is unmarshalled as '' and <x xsi:nil/> is unmarshalled as None.

    • service.binding.nil_supported = False -- means that property values = None are marshalled (out) as <x/> and <x/> and <x xsi:nil=true/> is unmarshalled as None. The xsi:nil is really ignored.
  • Sax handler updated to handle multiple character() callbacks when the sax parser "chunks" the text. When the node.text is None, the node.text is set to the characters. Else, the characters are appended. Thanks -

  • Replaced special (text) attribute with __text__ to allow for natural elements named "text"

  • Add unicode support by: * Add __unicode__ to all classes with __str__ * Replace all str() calls with unicode(). * __str__() returns UTF-8 encoded result of __unicode__.

  • XML output encoded as UTF-8 which matches the HTTP header and supports unicode.

  • SchemaCollection changed to provide the builtin() and custom() methods. To support this, findPrefixes() was added to the Element in This is a better approach anyway since the wsdl and schemas may have many prefixes to Tested with both doc/lit and rpc/lit bindings

  • Refactored bindings packages from document & rpc to literal & encoded

  • Contains the completion of full namespace support as follows:

    • Namespace prefixes are no longer stripped from attribute values that reference types defined in the wsdl.
    • Schema's imported using <import/> should properly handle namespace and prefix mapping and re-mapping as needed.
    • All types are resolved, using fully qualified (w/ namespaces) lookups.
    • Schema.get_type() supports paths with and without ns prefixes. When no prefix is specified the type is matched using the schema's target namespace.
  • Property maintains attribute names (keys) in the order added. This also means that get_item() and get_names() return ordered values.

    ( Although, I suspect ordering really needs to be done in the marshaller using the

    order specified in the wsdl/schema )

Major refactoring of the The primary goals is perparation for type lookups that are fully qualified by namespace. Once completed, the prefixes on attribute values will not longer be stripped (purged). Change Summary:

  1. SchemaProperty overlay classes created at __init__ instead of on-demand.

  2. schema imports performed by new Import class instead of by Schema.

  3. Schema loads top level properties using a factory.

  4. All SchemaProperty /children/ lists are sorted by __cmp__ in SchemaProperty derived classes. This ensures that types with the same name are resolved in the following order (Import, Complex, Simple, Element).

  5. All /children/ SchemaProperty lists are constructed at __init__ instead of on-demand.

  6. The SchemaGroup created and WSDL class updated. This works better then having the wsdl aggregate the <schema/> nodes which severs linkage to the wsdl parent element that have namespace prefix mapping.

  7. <import/> element handles properly in that both namespace remapping and prefix re-mapping of the imported schema's targetNamespace and associated prefix mapping - is performed.

    Eg: SCHMEA-A has prefix (tns) mapped as xmlns:tns=http://nsA and has targetNamespace=http://nsA. SCHEMA-B is importing schema A and has prefix (abc) mapped as xmlns:abc=http://nsABC. SCHEMA-B imports A as <import namespace=http://nsB xxx schemaLocation=http://nsA/schema-a.xsd>;. So, since SCHEMA-B will be referencing elements of SCHEMA-A with prefix (abc) such as abc:something, SCHEMA-A's targetNamespace must be updated as http://nsABC and all element with type=tns:something must be updated to be type=abc:something so then can be resolved.

  • Fixes unmarshalling problem where nodes are added to property as (text, value). This as introduced when the bindings were refactored.
  • Fixed various Property print problems.


Thanks to Jesper Noehr of Coniuro for the majority of the rpc/literal binding and for lots of collaboration on #suds.

version-0.1.8 (in-progress):