rinse

Rinse is a Python SOAP client using lxml, requests and defusedxml.

Latest Version Latest Version Documentation Build Status Coverage

Rinse works with both Python 2 and Python 3. Continuous integration testing is performed against the latest python 2.7, python 3.3 and python 3.4 releases.

The name “rinse” refers to its dictionary meaning, such as the act of removing soap suds from something using water.

The goal of rinse is to be a SOAP client that focuses on the minimum set of features required to make SOAP calls to services over HTTP/HTTPS. Support for common SOAP extensions including WSA (WS-Addressing) and WSSE (WS-Security) is provided. Rinse supports the WS-I Basic Profile Version 2.0 specification in principle, but takes a pragmatic approach to achieving compliance based upon further goals and constraints outlined below.

Using rinse as part of a SOAP service (SOAP server) is not supported. We recommend servers should use JSON for data interchange over RESTful HTTP(S) rather than providing SOAP services. And we’re not the only ones - Google announced its plans to abandon SOAP way back in 2009.

Security is improved by using the defusedxml library to parse XML data thereby minimising risks associated with parsing and processing data from untrusted sources. TODO: SSL certificate pinning to ensure that clients using rinse only disclose information to and parse information from intended servers.

Rinse has support for validating SOAP messages against the schema specified in XSD (XML schema definition) format within a given WSDL file, but is not capable of generating SOAP service bindings at runtime. Future development may provide support for generating bindings from WSDL in the form of Python source files. Dynamic (runtime) binding is unlikely to be supported.

Installation:

Rinse is available for installation direct from PyPi:

pip install rinse

Contents:

rinse

SOAP client.

rinse.client

SOAP client.

class rinse.client.SoapClient(url, debug=False, **kwargs)[source]

Rinse SOAP client.

rinse.message

SOAP client.

class rinse.message.SoapMessage(body=None)[source]

SOAP message.

>>> from rinse.message import SoapMessage
>>> from lxml import etree
>>> from rinse.util import printxml
>>> body = etree.Element('test')
>>> msg = SoapMessage(body)
>>> printxml(msg.etree())
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
  <soapenv:Header/>
  <soapenv:Body>
    <test/>
  </soapenv:Body>
</soapenv:Envelope>
elementmaker(prefix, url)[source]

Register namespace and return ElementMaker bound to the namespace.

elementmaker_cls

alias of ElementMaker

etree()[source]

Generate a SOAP Envelope message with header and body elements.

request(url=None, action=None)[source]

Generate a requests.Request instance.

tostring(**kwargs)[source]

Generate XML representation of self.

rinse.response

SOAP client.

class rinse.response.Response(response)[source]

Rinse Response object.

class rinse.response.RinseResponse(response, doc)
doc

Alias for field number 1

response

Alias for field number 0

rinse.util

rinse SOAP client utility functions.

class rinse.util.ElementMaker(typemap=None, namespace=None, nsmap=None, makeelement=None)[source]

Wrapper around lxml ElementMaker that casts ints as strings.

class rinse.util.ElementMakerCache(nsmap)[source]

Cache of ElementMaker instances for the given nsmap.

class rinse.util.RinseResponse(response, doc)
doc

Alias for field number 1

response

Alias for field number 0

class rinse.util.SchemaCache[source]

Cache of lxml.etree.XMLSchema instances, keyed by XSD basename.

get(xsd, xpath=None, namespaces=None)[source]

Generate XMLSchema instances as specified.

class rinse.util.cached_property(func)[source]
rinse.util.element_as_tree(element)[source]

Convert an element from within an ElementTree to its own tree.

rinse.util.printxml(doc)[source]

Pretty print an lxml document tree.

The XML printed may not be exactly equivalent to the doc provided, as blank text within elements will be stripped to allow etree.tostring() to work with the ‘pretty_print’ option set.

rinse.util.recursive_dict(element)[source]

Map an XML tree into a dict of dicts.

rinse.util.safe_parse_path(xml_path, **kwargs)[source]

Safely parse XML content from path into an element tree.

rinse.util.safe_parse_string(raw_xml, **kwargs)[source]

Safely parse raw XML content into an element tree.

rinse.util.safe_parse_url(xml_url, **kwargs)[source]

Safely parse XML content from path into an element tree.

rinse.wsa

WSA (Addressing) support for rinse SOAP client.

rinse.wsa.append_wsa_headers(msg, to, action, message_id=None, relates_to=None, relationship_type=None, reply_to=None, from_endpoint=None, fault_to=None)[source]

Add WSA (addressing) headers.

