Skip to main content

An OData query parser and transpiler.

Project description

Quality Gate Status Coverage Documentation Status Code style: black

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

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

odata_query-0.10.0b1.tar.gz (28.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

odata_query-0.10.0b1-py3-none-any.whl (34.8 kB view details)

Uploaded Python 3

File details

Details for the file odata_query-0.10.0b1.tar.gz.

File metadata

  • Download URL: odata_query-0.10.0b1.tar.gz
  • Upload date:
  • Size: 28.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.9.18 Darwin/23.2.0

File hashes

Hashes for odata_query-0.10.0b1.tar.gz
Algorithm Hash digest
SHA256 345a33e0fb9d4f197eca6142703016dcd97b51b5bdb2e78463254cac58bfd671
MD5 288958df16163f945d97b31447b6497d
BLAKE2b-256 f1e19cf756e91960d9d825beddaa2f1c11b5357c26eb6a8eb0f54f20bc25a9d7

See more details on using hashes here.

File details

Details for the file odata_query-0.10.0b1-py3-none-any.whl.

File metadata

  • Download URL: odata_query-0.10.0b1-py3-none-any.whl
  • Upload date:
  • Size: 34.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.9.18 Darwin/23.2.0

File hashes

Hashes for odata_query-0.10.0b1-py3-none-any.whl
Algorithm Hash digest
SHA256 1b84236a4ec27d0cd61672449c06a925b46ef5df9f2da4a0ec11d3a0beb5139a
MD5 34155190a03973cb67b41b920a55adcc
BLAKE2b-256 4f7a46fc023a03cf00bc64e2243fa0fca0edb135de3ef4dd181f4f1aebb49564

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page