Using libraries for SOAP

In this section, we are going to learn about Python libraries for SOAP. There are various libraries used for SOAP listed here:

  • SOAPpy
  • Zeep
  • Ladon
  • suds-jurko
  • pysimplesoap

These are the SOAP API libraries for Python. In this section, we are going to learn about the Zeep library only.

To use the functionality of Zeep, you need to install it first. Run the following command in your Terminal to install Zeep:

            $ pip3 install Zeep

The Zeep module is used for WSDL documents. It generates the code for the services and the documents and provides the programming interface to the SOAP server. The lxml library is used to parse the XML documents.

Now, we are going to see an example. Create a soap_example.py script and write the following code in it:

import zeep

w = 'http://www.soapclient.com/xml/soapresponder.wsdl'
c = zeep.Client(wsdl=w)
print(c.service.Method1('Hello', 'World'))

Run the script and you will get the following output:

student@ubuntu:~$ python3 soap_example.py
Output :
Your input parameters are Hello and World

In the preceding example, we first imported the zeep module. We first mentioned the website name. Then we created the zeep client object. The WSDL we used previously defines a simple Method1 function that is made available by zeep via client.service.Method1. It takes two arguments and returns a string.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset