promql-parser
What it is and what it does
promql-parser is a Python binding to a Rust-based PromQL parser that converts Prometheus query expressions into an inspectable AST. It lets you parse queries like `rate(http_requests_total{job="api"}[5m])` into structured objects (VectorSelector, MatrixSelector, Call, AggregateExpr, BinaryExpr) that you can examine, walk depth-first, or transform into new expressions. The package also includes duration helpers to parse and format time intervals.
Typical workflows involve parsing a PromQL string, inspecting its structure to extract metric names or matchers, walking the tree to collect information, or transforming nodes to rewrite queries. The AST can be converted back to PromQL string form. No runtime dependencies are required beyond Python itself.
Use it for:
- Extract metric names and label matchers from Prometheus queries for validation or analysis.
- Rewrite or transform PromQL expressions programmatically (e.g., rename metrics, adjust time ranges).
- Build tooling that inspects or validates Prometheus query syntax before execution.
- Walk query trees to collect metadata or enforce query patterns in monitoring systems.
- Parse duration strings from PromQL into Python timedelta objects.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Parses Prometheus query language (PromQL) expressions into a Python-accessible abstract syntax tree that can be inspected, walked, transformed, and formatted back to PromQL.
Yes, if you need to parse or manipulate PromQL queries in Python. The package is actively maintained, has no known vulnerabilities, supports Python >=3.8, and requires no runtime dependencies. Medium install friction (prebuilt wheels for common platforms) is a minor trade-off for a specialized tool with a clear use case.
Install
promql-parser on PyPI
pip
pip install promql-parseruv
uv add promql-parserpoetry
poetry add promql-parserInstalling promql-parser
Before you install
Medium install friction due to compiled wheels; prebuilt binaries available for Python 3.10–3.11 on common platforms. Active maintenance with latest release 67 days ago.
Quickstart
pip install promql-parser
import promql_parser
ast = promql_parser.parse('prometheus_http_requests_total{code="200", job="prometheus"}')
print(ast.prettify())
Requires Python >=3.8; prebuilt wheels available for Python 3.10–3.11 on Linux, macOS, and Windows.
Verify before relying
- Whether the Rust implementation is vendored or requires a separate build toolchain for platforms without prebuilt wheels.
- Whether PyPy support (listed in classifiers) is fully tested or aspirational.
- License details: license_spdx and license_raw are both null despite MIT being mentioned in the description.
Package facts
| License | not declared (unclear) |
| Python support | supports the current Python release (>=3.8) |
| Install friction | medium — platform-specific wheel |
| Runtime dependencies | none |
| Maintenance | actively maintained — 67 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 430,452/month — #6,727 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: promql_parser-0.10.0-cp310-cp310-macosx_10_12_x86_64.whl; promql_parser-0.10.0-cp310-cp310-macosx_11_0_arm64.whl; promql_parser-0.10.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl; promql_parser-0.10.0-cp310-cp310-manylinux_2_17_armv7l.manylinux2014_armv7l.whl; promql_parser-0.10.0-cp310-cp310-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl; promql_parser-0.10.0-cp310-cp310-manylinux_2_17_s390x.manylinux2014_s390x.whl; promql_parser-0.10.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl; promql_parser-0.10.0-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.whl; promql_parser-0.10.0-cp310-cp310-musllinux_1_2_aarch64.whl; promql_parser-0.10.0-cp310-cp310-musllinux_1_2_armv7l.whl; promql_parser-0.10.0-cp310-cp310-musllinux_1_2_i686.whl; promql_parser-0.10.0-cp310-cp310-musllinux_1_2_x86_64.whl; promql_parser-0.10.0-cp310-cp310-win32.whl; promql_parser-0.10.0-cp310-cp310-win_amd64.whl; promql_parser-0.10.0-cp311-cp311-macosx_10_12_x86_64.whl; promql_parser-0.10.0-cp311-cp311-macosx_11_0_arm64.whl; promql_parser-0.10.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl; promql_parser-0.10.0-cp311-cp311-manylinux_2_17_armv7l.manylinux2014_armv7l.whl; promql_parser-0.10.0-cp311-cp311-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl; promql_parser-0.10.0-cp311-cp311-manylinux_2_17_s390x.manylinux2014_s390x.whl
Tags
More Monitoring packages
Wraps any iterable to display a real-time…
copyleft · top 100 on PyPI
opentelemetry-semantic-conventionsProvides generated Python code for…
permissive · top 100 on PyPI
opentelemetry-sdkProvides the reference implementation of the…
permissive · top 100 on PyPI
opentelemetry-apiProvides the abstract API and interfaces for…
permissive · top 100 on PyPI
opentelemetry-exporter-otlp-proto-httpExports OpenTelemetry observability data to an…
permissive · top 1,000 on PyPI
opentelemetry-instrumentationProvides automatic instrumentation commands and…
permissive · top 1,000 on PyPI
syntaqliteParse, format, validate, and tokenize SQLite…
permissive · top 15,000 on PyPI
luaparserParses Lua source code into an abstract syntax…
permissive · top 15,000 on PyPI
cql2Parses, validates, and converts Common Query…
permissive · top 15,000 on PyPI
hogql-parser-rsParses HogQL query expressions into JSON AST…
permissive · top 5,000 on PyPI
pygeofilterParses OGC filtering standards (CQL, CQL JSON,…
permissive · top 15,000 on PyPI
astorastor converts Python abstract syntax trees…
permissive · top 5,000 on PyPI
jsonata-pythonEvaluates JSONata expressions against JSON…
permissive · top 5,000 on PyPI
scim2-filter-parserParses SCIM 2.0 filter query strings into…
permissive · top 5,000 on PyPI
gastProvides a unified Abstract Syntax Tree…
permissive · top 5,000 on PyPI
PyMeta3PyMeta3 compiles pattern-matching grammars…
permissive · top 15,000 on PyPI