MCPcopy Index your code
hub / github.com/GreptimeTeam/promql-parser

github.com/GreptimeTeam/promql-parser @v0.10.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.10.0 ↗ · + Follow
361 symbols 757 edges 20 files 58 documented · 16%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

License Build Status Version codecov

PromQL Lexer and Parser

The goal of this project is to build a PromQL lexer and parser capable of parsing PromQL that conforms with Prometheus Query.

Example

To parse a simple instant vector selector expression:

use promql_parser::parser;

let promql = r#"
    http_requests_total{
        environment=~"staging|testing|development",
        method!="GET"
    } offset 5m
"#;

match parser::parse(promql) {
    Ok(expr) => {
        println!("Prettify:\n{}\n", expr.prettify());
        println!("AST:\n{expr:?}");
    }
    Err(info) => println!("Err: {info:?}"),
}

or you can directly run examples under this repo:

cargo run --example parser

This outputs:

Prettify:
http_requests_total{environment=~"staging|testing|development",method!="GET"} offset 5m

AST:
VectorSelector(VectorSelector { name: Some("http_requests_total"), matchers: Matchers { matchers: [Matcher { op: Re(staging|testing|development), name: "environment", value: "staging|testing|development" }, Matcher { op: NotEqual, name: "method", value: "GET" }] }, offset: Some(Pos(300s)), at: None })

PromQL compliance

This crate declares compatible with prometheus v3.8, which is released at 2025-11-28. Any revision on PromQL after this commit is not guaranteed.

Community Extensions

There are a number of community projects that extend promql-parser or provide integrations with other systems.

Language Bindings

Known Uses

Here are some of the projects known to use promql-parser:

  • GreptimeDB Open Source & Cloud Native Distributed Time Series Database
  • OpenObserve High performance, petabyte scale Elasticsearch/Splunk/Datadog alternative for (logs, metrics, traces, RUM, Error tracking, Session replay)

If your project is using promql-parser, feel free to make a PR to add it to this list.

Contributing

Contributions are highly encouraged!

Pull requests that add support for or fix a bug in a feature in the PromQL will likely be accepted after review.

Licensing

All code in this repository is licensed under the Apache License 2.0.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be licensed as above, without any additional terms or conditions.

Extension points exported contracts — how you extend this code

Prettier (Interface)
Approach -------- When a PromQL query is parsed, it is converted into PromQL AST, which is a nested structure of nodes. [13 …
src/parser/mod.rs
ExprVisitor (Interface)
Trait that implements the [Visitor pattern](https://en.wikipedia.org/wiki/Visitor_pattern) for a depth first walk on [Ex [1 …
src/util/visitor.rs
ExtensionExpr (Interface)
The interface for extending the AST with custom expression node. [1 implementers]
src/parser/ast.rs
ExprVisitorMut (Interface)
Trait that implements the [Visitor pattern](https://en.wikipedia.org/wiki/Visitor_pattern) for a depth first walk on [Ex [1 …
src/util/visitor.rs
Value (Interface)
(no doc)
src/parser/value.rs

Core symbols most depended-on inside this repo

parse
called by 33
src/parser/parse.rs
assert_cases
called by 25
src/parser/parse.rs
pop
called by 19
src/parser/lex.rs
value_type
called by 18
src/parser/ast.rs
assert_matches
called by 14
src/parser/lex.rs
len
called by 14
src/parser/function.rs
peek
called by 11
src/parser/lex.rs
check_ast
called by 11
src/parser/ast.rs

Shape

Function 171
Method 148
Class 29
Enum 8
Interface 5

Languages

Rust98%
Python2%

Modules by API surface

src/parser/ast.rs106 symbols
src/parser/lex.rs64 symbols
src/label/matcher.rs37 symbols
src/util/visitor.rs27 symbols
src/parser/parse.rs21 symbols
src/parser/token.rs20 symbols
src/util/string.rs18 symbols
src/parser/function.rs17 symbols
src/label/mod.rs11 symbols
src/util/duration.rs9 symbols
src/parser/mod.rs8 symbols
scripts/compare_functions.py7 symbols

For agents

$ claude mcp add promql-parser \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page