Skip to main content

A PromQL lexer for Pygments

Project description

pygments-promql

Python package

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.

PromQL syntax highlighted

Installation

Using pip

To get the latest version from pypi.org:

pip install pygments-promql

Usage

Command-line

The following examples are using queries from tests/example.promql

Showing colorized output in a terminal:

pygmentize tests/example.promql

Or to generate a PNG file:

pygmentize -f png -O "line_numbers=False,style=monokai" -o example.png tests/example.promql

Python code

The following example:

from pygments import highlight
from pygments.formatters import HtmlFormatter
from 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">&quot;/api/comments&quot;</span>
	<span class="p">}</span>
	<span class="w"></span>
    </pre>
</div>

Use HtmlFormatter(noclasses=True) to include CSS inline styles on every <span> tag.

Testing

If you want to test, play or contribute to this repo:

git clone https://github.com/pabluk/pygments-promql.git
cd pygments-promql/
pip install -r requirements.txt
pip install -e .
pytest -v

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pygments-promql-0.0.2.tar.gz (3.5 kB view details)

Uploaded Source

Built Distribution

pygments_promql-0.0.2-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

Details for the file pygments-promql-0.0.2.tar.gz.

File metadata

  • Download URL: pygments-promql-0.0.2.tar.gz
  • Upload date:
  • Size: 3.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.6.9

File hashes

Hashes for pygments-promql-0.0.2.tar.gz
Algorithm Hash digest
SHA256 af3c8b4b416323449ba6a18121b86be8066656be3f54384040aec9246472e613
MD5 f93c9f9b183018c77827af4acdfbe6bc
BLAKE2b-256 b6c02c8481d135d3dd766184b4e9de7aac775b402dd37f733495f0517beb86e7

See more details on using hashes here.

File details

Details for the file pygments_promql-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: pygments_promql-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 4.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.6.9

File hashes

Hashes for pygments_promql-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b187d43093d72ec46f326ad1deca6eb7482444379b12f7740a064fa90ee255ce
MD5 1bfa969657e3ace3f1ccbc9680d5f516
BLAKE2b-256 e1c6bb605c50ed42b1bbff5c85642bee5ba8c1fa290462a1cad2dff284883d97

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page