{"id":162778,"date":"2019-02-18T04:22:30","date_gmt":"2019-02-18T04:22:30","guid":{"rendered":"https:\/\/webkul.com\/blog\/?p=162778"},"modified":"2019-09-14T08:58:16","modified_gmt":"2019-09-14T08:58:16","slug":"python-soap-clients-with-zeep","status":"publish","type":"post","link":"https:\/\/webkul.com\/blog\/python-soap-clients-with-zeep\/","title":{"rendered":"Python SOAP Clients With Zeep"},"content":{"rendered":"<h3 style=\"text-align: left\">Introduction:<\/h3>\n<p>Working with SOAP based web services can sometimes be a time taking task when you have to write the complete XML for making API requests and then parse the response xml to fetch the desired results. That&#8217;s a headache right? Well, that&#8217;s when <strong>zeep<\/strong> comes into play. Zeep is a pure-python module. The best thing about Zeep is that you don\u2019t have to write the XML at all. You just create a dictionary with all the relevant request data, and it will create the XML for you.<\/p>\n<h3 style=\"text-align: left\">Implementing zeep client:<\/h3>\n<p>The first thing that you&#8217;ll need to do is, install the zeep python library as:<\/p>\n<pre class=\"brush:py\">pip install zeep<\/pre>\n<p>Now, in your python code, you&#8217;ll need to import Client from zeep and then instantiate the same by passing the wsdl url in it as shown below:<\/p>\n<pre class=\"brush:py\">from zeep import Client<\/pre>\n<pre class=\"brush:py\">wsdl =\u00a0\"https:\/\/wsvc.cdiscount.com\/MarketplaceAPIService.svc?wsdl\"\nclient = Client(wsdl)<\/pre>\n<p>You can also pass user autherntication details(username and passowrd) in case the wsdl is password protected. For this, you&#8217;ll need to create the Session object as shown below:<\/p>\n<pre class=\"brush:py\">from zeep import Client\nfrom requests import Session\nfrom requests.auth import HTTPBasicAuth\nfrom zeep.transports import Transport<\/pre>\n<pre class=\"brush:py\">wsdl = &lt;wsdl_url&gt;\nsession = Session()\nsession.auth = HTTPBasicAuth(&lt;username&gt;, &lt;password&gt;)<\/pre>\n<pre class=\"brush:py\">#An additional argument 'transport' is passed with the authentication details\nclient = Client(wsdl, transport=Transport(session=session))\n<\/pre>\n<h3>Passing Parameters using Zeep:<\/h3>\n<p>As I mentioned above, you just need to pass the request parameters as a standard python dictionary and zeep will internally convert it to the final xml.<\/p>\n<p>For instance:<\/p>\n<pre class=\"brush:py\">request_data = {\n    'account_id': '1234abc',\n    'sender': {\n        'street': '1226  Denver Avenue',\n        'city': 'Anaheim',\n        'state': 'CA',\n        'zip': '92801',\n        'country': 'US',\n    },\n    'receiver': {\n        'street': '4040  Leo Street',\n        'city': 'Pittsburgh',\n        'state': 'PA',\n        'zip': '15205',\n        'country': 'US',\n    },\n    'attributes': {\n        'item': {\n            'id': '0',\n            'unitPrice': '12.34',\n            'quantity': '1',\n        },\n        'service': {\n            'delivery': 'Ground',\n        }\n    }\n}\n<\/pre>\n<p>The above dictionary will be converted to the xml something similar to:<\/p>\n<pre class=\"brush:xml\">&lt;account_id&gt;1234abc&lt;\/account_id&gt;\n&lt;sender&gt;\n    &lt;street&gt;1226  Denver Avenue&lt;\/street&gt;\n    &lt;city&gt;Anaheim&lt;\/city&gt;\n    &lt;state&gt;CA&lt;\/state&gt;\n    &lt;zip&gt;92801&lt;\/zip&gt;\n    &lt;country&gt;US&lt;\/country&gt;\n&lt;\/sender&gt;\n&lt;receiver&gt;\n    &lt;street&gt;4040  Leo Street&lt;\/street&gt;\n    &lt;city&gt;Pittsburgh&lt;\/city&gt;\n    &lt;state&gt;PA&lt;\/state&gt;\n    &lt;zip&gt;15205&lt;\/zip&gt;\n    &lt;country&gt;US&lt;\/country&gt;\n&lt;\/receiver&gt;\n&lt;attributes&gt;\n    &lt;item&gt;\n        &lt;id&gt;0&lt;\/id&gt;\n        &lt;unitPrice&gt;12.34&lt;\/unitPrice&gt;\n        &lt;quantity&gt;1&lt;\/quantity&gt;\n    &lt;\/item&gt;\n    &lt;service&gt;\n        &lt;delivery&gt;Ground&lt;\/delivery&gt;\n    &lt;\/service&gt;\n&lt;\/attributes&gt;<\/pre>\n<p>Zeep detects the xml schema from the wsdl file that is passed while creating the client object. Wsdl(Web Service Description Language) contains the required description about the endpoint. It contains the list of operations available and also states the parameters that each operation requires. Zeep uses this information to map the passed request\u00a0 dictionary to the corresponding xml.<\/p>\n<h3>Envoking web service methods:<\/h3>\n<p>You can use the operations defined in the wsdl using the simple syntax shown below:<\/p>\n<pre class=\"brush:py\">response = client.service.sendData(**request_data)\n#Here 'request_data' is the request parameter dictionary.\n#Assuming that the operation named 'sendData' is defined in the passed wsdl.\n<\/pre>\n<h3>The response object:<\/h3>\n<p>Zeep response is similar to a python dictionary object(key-value pair) so it&#8217;s very easy to obtain the desired values from the response object using the following syntax:<\/p>\n<pre class=\"brush:py\">response['key']<\/pre>\n<p>That&#8217;s it. If you like this post, it would be great if you could add your feedback and suggestions in the comment section. Also feel free to share your queries down below. Happy coding. \ud83d\ude42<\/p>\n<p>Thanks!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction: Working with SOAP based web services can sometimes be a time taking task when you have to write the complete XML for making API requests and then parse the response xml to fetch the desired results. That&#8217;s a headache right? Well, that&#8217;s when zeep comes into play. Zeep is a pure-python module. The best <a href=\"https:\/\/webkul.com\/blog\/python-soap-clients-with-zeep\/\">[&#8230;]<\/a><\/p>\n","protected":false},"author":175,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1173],"tags":[],"class_list":["post-162778","post","type-post","status-publish","format-standard","hentry","category-api-2"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Python SOAP Clients With Zeep - Webkul Blog<\/title>\n<meta name=\"description\" content=\"Consuming SOAP web services using python&#039;s Zeep library. Aditya Sharma, Webkul Software Pvt Ltd. #Python # SOAP #ZEEP\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/webkul.com\/blog\/python-soap-clients-with-zeep\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python SOAP Clients With Zeep - Webkul Blog\" \/>\n<meta property=\"og:description\" content=\"Consuming SOAP web services using python&#039;s Zeep library. Aditya Sharma, Webkul Software Pvt Ltd. #Python # SOAP #ZEEP\" \/>\n<meta property=\"og:url\" content=\"https:\/\/webkul.com\/blog\/python-soap-clients-with-zeep\/\" \/>\n<meta property=\"og:site_name\" content=\"Webkul Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webkul\/\" \/>\n<meta property=\"article:published_time\" content=\"2019-02-18T04:22:30+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-09-14T08:58:16+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-og.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"630\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Aditya Sharma\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@webkul\" \/>\n<meta name=\"twitter:site\" content=\"@webkul\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Aditya Sharma\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/webkul.com\/blog\/python-soap-clients-with-zeep\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/python-soap-clients-with-zeep\/\"},\"author\":{\"name\":\"Aditya Sharma\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/87db1262c47801c9d6948cdd050c27f1\"},\"headline\":\"Python SOAP Clients With Zeep\",\"datePublished\":\"2019-02-18T04:22:30+00:00\",\"dateModified\":\"2019-09-14T08:58:16+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/python-soap-clients-with-zeep\/\"},\"wordCount\":357,\"commentCount\":16,\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"articleSection\":[\"API\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/webkul.com\/blog\/python-soap-clients-with-zeep\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/webkul.com\/blog\/python-soap-clients-with-zeep\/\",\"url\":\"https:\/\/webkul.com\/blog\/python-soap-clients-with-zeep\/\",\"name\":\"Python SOAP Clients With Zeep - Webkul Blog\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/#website\"},\"datePublished\":\"2019-02-18T04:22:30+00:00\",\"dateModified\":\"2019-09-14T08:58:16+00:00\",\"description\":\"Consuming SOAP web services using python's Zeep library. Aditya Sharma, Webkul Software Pvt Ltd. #Python # SOAP #ZEEP\",\"breadcrumb\":{\"@id\":\"https:\/\/webkul.com\/blog\/python-soap-clients-with-zeep\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/webkul.com\/blog\/python-soap-clients-with-zeep\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/webkul.com\/blog\/python-soap-clients-with-zeep\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/webkul.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Python SOAP Clients With Zeep\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/webkul.com\/blog\/#website\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"name\":\"Webkul Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/webkul.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/webkul.com\/blog\/#organization\",\"name\":\"WebKul Software Private Limited\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"contentUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"width\":380,\"height\":380,\"caption\":\"WebKul Software Private Limited\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webkul\/\",\"https:\/\/x.com\/webkul\",\"https:\/\/www.instagram.com\/webkul\/\",\"https:\/\/www.linkedin.com\/company\/webkul\",\"https:\/\/www.youtube.com\/user\/webkul\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/87db1262c47801c9d6948cdd050c27f1\",\"name\":\"Aditya Sharma\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/108027c738eda2c8d5924eef90b90eb75c9128bca8e6bc61314be4f5b6f1c37d?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/108027c738eda2c8d5924eef90b90eb75c9128bca8e6bc61314be4f5b6f1c37d?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g\",\"caption\":\"Aditya Sharma\"},\"url\":\"https:\/\/webkul.com\/blog\/author\/aditya-sharma185\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Python SOAP Clients With Zeep - Webkul Blog","description":"Consuming SOAP web services using python's Zeep library. Aditya Sharma, Webkul Software Pvt Ltd. #Python # SOAP #ZEEP","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/webkul.com\/blog\/python-soap-clients-with-zeep\/","og_locale":"en_US","og_type":"article","og_title":"Python SOAP Clients With Zeep - Webkul Blog","og_description":"Consuming SOAP web services using python's Zeep library. Aditya Sharma, Webkul Software Pvt Ltd. #Python # SOAP #ZEEP","og_url":"https:\/\/webkul.com\/blog\/python-soap-clients-with-zeep\/","og_site_name":"Webkul Blog","article_publisher":"https:\/\/www.facebook.com\/webkul\/","article_published_time":"2019-02-18T04:22:30+00:00","article_modified_time":"2019-09-14T08:58:16+00:00","og_image":[{"width":1200,"height":630,"url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-og.png","type":"image\/png"}],"author":"Aditya Sharma","twitter_card":"summary_large_image","twitter_creator":"@webkul","twitter_site":"@webkul","twitter_misc":{"Written by":"Aditya Sharma","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/webkul.com\/blog\/python-soap-clients-with-zeep\/#article","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/python-soap-clients-with-zeep\/"},"author":{"name":"Aditya Sharma","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/87db1262c47801c9d6948cdd050c27f1"},"headline":"Python SOAP Clients With Zeep","datePublished":"2019-02-18T04:22:30+00:00","dateModified":"2019-09-14T08:58:16+00:00","mainEntityOfPage":{"@id":"https:\/\/webkul.com\/blog\/python-soap-clients-with-zeep\/"},"wordCount":357,"commentCount":16,"publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"articleSection":["API"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/webkul.com\/blog\/python-soap-clients-with-zeep\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/webkul.com\/blog\/python-soap-clients-with-zeep\/","url":"https:\/\/webkul.com\/blog\/python-soap-clients-with-zeep\/","name":"Python SOAP Clients With Zeep - Webkul Blog","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/#website"},"datePublished":"2019-02-18T04:22:30+00:00","dateModified":"2019-09-14T08:58:16+00:00","description":"Consuming SOAP web services using python's Zeep library. Aditya Sharma, Webkul Software Pvt Ltd. #Python # SOAP #ZEEP","breadcrumb":{"@id":"https:\/\/webkul.com\/blog\/python-soap-clients-with-zeep\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/webkul.com\/blog\/python-soap-clients-with-zeep\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/webkul.com\/blog\/python-soap-clients-with-zeep\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/webkul.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Python SOAP Clients With Zeep"}]},{"@type":"WebSite","@id":"https:\/\/webkul.com\/blog\/#website","url":"https:\/\/webkul.com\/blog\/","name":"Webkul Blog","description":"","publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/webkul.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/webkul.com\/blog\/#organization","name":"WebKul Software Private Limited","url":"https:\/\/webkul.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","contentUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","width":380,"height":380,"caption":"WebKul Software Private Limited"},"image":{"@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webkul\/","https:\/\/x.com\/webkul","https:\/\/www.instagram.com\/webkul\/","https:\/\/www.linkedin.com\/company\/webkul","https:\/\/www.youtube.com\/user\/webkul\/"]},{"@type":"Person","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/87db1262c47801c9d6948cdd050c27f1","name":"Aditya Sharma","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/108027c738eda2c8d5924eef90b90eb75c9128bca8e6bc61314be4f5b6f1c37d?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/108027c738eda2c8d5924eef90b90eb75c9128bca8e6bc61314be4f5b6f1c37d?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g","caption":"Aditya Sharma"},"url":"https:\/\/webkul.com\/blog\/author\/aditya-sharma185\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/162778","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/users\/175"}],"replies":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/comments?post=162778"}],"version-history":[{"count":19,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/162778\/revisions"}],"predecessor-version":[{"id":197957,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/162778\/revisions\/197957"}],"wp:attachment":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/media?parent=162778"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/categories?post=162778"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/tags?post=162778"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}