promql-parser is a Python binding that provides a fast and robust PromQL (Prometheus Query Language) parser. It leverages a Rust-based parser for efficient conversion of PromQL queries into an Abstract Syntax Tree (AST), enabling programmatic analysis and manipulation of Prometheus queries. The current version is 0.8.0, with releases typically following updates to the underlying Rust parser.
pip install promql-parserVerified import paths — ran on the pinned version, not inferred.
Parse a PromQL query string into its Abstract Syntax Tree (AST) representation. The returned AST is a Python object that mirrors the structure of the PromQL query, allowing for detailed inspection of metric names, labels, functions, and operators.
Monitor the `messense/py-promql-parser` and `GreptimeTeam/promql-parser` GitHub repositories for updates and release notes to ensure compatibility with the PromQL version you are using. Upgrade `promql-parser` promptly when new versions are released to maintain parsing accuracy for evolving PromQL syntax.
Inspect the `print(ast)` output for various query types to understand its structure. Refer to the `GreptimeTeam/promql-parser` documentation (Rust library) for details on the AST node types if deep programmatic manipulation is required, as the Python binding directly exposes this underlying structure.
pip install promql-parser
Correct the PromQL query string to adhere to the supported PromQL syntax. Example of correct usage: `promql_parser.parse('http_requests_total')`Import the `parse` function directly from the top-level `promql_parser` module: `from promql_parser import parse`
Consult the `promql-parser` library's documentation or inspect the AST object's structure (e.g., using `dir()` or `print(ast_node.__dict__)`) to identify the correct attributes for the specific AST node type.
No dependency data recorded yet.