Skip to main content

Filters

Build Status

jqfilters allows to easily create filter objects, which can be applied to JSON-like dictionaries. It is based on the popular JSON parsing tool jq, so the syntax mimics jq's.

For showing both, the same JSON object will be used:

>>> person = {
...     "name": "Alice"
...     "books": [
...         {"name": "The name of the wind"},
...         {"name": "A feast for crows"},
...         {"name": "Continuous delivery"}
...     ],
...     "age": 24,
...     "location": "Lancashire"
... }

Simple Queries

We will create a filter that will return True for people living in Yorkshire.

>>> from jqfilters import Filter
>>> is_from_yorkshire = Filter(op1='.location', operator='eq', op2='Yorshire')
>>> is_from_yorkshire(person)
False

We can also apply some transformation to operands (see jqfilters.operations):

>>> from jqfilters import Filter
>>> reads_a_lot = Filter(op1='.books', transform1='len', operator='ge', op2=3)
>>> reads_a_lot(person)
True

Complex Queries

We will create a filter that will return True when any of the book name is "A game of thrones" or when the person is older than 18. As this specification is more complex, the :meth:fromConfig <jqfilters.filters.Filter.fromConfig> method will be used.

>>> specs = {
...     "op1": {
...         "op1": ".books[].name",
...         "operator": "contains",
...         "op2": "A game of thrones"
...     },
...     "operator": "or",
...     "op2": {
...         "op1": ".age",
...         "operator": "ge",
...         "op2": 18
...     }
... }
>>> adult_got_fans = Filter.fromConfig(specs)
>>> adult_got_fans(person)
True

A filter can be inspected in an easier way by just prompting it:

>>> adult_got_fans
>>> ((.books[].name - contains - A game of thrones) - or - (.age - ge - 18))

Metadata

Release files for jqfilters 0.9.5

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

Source distribution (sdist)

Source distribution for jqfilters 0.9.5
File Size Uploaded Provenance Actions
jqfilters-0.9.5.tar.gz 5.4 kB Without provenance Details for jqfilters-0.9.5.tar.gz

Release files / jqfilters-0.9.5.tar.gz

Download URL jqfilters-0.9.5.tar.gz
Size 5.4 kB
Tags Source
SHA-256 checksum
How to use checksums
242659f6f51b9f885af96a29dfc8d2e8b426d1bd4b0973b4140d4da180bebccd
BLAKE2b-256 checksum
How to use checksums
f3f23343f654f70f30832fb29d2e84e74675a7e7322ed423dae34934d461151d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.3.1 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.0

Security for jqfilters 0.9.5

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