Skip to main content

OData-Query

Documentation Status Ruff

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
uv add 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.

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()

apply_odata_query also takes the $orderby, $top and $skip query options, as the keyword arguments orderby, top and skip:

query = apply_odata_query(orm_query, "name eq 'test'", orderby="age desc", top=10, skip=20)

Advanced Usage

Not all use cases are as simple as that. Luckily, odata-query is modular and extendable. See the documentation for advanced usage or extending the library for other cases.

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.

Metadata

Release files for odata-query 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for odata-query 1.0.0
File Size Uploaded Provenance Actions
odata_query-1.0.0.tar.gz 32.5 kB Without provenance Details for odata_query-1.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for odata-query 1.0.0
File Interpreter ABI Platform Actions
odata_query-1.0.0-py3-none-any.whl Python 3 none any Details for odata_query-1.0.0-py3-none-any.whl

Total release size: 73.2 kB

Release files / odata_query-1.0.0.tar.gz

Download URL odata_query-1.0.0.tar.gz
Size 32.5 kB
Tags Source
SHA-256 checksum
How to use checksums
796c7fc0fbe2f518f733d82b5a006c9c51810c80ac055414006111b78e7a2206
BLAKE2b-256 checksum
How to use checksums
3f3dbc0bea7d9295ddc6aa0705d96c825a8f107f5d947ea9936ee68c311f985a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.8 {"installer":{"name":"uv","version":"0.13.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / odata_query-1.0.0-py3-none-any.whl

Download URL odata_query-1.0.0-py3-none-any.whl
Size 40.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3a4cd9b0a4685f1764b80f7481f3bba8b285a7d5917759b23f0f14713eb4743e
BLAKE2b-256 checksum
How to use checksums
7d30da4b05635b4b01258a1f8a3202e5d1817696abfab3b402c31c90ecaf3ba2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.8 {"installer":{"name":"uv","version":"0.13.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for odata-query 1.0.0

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page