File: vendors.rst

package info (click to toggle)
python-pyodata 1.11.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,280 kB
  • sloc: python: 7,170; xml: 947; makefile: 67; sh: 15
file content (36 lines) | stat: -rw-r--r-- 1,493 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
Vendor-specific helpers
==============

This document presents the helpers found in ``pyodata.vendor`` 

Get the service proxy client for an OData service published on SAP BTP, ABAP environment
--------------------------------------------------------------------------

Let's assume you have an ABAP environment service instance running on SAP Business Technology
Platform. You have used this instance to provide an OData service by using, for example, the
ABAP RESTful Application Programming Model. To connect to it, you need to provide several attributes 
found in the JSON service key of the instance, as well as your username and password for SAP BTP.

``pyodata.vendor.SAP`` offers a helper that takes the arguments described above, as well as an
existing ``requests.Session`` object (or another one conforming to the same API), and adds the
required token to the session object's authorization header.

The following code demonstrates using the helper.

.. code-block:: python
  
  import pyodata
  from pyodata.vendor import SAP
  import requests
  import json

  with open('key.txt', 'r') as f:
      KEY = json.loads(f.read())

  USER = "MyBtpUser"
  PASSWORD = "MyBtpPassword"
  SERVICE_URL = KEY["url"] + "/sap/opu/odata/sap/" + "ZMyBtpService"

  session = SAP.add_btp_token_to_session(requests.Session(), KEY, USER, PASSWORD)
  # do something more with session object if necessary (e.g. adding sap-client parameter, or CSRF token)
  client = pyodata.Client(SERVICE_URL, session)