python-odata
A simple library for read/write access to OData services.
- Supports OData version 4.0
- Requires JSON format support from the service
- Should work on both Python 2.x and 3.x
Documentation
Available on readthedocs.org
Dependencies
- requests >= 2.0
- python-dateutil
- rich >= 13.3.1
Demo
Northwind ODATA service
Reading data from the Northwind service.
import requests
from datetime import datetime
# you can only import this on the second run, the first run will create the package
# import generated
from odata import ODataService
session = requests.Session()
url = 'http://services.odata.org/V4/Northwind/Northwind.svc/'
service = ODataService(
url="http://services.odata.org/V4/Northwind/Northwind.svc/",
session=session,
base=generated.northwind.ReflectionBase,
reflect_entities=True,
reflect_output_package="generated.northwind")
OrderDetails = generated.northwind.Order_Details
q = service.query(generated.northwind.Customers)
q = q.filter(generated.northwind.Customers.ContactTitle.startswith('Sales'))
q = q.filter(generated.northwind.Customers.PostalCode == '68306')
data = q.first()
query = service.query(OrderDetails)
values = query.all()
values = query \
.filter((OrderDetails.Order.Employee.HomePhone.contains("555")) | (OrderDetails.Order.Employee.City == "London")) \
.filter(OrderDetails.Order.Employee.FirstName.lacks("Steven")) \
.filter(OrderDetails.Order.OrderDate >= datetime(year=1990, month=5, day=1, hour=10, minute=10, second=59, tzinfo=pytz.UTC))\
.expand(OrderDetails.Order, OrderDetails.Order.Employee) \
.order_by(OrderDetails.Order.ShipCountry.asc()) \
.limit(10) \
.all()
for order_details in values:
print(f"Order {order_details.OrderID}")
service.values(order_details)
service.values(order_details.Order)
service.values(order_details.Order.Employee)
import datetime
Order = Service.entities['Order']
Employee = Service.entities['Employee']
empl = Service.query(Employee).first()
query = Service.query(Order)
query = query.filter(Order.ShipCity == 'Berlin')
for order in query:
order.ShippedDate = datetime.datetime.utcnow()
order.Employee = empl
Service.save(order)
TripPin ODATA service (v4)
OData V4 example with Enums.
import logging
import requests
import rich
# comment on first run so you get the generated package
import generated.trippin
from odata import ODataService
requests.packages.urllib3.disable_warnings()
def test_trippin(console):
proxy = {'http': '', 'https': ''}
session = requests.Session()
session.trust_env = False
session.verify = False
session.proxies.update(proxy)
service = ODataService(
url="https://services.odata.org/v4/TripPinServiceRW",
session=session,
#base=generated.trippin.ReflectionBase, # comment on first run
#reflect_entities=True,
reflect_output_package="generated.trippin")
People = generated.trippin.People
q = service.query(People)
values = q.all()
for value in values:
console.rule(f"People {value.FirstName} {value.LastName}")
service.values(value)
if __name__ == "__main__":
logging.basicConfig(level="DEBUG")
console = rich.console.Console()
test_trippin(console)
Writing changes. Note that the real Northwind service is read-only and the data modifications do not work against it.
Metadata
Release files for python-odata 0.8.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| python_odata-0.8.1.tar.gz | 29.6 kB | Without provenance | Details for python_odata-0.8.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| python_odata-0.8.1-py3-none-any.whl | Python 3 | none | any | Details for python_odata-0.8.1-py3-none-any.whl |
Total release size: 67.5 kB
Release files / python_odata-0.8.1.tar.gz
| Download URL | python_odata-0.8.1.tar.gz |
|---|---|
| Size | 29.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d31d80a5edd0ff1edb1dfd9069c323f99f52f84e7471ad933b3758c2f8e95427
|
|
BLAKE2b-256 checksum How to use checksums |
63eca60f6f4e62a3ea6c9d3b7be1744190a2f85e81de726b8496478bed151bbb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / python_odata-0.8.1-py3-none-any.whl
| Download URL | python_odata-0.8.1-py3-none-any.whl |
|---|---|
| Size | 37.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
436329006ccc98464170f61f83198c957b4a272ba7398c91ce259cc43f055459
|
|
BLAKE2b-256 checksum How to use checksums |
a301b3e9b6401114550162c6a469739ed6e5aa781460ff141decb7a5d9ad821a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for python-odata 0.8.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.