1- # python- pyodata
1+ # Python OData Client - pyodata
22
3- Enterprise-ready Python OData client
3+ Python OData client which provides comfortable Python agnostic
4+ way for communication with OData services.
45
5- ## Requirements
6-
7- - Python 3.6
8-
9- ## Usage
10-
11- ### Get the service
12-
13- ``` python
14- import requests
15- import pyodata
6+ The goal of this Python module is to hide all OData protocol implementation
7+ details.
168
17- SERVICE_URL = ' http://services.odata.org/V2/Northwind/Northwind.svc/'
18-
19- # Create instance of OData client
20- client = pyodata.Client(SERVICE_URL , requests.Session())
21- ```
22-
23- ### Get one entity identified by its key value
24-
25- ``` python
26- # Get employee identified by 1 and print employee first name
27- employee1 = client.entity_sets.Employees.get_entity(1 ).execute()
28- print employee1.FirstName
29- ```
9+ ## Requirements
3010
31- ### Get one entity identified by its key value which is not scalar
11+ - [ Python >= 3.6 ] ( https://www.python.org/downloads/release/python-368/ )
3212
33- ``` python
34- # Get number of orderd units in the order identified by ProductID 42 and OrderID 10248.
35- order = client.entity_sets.Order_Details.get_entity(OrderID = 10248 , ProductID = 42 ).execute()
36- print (order.Quantity)
37- ```
13+ ## Download and Installation
3814
39- ### Get all entities of an entity set
40-
41- ``` python
15+ You can make use of [ pip] ( https://packaging.python.org/tutorials/installing-packages/#installing-from-vcs )
16+ to install the pyodata module automatically:
4217
43- # Print unique identification (Id) and last name of all cemployees
44- employees = client.entity_sets.Employees.get_entities().select(' EmployeeID,LasttName' ).execute()
45- for employee in employees:
46- print (employee.EmployeeID, employee.LastName)
18+ ``` bash
19+ pip install -e git+https://github.com/SAP/python-pyodata.git
4720```
4821
49- ### Get entities matching a filter
22+ ## Configuration
5023
51- ``` python
52- # Print unique identification (Id) of all employees with name John Smith
53- smith_employees_request = client.entity_sets.Employees.get_entities()
54- smith_employees_request = smith_employees_request.filter(" FirstName eq 'John' and LastName eq 'Smith'" )
55- for smith in smith_employees.execute():
56- print (smith.EmployeeID)
57- ```
24+ You can start building your OData projects straight away after installing the
25+ Python module without any additional configuration steps needed.
5826
59- ### Get entities matching a filter in more Pythonic way
27+ ## Limitations
6028
61- ``` python
62- from pyodata.v2.service import GetEntitySetFilter
29+ There have been no limitations discovered yet.
6330
64- # Print unique identification (Id) of all employees with name John Smith
65- smith_employees_request = client.entity_sets.Employees.get_entities()
66- smith_employees_request = smith_employees_request.filter(GetEntitySetFilter.and_(
67- smith_employees_request.FirstName == ' Jonh' ,
68- smith_employees_request.LastName == ' Smith' ))
69- for smith in smith_employees_request.execute():
70- print (smith.EmployeeID)
71- ```
31+ ## Known Issues
7232
73- ### Creating entity
33+ There are no known issues at this time.
7434
75- You need to use the method set which accepts key value parameters:
35+ ## How to obtain support
7636
77- ``` python
78- employee_data = {
79- ' FirstName' : ' Mark' ,
80- ' LastName' : ' Goody' ,
81- ' Address' : {
82- ' HouseNumber' : 42 ,
83- ' Street' : ' Paradise' ,
84- ' City' : ' Heaven'
85- }
86- }
37+ We accept bug reports, feature requests, questions and comments via [ GitHub issues] ( https://github.com/SAP/python-pyodata/issues )
8738
88- create_request = client.entity_sets.Employees.create_entity()
89- create_request.set(** employee_data)
90-
91- new_employee_entity = create_request.execute()
92- ```
39+ ## Usage
9340
94- or you can do it explicitly:
41+ The only thing you need to do is to import the _ pyodata _ Python module.
9542
9643``` python
97- create_request = client.entity_sets.Employees.create_entity()
98- create_request.set(
99- FirstName = ' Mark' ,
100- LastName = ' Goody' ,
101- Address = {
102- ' HouseNumber' : 42 ,
103- ' Street' : ' Paradise' ,
104- ' City' : ' Heaven'
105- }
106- )
107-
108- new_employee_entity = request.execute()
109- ```
110-
111-
112- ### Batch requests
113-
114- Example of batch request that contains 3 simple entity queries
115- ```
116- client = pyodata.Client(SERVICE_URL, requests.Session())
117-
118- batch = client.create_batch()
119-
120- batch.add_request(client.entity_sets.Employees.get_entity(108))
121- batch.add_request(client.entity_sets.Employees.get_entity(234))
122- batch.add_request(client.entity_sets.Employees.get_entity(23))
123-
124- response = batch.execute()
44+ import requests
45+ import pyodata
12546
126- print(response[0].EmployeeID, response[0].LastName)
127- print(response[1].EmployeeID, response[1].LastName)
128- print(response[1].EmployeeID, response[1].LastName)
129- ```
47+ SERVICE_URL = ' http://services.odata.org/V2/Northwind/Northwind.svc/'
13048
131- Example of batch request that contains simple entity query as well
132- as changest consisting of two requests for entity modification
133- ```
49+ # Create instance of OData client
13450client = pyodata.Client(SERVICE_URL , requests.Session())
135-
136- batch = client.create_batch()
137-
138- batch.add_request(client.entity_sets.Employees.get_entity(108))
139-
140- changeset = client.create_changeset()
141-
142- changeset.add_request(client.entity_sets.Employees.update_entity(45).set(LastName='Douglas'))
143-
144- batch.add_request(changeset)
145-
146- response = batch.execute()
147-
148- print(response[0].EmployeeID, response[0].LastName)
14951```
15052
151- ### Calling a function import
53+ Find more sophisticated examples in the [ USAGE ] ( USAGE.md ) section.
15254
153- ``` python
154- products = client.functions.GetProductsByRating.parameter(' rating' , 16 ).execute()
155- for prod in products:
156- print (prod)
157- ```
158-
159- ## Error handling
160-
161- PyOData returns HttpError when the response code does not match the expected
162- code.
163-
164- In the case you know the implementation of back-end part and you want to show
165- accurate errors reported by your service, you can replace HttpError by your
166- sub-class HttpError by assigning your type into the class member VendorType of
167- the class HttpError.
168-
169- ``` python
170- from pyodata.exceptions import HttpError
171-
172-
173- class MyHttpError (HttpError ):
174-
175- def __init__ (self , message , response ):
176- super (MyHttpError, self ).__init__ (' Better message' , response)
177-
178-
179- HttpError.VendorType = MyHttpError
180- ```
181-
182- The class ``` pyodata.vendor.SAP.BusinessGatewayError ``` is an example of such
183- an HTTP error handling.
184-
185- ## Metadata tests
186-
187- By default, the client makes sure that references to properties, entities and
188- entity sets are pointing to existing elements.
189-
190- The most often problem that we had to deal with was an invalid ValueList annotion
191- pointing to a non-existing property.
192-
193-
194- ### Property has this label
195-
196- ``` python
197-
198- assert client.schema.entity_type(' Customer' ).proprty(' CustomerID' ).label == ' Identifier'
199- ```
200-
201- ### Property has a value helper
202-
203- ``` python
204-
205- assert client.schema.entity_type(' Customer' ).proprty(' City' ).value_helper is not None
206- ```
207-
208-
209- # Contributing
55+ ## Contributing
21056
21157Before contributing, please, make yourself familiar with git. You can [ try git
21258online] ( https://try.github.io/ ) . Things would be easier for all of us if you do
@@ -222,7 +68,7 @@ negative decisions - i.e. why you decided to not do particular things. Please
22268bare in mind that other developers might not understand what the original
22369problem was.
22470
225- ## Full example
71+ ### Full example
22672
22773Here's an example workflow for a project ` PyOData ` hosted on Github
22874Your username is ` yourname ` and you're submitting a basic bugfix or feature.
@@ -243,17 +89,8 @@ Your username is `yourname` and you're submitting a basic bugfix or feature.
24389* Hit 'submit'! And please be patient - the maintainers will get to you when
24490 they can.
24591
246- ## Tips & tricks
247-
248- If you want to avoid creating pull requests that fail on lint errors but you
249- always forgot to run ` make check ` , create the pre-commit file in the director
250- .git/hooks with the following content:
251-
252- ``` bash
253- #! /bin/sh
254-
255- make check
256- ```
92+ ## License
25793
258- Do not forget to run ` chmod +x .git/hooks/pre-commit ` to make the hook script
259- executable.
94+ Copyright (c) 2019 SAP SE or an SAP affiliate company. All rights reserved.
95+ This file is licensed under the Apache Software License, v. 2 except as noted
96+ otherwise in [ the LICENSE file] ( LICENSE )
0 commit comments