OData-Query
odata-query
is a library that parses OData v4 filter strings, and can
convert them to other forms such as Django Queries, SQLAlchemy Queries,
or just plain SQL.
Installation
odata-query
is available on pypi, so can be installed with the package manager
of your choice:
pip install odata-query
# OR
poetry add odata-query
# OR
pipenv install odata-query
The package defines the following optional extra
’s:
django
: If you want to pin a compatible Django version.sqlalchemy
: If you want to pin a compatible SQLAlchemy version.
The following extra
’s relate to the development of this library:
linting
: The linting and code style tools.testing
: Packages for running the tests.docs
: For building the project documentation.
You can install extra
’s by adding them between square brackets during
installation:
pip install odata-query[sqlalchemy]
Quickstart
The most common use case is probably parsing an OData query string, and applying
it to a query your ORM understands. For this purpose there is an all-in-one function:
apply_odata_query
.
Example for Django:
from odata_query.django import apply_odata_query
orm_query = MyModel.objects # This can be a Manager or a QuerySet.
odata_query = "name eq 'test'" # This will usually come from a query string parameter.
query = apply_odata_query(orm_query, odata_query)
results = query.all()
Example for SQLAlchemy ORM:
from odata_query.sqlalchemy import apply_odata_query
orm_query = select(MyModel) # This is any form of Query or Selectable.
odata_query = "name eq 'test'" # This will usually come from a query string parameter.
query = apply_odata_query(orm_query, odata_query)
results = session.execute(query).scalars().all()
Example for SQLAlchemy Core:
from odata_query.sqlalchemy import apply_odata_core
core_query = select(MyTable) # This is any form of Query or Selectable.
odata_query = "name eq 'test'" # This will usually come from a query string parameter.
query = apply_odata_core(core_query, odata_query)
results = session.execute(query).scalars().all()
Contents
- Getting Started
- Using OData with Django
- Using OData with SQLAlchemy
- Using OData with raw SQL
- Parsing OData
- Working with the AST
- Glossary
- How to contribute
- Changelog
- [0.9.0] - 2023-08-17
- [0.8.1] - 2023-02-17
- [0.8.0] - 2023-01-20
- [0.7.2] - 2022-12-19
- [0.7.1] - 2022-12-16
- [0.7.0] - 2022-10-28
- [0.6.0] - 2022-10-28
- [0.5.2] - 2022-03-14
- [0.5.1] - 2022-02-28
- [0.5.0] - 2022-02-28
- [0.4.2] - 2021-12-19
- [0.4.1] - 2021-07-16
- [0.4.0] - 2021-05-28
- [0.3.0] - 2021-05-17
- [0.2.0] - 2021-05-05
- [0.1.0] - 2021-03-12
- API Docs
Contact
Got any questions or ideas? We’d love to hear from you. Check out our contributing guidelines for ways to offer feedback and contribute.
License
Copyright © Gorillini NV. All rights reserved.
Licensed under the MIT License.