>>> from rinse.wsa import append_wsa_headers
>>> import lxml.usedoctest
>>> from rinse.message import SoapMessage
>>> from rinse.util import printxml
>>> msg = SoapMessage()
>>> f123 = msg.elementmaker(
...     'f123',
...     'http://www.fabrikam123.example/svc53',
... )
>>> msg.body = f123.Delete(f123.maxCount('42'))
>>> append_wsa_headers(
...     msg,
...     'mailto:joe@fabrikam123.example',
...     'http://fabrikam123.example/mail/Delete',
...     message_id='uuid:aaaabbbb-cccc-dddd-eeee-ffffffffffff',
...     reply_to='http://business456.example/client1',
... )
>>> print(msg['SOAPAction'])
"http://fabrikam123.example/mail/Delete"
>>> printxml(msg.etree())
<soapenv:Envelope xmlns:f123="http://www.fabrikam123.example/svc53"
        xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
        xmlns:wsa="http://www.w3.org/2005/08/addressing">
  <soapenv:Header>
    <wsa:MessageID>uuid:aaaabbbb-cccc-dddd-eeee-ffffffffffff</wsa:MessageID>
    <wsa:To>mailto:joe@fabrikam123.example</wsa:To>
    <wsa:Action>http://fabrikam123.example/mail/Delete</wsa:Action>
    <wsa:ReplyTo>
      <wsa:Address>http://business456.example/client1</wsa:Address>
    </wsa:ReplyTo>
  </soapenv:Header>
  <soapenv:Body>
    <f123:Delete>
      <f123:maxCount>42</f123:maxCount>
    </f123:Delete>
  </soapenv:Body>
</soapenv:Envelope>

rinse.wsdl

Rinse SOAP library: module providing WSDL functions.

class rinse.wsdl.WSDL(wsdl_root)[source]

WSDL object.

classmethod from_file(wsdl_path)[source]

Make a WSDL instance from a file path.

classmethod from_url(wsdl_path)[source]

Make a WSDL instance from a URL.

is_valid(soapmsg)[source]

Return True if SOAP message body validates against WSDL schema.

schema

Return schema element (used for XSD validation).

validate(soapmsg)[source]

Raise exception if SOAP message body is invalid.

xsd_validator

Extract XML Schema Definition (XSD) element tree.

rinse.wsse

SOAP client.

rinse.wsse.append_wsse_headers(msg, username, password)[source]

Add WSSE (security) headers.

>>> from rinse.wsse import append_wsse_headers
>>> import lxml.usedoctest
>>> from rinse.message import SoapMessage
>>> from rinse.util import printxml
>>> msg = SoapMessage()
>>> f123 = msg.elementmaker(
...     'f123',
...     'http://www.fabrikam123.example/svc53',
... )
>>> msg.body = f123.Delete(f123.maxCount('42'))
>>> append_wsse_headers(msg, 'alice', '$uper-5ecret')
>>> printxml(msg.etree())
<soapenv:Envelope xmlns:f123="http://www.fabrikam123.example/svc53"
         xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
         xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
  <soapenv:Header>
    <wsse:Security>
      <wsse:UsernameToken>
        <wsse:Username>alice</wsse:Username>
        <wsse:Password>$uper-5ecret</wsse:Password>
      </wsse:UsernameToken>
    </wsse:Security>
  </soapenv:Header>
  <soapenv:Body>
    <f123:Delete>
      <f123:maxCount>42</f123:maxCount>
    </f123:Delete>
  </soapenv:Body>
</soapenv:Envelope>

rinse.xsd

Rinse SOAP library: XML Schema Definition (XSD) functions.

class rinse.xsd.XSDValidator(schema_root)[source]

XSD Schema Validation.

is_valid(doc)[source]

Validate doc against schema, return True if doc is valid.

validate(doc)[source]

Validate doc against schema, raises exception if doc is invalid.

Indices and tables

Changelog

0.4.0

  • Use @cached_property to simplify property code.
  • Fix AttributeError when debugging.
  • Include missing XSD files in wheel distributions.
  • Ensure XSD files exist in distributed files via tox test suite options.

0.3.0

  • Add ‘SOAPAction’ header to requests.
  • Expose requests.Session.
  • Include missing XSD files in package data.
  • Add Python 3.4 to test builds.

0.2.0

0.1.3

  • Add links to README.

0.1.2

  • Added Sphinx documentation.

0.1.1

  • Add ElementMaker wrapper class and safe_parse_url function.
  • Add travis-ci.org build configuration.
  • Split features into submodules.

0.1.0

  • Support for WSDL.
  • Simplified usage through use of SoapClient and SoapMessage classes.

0.0.5

  • Pylint/PEP8/pychecker fixes.

0.0.4

  • Remove reference to stale source (client.py).

0.0.3

  • Add defused.xml to requirements.

0.0.2

  • Validate messages against SOAP 1.1 Envelope and SOAP 1.2 XML schema.
  • Add support for WSSE (Security) headers.

0.0.1

  • Generate SOAP requests and parse SOAP 1.1 responses.

License

The MIT License (MIT)

Copyright (c) 2014 Tyson Clugg

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.