Registry / database / odata-query

odata-query

JSON →
library0.10.0pypypi✓ verified 82d ago

A Python library for parsing OData query strings and transpiling them into SQL or other formats. Current version 0.10.0, supports Python 3.7+ (<4.0). Releases are infrequent with minor updates.

pip install odata-query
INSTALL
IMPORT
SIG · ODATA-QUERY
O
odata-query
databasepythonv0.10.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

ODataQuery
import odata_query
from odata_query import ODataQuery

Parse an OData query string and optionally transpile to SQL.

from odata_query import ODataQuery # Parse an OData query string query = ODataQuery("$filter=Name eq 'Alice'&$top=10&$orderby=Age desc") # Access parsed components print(query.filter) # Name eq 'Alice' print(query.top) # 10 print(query.orderby) # Age desc # Transpile to SQL (experimental) from odata_query.transpiler import SqlTranspiler transpiler = SqlTranspiler() sql = transpiler.transpile(query) print(sql) # Output: SELECT * FROM table WHERE Name = 'Alice' ORDER BY Age DESC LIMIT 10
Debug
Known issues
gotchaThe library does not build full SQL queries; SqlTranspiler only handles filter, orderby, top, skip. You must provide the SELECT and FROM parts manually.
fix
Use SqlTranspiler to get WHERE, ORDER BY, LIMIT clauses, then combine with your own SELECT/FROM.
affects: <=0.10.0
gotchaODataQuery object attributes (filter, top, etc.) are strings, not structured objects. Do not expect them to be parsed into AST nodes by default.
fix
To access the parsed AST, use query.filter_ast, query.top_ast, etc. (attributes ending with _ast).
affects: <=0.10.0
deprecatedThe 'SqlTranspiler' class is experimental and may change in future versions.
fix
Check the documentation for the latest transpilation API. Consider contributing to the library if you rely on this.
affects: 0.9.0 - 0.10.0
gotchaFilter expression strings may use OData functions like 'contains', 'startswith', but SqlTranspiler may not support all of them. Unsupported functions cause a NotImplementedError.
fix
Sanitize or limit OData query functionality before transpiling. Check the source for supported functions.
affects: <=0.10.0
Upgrade
Version history
0.10.0latest on PyPI · released Jun 28, 2024
Audit
Dependencies
lark-parserrequiredUsed for parsing OData grammar
Agent activity
9 hits · last 30 days
node
8
Resources
odata-query — pip install odata-query · libregistry