Member-only story

Using Zeep to make SOAP requests in Python

Adrienne Domingus
3 min readMar 25, 2017

While most APIs are REST these days, there are still some SOAP ones out there — typically enterprise software or if you need the benefits of WS-security or the like. What brought me to SOAP was integrating with an enterprise payment gateway that had developed their own clients in several languages, but not Python, so I was on the hunt for my own. There are others, the short version of why I went with Zeep is because it was purported to be the most “modern” — we can argue about whether this was a good decision or rationale some other time. This is a pretty basic overview, but should enable you to make your first requests and clear up some hurdles I faced when some things were less clear than I would have liked in the docs.

Passing Parameters/Generating XML

One of the nice things about using Zeep is that you don’t actually need to write XML, which can be finicky. Create a dictionary with the relevant data, and it will create XML for you, based on an XML schema that you provide it (more on that later). For example, the following dictionary:

request_data = {
'merchantID': '1234abc',
'billTo': {
'street1': '400 Broad Street',
'city': 'Seattle',
'state': 'WA',
'postalCode': '98109',
'country': 'US',
},
'item': [{
'id': '0',
'unitPrice': '12.34',
'quantity': '1',
}],
'taxService': {
'run': "true",
'nexus': "WA, CA"
},
}

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Responses (13)

Write a response

Hey Adrienne, thanks for the post.
Just to chip in, you can also find a list of the operations available at an endpoint using it’s WSDL file/link. You do:
$ python -mzeep <wsdl-link> or <path-to-wsdl-file>
$ python -mzeep…

8

It would be helpful to understand how you determined what *request_data* should be.

1

Adrienne- thanks for the wsse login usage. i was struggling with the HTTPBasicAuth to get working. yours works like a charm.

1