Introspecting a WSDL with Python Zeep
Based on the answer from jordanm, I used the following to get all of the data I needed on the available methods
from zeep import Client
from pprint import pprint
wsdl = 'http://webservices.amazon.com/AWSECommerceService/AWSECommerceService.wsdl'
client = Client(wsdl)
def parseElements(elements):
all_elements = {}
for name, element in elements:
all_elements[name] = {}
all_elements[name]['optional'] = element.is_optional
if hasattr(element.type, 'elements'):
all_elements[name]['type'] = parseElements(
element.type.elements)
else:
all_elements[name]['type'] = str(element.type)
return all_elements
interface = {}
for service in client.wsdl.services.values():
interface[service.name] = {}
for port in service.ports.values():
interface[service.name][port.name] = {}
operations = {}
for operation in port.binding._operations.values():
operations[operation.name] = {}
operations[operation.name]['input'] = {}
elements = operation.input.body.type.elements
operations[operation.name]['input'] = parseElements(elements)
interface[service.name][port.name]['operations'] = operations
pprint(interface)
You can access parameter elements with operation.input.body.type.elements
, which is a list of tuples containing element objects. These objects contain information such as the type.
(Pdb) operation.input.body.type.elements
[('MarketplaceDomain', <Element(name='MarketplaceDomain', type=<zeep.xsd.types.builtins.String object at 0x7f1bd8a4b320>)>), ('AWSAccessKeyId', <Element(name='AWSAccessKeyId', type=<zeep.xsd.types.builtins.String object at 0x7f1bd8a4b320>)>), ('AssociateTag', <Element(name='AssociateTag', type=<zeep.xsd.types.builtins.String object at 0x7f1bd8a4b320>)>), ('Validate', <Element(name='Validate', type=<zeep.xsd.types.builtins.String object at 0x7f1bd8a4b320>)>), ('XMLEscaping', <Element(name='XMLEscaping', type=<zeep.xsd.types.builtins.String object at 0x7f1bd8a4b320>)>), ('Shared', <Element(name='Shared', type=<zeep.xsd.dynamic_types.BrowseNodeLookupRequest object at 0x7f1bd8177e48>)>), ('Request', <Element(name='Request', type=<zeep.xsd.dynamic_types.BrowseNodeLookupRequest object at 0x7f1bd8177e48>)>)]
(Pdb) operation.input.body.type.elements[0][1].name
'MarketplaceDomain'
(Pdb) operation.input.body.type.elements[0][1].type.name
'string'
(Pdb) operation.input.body.type.elements[0][1].is_optional
True