Skip to main content

jpq

jq-style JSON filtering, but with Python expressions.

The parsed stdin JSON is bound to this; the value of the expression is printed as JSON.

Install

From PyPI using uv (recommended):

uv tool install jpq
# alternatively (using pip/pipx):
# pipx install jpq
# pip install --user jpq

From source, after cloning:

uv tool install .

By building locally:

uv build
uv tool install ./dist/jpq-*.whl

Or run straight from the checkout without (re)installing:

$ echo '[1,2]' | uv run main.py 'this[0]'  # 1

Usage

$ echo '{"name":"alice","age":30}' | jpq 'this["name"]'  # "alice"

$ echo '[1,2,3,4,5]' | jpq 'statistics.mean(this)'  # 3

$ echo '{"a": [{"b": 2}]}' | jpq 'this.a[0].b'  # 2

$ echo '[{"status":"ok"},{"status":"error"},{"status":"ok"}]' | jpq 'collections.Counter(el["status"] for el in this)'  # {"ok": 2, "error": 1}

Note that you can access dict keys as attributes, e.g. this.name instead of this["name"].

Missing attributes show the available keys when the object has fewer than 20 keys:

$ echo '{"name":"alice","age":30}' | jpq 'this.abcd'
jpq: AttributeError: abcd (available keys: ['name', 'age'])

Pre-imported in the eval namespace: re, collections, itertools, statistics, math, datetime, plus all builtins.

Run jpq --help for more.

Advanced examples

Pipe an API response through a multi-line expression to reshape it:

$ curl -s https://api.github.com/repos/python/cpython | jpq '
{
"now": (now:=datetime.datetime.now(tz=datetime.UTC)),
"stars": this["stargazers_count"],
"last_pushed_seconds_ago": (
    now - datetime.datetime.fromisoformat(this["pushed_at"])
).total_seconds(),
}'
{
  "now": "2026-05-13T15:05:11.746397+00:00",
  "stars": 72668,
  "last_pushed_seconds_ago": 566.746397
}

Note how the walrus operator (:=) is used to assign now and use it in the expression and how it is serialized to JSON via datetime fallback.

See more examples in the blog post about jpq.

Metadata

Release files for jpq 0.3.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 jpq 0.3.0
File Size Uploaded Provenance Actions
jpq-0.3.0.tar.gz 39.6 kB Without provenance Details for jpq-0.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for jpq 0.3.0
File Interpreter ABI Platform Actions
jpq-0.3.0-py3-none-any.whl Python 3 none any Details for jpq-0.3.0-py3-none-any.whl

Total release size: 56.9 kB

Release files / jpq-0.3.0.tar.gz

Download URL jpq-0.3.0.tar.gz
Size 39.6 kB
Tags Source
SHA-256 checksum
How to use checksums
49a9685f9b7b1e61812652be8b6ab76b464f3cf9bc8bfc07e31233ecc68d6bcd
BLAKE2b-256 checksum
How to use checksums
aa36d32982324303a31339c0b7fe191d465917980ad5cde0ed27b1d00e2d021e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.18 {"installer":{"name":"uv","version":"0.12.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / jpq-0.3.0-py3-none-any.whl

Download URL jpq-0.3.0-py3-none-any.whl
Size 17.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
db96ef5819cb142a50a8fa46aa99571ebf3e7c63be37c9585eeedba82f0c3efc
BLAKE2b-256 checksum
How to use checksums
d6ee8a3adbc6fce820db8dcbb57cf8f13f83666154316223d18489787e856d5e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.18 {"installer":{"name":"uv","version":"0.12.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for jpq 0.3.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