Skip to main content

No project description provided

Project description

Pydantic MQL

This library can parse and evaluate conditions using pydantic. The usage is similar to the MongoDB Query Language. But instead of filtering documents within a database collection you can use the library to filter arbitrary application data in memory.

Example Usage

Parsing

from pydantic_mql import Condition
test_json = '{"operator": "$eq", "field": "label", "value": "lab"}'
condition = Condition.model_validate_json(test_json)
print(condition)

Serializing

from pydantic_mql import Condition
condition = Condition(operator='$and', conditions=[
    Condition(operator='$eq', field='label', value='lab'),
    Condition(operator='$lte', field='rating', value=80)
])
print(condition.model_dump())

Condition Eval

test_data = {'rating': 60, 'label': 'lab'}
result = condition.eval(test_data)
print(result)

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

pydantic-mql-0.1.0.tar.gz (4.1 kB view hashes)

Uploaded Source

Built Distribution

pydantic_mql-0.1.0-py3-none-any.whl (4.8 kB view hashes)

Uploaded Python 3

Supported by

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