pygments-promql
A PromQL lexer for Pygments.
This Python package provides a Pygments lexer for the Prometheus Query Language. It allows Pygments and other tools (Sphinx, Chroma, etc) to highlight PromQL queries.
Installation
Using pip
To get the latest version from pypi.org:
pip install pygments-promql
Usage
Command-line
In a terminal you can echo and pipe a query directly from stdin:
echo 'prometheus_http_requests_total{code="200"}' | pygmentize -l promql
Or use a file, for example, create the example.promql file with queries from
tests/example.promql.
In this case the option -l promql is not needed because the lexer will be
detected based on the file extension.
Showing colorized output in a terminal:
pygmentize example.promql
To generate a PNG file:
pygmentize -f png -O "line_numbers=False,style=monokai" -o example.png example.promql
Python code
The following example:
from pygments import highlight
from pygments.formatters import HtmlFormatter
from pygments_promql import PromQLLexer
query = 'http_requests_total{handler="/api/comments"}'
print(highlight(query, PromQLLexer(), HtmlFormatter()))
Will generate this HTML output:
<div class="highlight">
<pre>
<span></span>
<span class="nv">http_requests_total</span>
<span class="p">{</span>
<span class="nl">handler</span>
<span class="o">=</span>
<span class="s">"/api/comments"</span>
<span class="p">}</span>
<span class="w"></span>
</pre>
</div>
Use HtmlFormatter(noclasses=True) to include CSS inline styles on every <span> tag.
Sphinx
In order to highlight PromQL syntax in your Sphinx documentation site
you just need to add this 3 lines of Python code at the end of your site's conf.py file:
from sphinx.highlighting import lexers
from pygments_promql import PromQLLexer
lexers['promql'] = PromQLLexer()
Then you will be able to use it like this:
Here's a PromQL example:
.. code-block:: promql
# A metric with label filtering
go_gc_duration_seconds{instance="localhost:9090"}
Testing
If you want to test, play or contribute to this repo:
git clone https://github.com/pabluk/pygments-promql.git
cd pygments-promql/
uv sync --locked --all-extras --dev
uv run pytest -v
Metadata
Release files for pygments-promql 0.2.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pygments_promql-0.2.7.tar.gz | 4.3 kB | Without provenance | Details for pygments_promql-0.2.7.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pygments_promql-0.2.7-py3-none-any.whl | Python 3 | none | any | Details for pygments_promql-0.2.7-py3-none-any.whl |
Total release size: 9.9 kB
Release files / pygments_promql-0.2.7.tar.gz
| Download URL | pygments_promql-0.2.7.tar.gz |
|---|---|
| Size | 4.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a29dfa0360d39f6d43bcaa5c14bbdf4549d1628d26768d12bfab93e9f3e0bcfa
|
|
BLAKE2b-256 checksum How to use checksums |
476c7997dc9479dec7e5c48352546e16f15c7fba5ec55bc2d580401034013028
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.11.2 {"installer":{"name":"uv","version":"0.11.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / pygments_promql-0.2.7-py3-none-any.whl
| Download URL | pygments_promql-0.2.7-py3-none-any.whl |
|---|---|
| Size | 5.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b05ce7d5fd38d0ec96f510694709599a837eac820f20b6a6c9e3eff9627d879a
|
|
BLAKE2b-256 checksum How to use checksums |
93069f5a7fc8f15257b8ebb5834866c820ce6928a8fb6750245151eed41315b8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.11.2 {"installer":{"name":"uv","version":"0.11.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for pygments-promql 0.2.7
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.