Skip to main content

tq

tq is a tiny Python package and CLI for querying JSON records from files or stdin.

It reads JSON Lines, arrays of JSON objects, multiline objects, and consecutive JSON objects, then writes matching records as JSON. You can pair it with jq to extract or prepare records.

Get started

Install:

pip install tq-json         # package only
pip install "tq-json[cli]"  # with CLI support

Try tq with OpenRouter models from models.dev:

# Extract models with jq
curl -fsSL https://models.dev/catalog.json \
  | jq '.providers.openrouter.models[] | {id, modalities, limit, reasoning, tool_call}' -c \
  > models.jsonl

# Query with tq
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 automatic for terminals (unless NO_COLOR is set) and plain for pipes; -C and -M override it. -c only controls JSON formatting.

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-json 0.1.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 tq-json 0.1.0
File Size Uploaded
tq_json-0.1.0.tar.gz 17.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for tq-json 0.1.0
File Interpreter ABI Platform
tq_json-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 27.8 kB

Release files / tq_json-0.1.0.tar.gz

Download URL tq_json-0.1.0.tar.gz
Size 17.2 kB
Tags Source
SHA-256 checksum
How to use checksums
9874a31b0335553f75cb71949f7f87644343990a1dccdadeee952a2c6c399a6c
BLAKE2b-256 checksum
How to use checksums
0da4325485eb764ab923061648ea1fec034b95b955b472ff2aa4b900c5176dd0
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 26, 2026.

Transparency log

Release files / tq_json-0.1.0-py3-none-any.whl

Download URL tq_json-0.1.0-py3-none-any.whl
Size 10.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e51112075617e69da1b08af273cd7f6ed719e914994c2e904a662b63b906ffa3
BLAKE2b-256 checksum
How to use checksums
aa88f7f6f925041137b62d65a7087492a3119504439242634cb53c0e6461b79a
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 26, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

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