Skip to Content
Author's profile photo Former Member

Using the SAP PI Directory API from Python


The SAP PI Integration Builder Directory exposes a SOAP API to programmatically access, edit, and activate configuration objects. You may want to use it to perform bulk changes, to update routing rules such as a receiver determination at runtime or possibly to automatically generate some documentation. The code below  is an example of how to invoke an API service from Python.

h2. Getting the WSDLs

The service WSDLs are available in the Enterprise Service Repository (ESR) as external defintions under the software component version SAP BASIS 7.10 and the namespace However, as is the case for ESR objects in general, the WSDLs are landscape agnostic, in other words details such as bindings are missing. You can either add these manually or, as I did below, dynamically load the WSDLs from the Webservice Navigator.

h2. Prerequisites

This demo uses the the Python SOAP client Suds available from or the Python Cheese Shop. In addition your PI user requires the following roles:


Demo module

def demo():<br />    “”” <br />    Invoke the ‘query’ operation of the BusinessComponentService and print the<br />    response.<br />    “””<br />    <br />    # Enable logging to print SOAP request and response to console<br />    logging.basicConfig(level=logging.INFO)<br />    logging.getLogger(‘suds.client’).setLevel(logging.DEBUG)<br />    # Create client instance for BusinessComponentService<br />    client = getservice_client(‘BusinessComponentService’)
    # Create empty request object – see print(client) for service & type info
    request = client.factory.create(‘ns2:BusinessComponentQueryIn’)
    # invoke the BusinessComponentService’s “query” operation
    response = client.service.query(request)
if __name__ == ‘__main__’:
    _demo()h2. Resources

SAP Help – Integration Directory API

Assigned Tags

      You must be Logged on to comment or reply to a post.
      Author's profile photo Former Member
      Former Member
      Good stuff HC
      Author's profile photo Iliya Kuznetsov
      Iliya Kuznetsov
      what `result` will be, xml DOM or python datatypes?
      Author's profile photo Former Member
      Former Member
      A Python object similar to request.
      Author's profile photo Steve Oldner
      Steve Oldner
      Nice, I've been wanting to integrate SAP with Python. 

      Thanks for the example!