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 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">&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.3.tar.gz (3.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: pygments-promql-0.0.3.tar.gz
  • Upload date:
  • Size: 3.4 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.3.tar.gz
Algorithm Hash digest
SHA256 fe8b40c4f5901c037235faa2065bf171ee9b5cb0a25170eb8ba1cc6bdde0a242
MD5 972df5ef1f970cec3d264e53a1b71726
BLAKE2b-256 2ae3e81c379f09f3a3920701316477bdd43243274582ba49e980ad70544137cd

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pygments_promql-0.0.3-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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 70cea75bc6de44f54b80a74ddb99697b3d8416b787134fe1c90c228d9e05a085
MD5 aca10278ae4bfaa938abc7fe5e594da3
BLAKE2b-256 2af67375dc1592f3cb7a78b462c0198b04094c59ba80df0f6726131f8d9403bf

See more details on using hashes here.

Supported by

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