tq
tq is a small Python package and CLI for querying JSON records.
It reads JSON Lines, JSON arrays, multiline objects, and consecutive JSON objects from a file or stdin, and writes matching records as JSON.
Get started
Install the Python library only:
pip install tq-query
Install the CLI and its optional dependencies:
pip install "tq-query[cli]"
# or: uv tool install "tq-query[cli]"
The tq command requires the cli extra; without it, the command prints an install hint.
To try tq with OpenRouter model data from models.dev, download the catalog and convert it to models.jsonl:
curl -fsSL https://models.dev/catalog.json \
| jq '.providers.openrouter.models[] | {id, modalities, limit, reasoning, tool_call}' -c \
> models.jsonl
Each line is one model record. Query by identity or fields:
tq 'openai/*[reasoning;tool_call]' models.jsonl
tq '[limit.context>=200000]' models.jsonl
tq '[modalities.input has image]' models.jsonl
tq '[modalities.input has all (text,image)]' models.jsonl
CLI
usage: tq [OPTIONS] QUERY [FILE]
Arguments:
query match expression
file JSON input file; defaults to stdin
Options:
-h, --help show this help message and exit
-k KEY identity field (default: ref, then id)
-r, --reorder order matches by query branch, then input position
-C, --color force colored output
-M, --no-color force uncolored output
-c, --compact compact JSON output, one record per line
Color is enabled for terminals and disabled for pipes. -c controls formatting independently.
Query syntax
A query is a comma-separated list of branches. Each branch may combine an identity pattern with predicates:
IDENTITY[PREDICATE;PREDICATE],IDENTITY[PREDICATE]
Omit the identity to match any record. Branches are OR-ed; predicates within a branch are AND-ed and may be separated by commas or semicolons.
| Syntax | Meaning |
|---|---|
foo* / foo? |
Identity glob: * matches any sequence; ? matches one character |
"foo*" |
Exact identity; wildcards are literal |
f / !f |
f = true / f = false |
f = v / f != v |
Equal / not equal |
f < v, f <= v, f > v, f >= v |
Ordered comparison |
f has v / f has no v |
Array contains / does not contain v |
f has any (a,b) |
Array contains at least one candidate |
f has all (a,b) |
Array contains every candidate |
f has none (a,b) |
Array contains no candidate |
v in f / v not in f |
Aliases for f has v / f has no v |
a.b.c |
Access a nested field |
has any, has all, and has none require at least two candidates.
Quote values when needed; for example, "true" is the text value true. Missing fields never match a predicate, including negative predicates. Explicit null is distinct from a missing field.
Python API
from tq import Query
schema = {"key": "id", "filter": ["reasoning", "tool_call"]}
query = Query.parse("openai/*[reasoning;tool_call]").validate(schema)
record = {
"id": "openai/gpt-5",
"reasoning": True,
"tool_call": True,
}
branch = query.match(record)
Publishing
See PUBLISHING.md for PyPI Trusted Publishing setup and release instructions.
Release files for tq-query 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| tq_query-0.1.0.tar.gz | 16.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| tq_query-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 26.4 kB
Release files / tq_query-0.1.0.tar.gz
| Download URL | tq_query-0.1.0.tar.gz |
|---|---|
| Size | 16.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6b3b85c19b71435b1b03c5001bd59d264352f7bb61b1132ac5f5272de84784b9
|
|
BLAKE2b-256 checksum How to use checksums |
260d6fdbcf18df41b89ad66da6cdba69267ec2ce44bdaa0f555ca9a3bdc7afdf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 25, 2026.
Transparency logRelease files / tq_query-0.1.0-py3-none-any.whl
| Download URL | tq_query-0.1.0-py3-none-any.whl |
|---|---|
| Size | 9.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f6d3d271e2eb98697ac444b0d2a56311f2eae7af89f4ec4f99a2341ae91868b5
|
|
BLAKE2b-256 checksum How to use checksums |
1a126a60a06ff995c78cb60da74b9544c3931b862bed86807ea167c8a0cb0ad1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 25, 2026.
Transparency log