pygments-promql


Namepygments-promql JSON
Version 0.1.1 PyPI version JSON
download
home_pagehttps://github.com/pabluk/pygments-promql
SummaryA PromQL lexer for Pygments
upload_time2023-11-04 10:38:07
maintainer
docs_urlNone
authorPablo Seminario
requires_python>=3.7
license
keywords pygments-lexer promql highlighting
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # pygments-promql

[![Python package](https://github.com/pabluk/pygments-promql/workflows/Python%20package/badge.svg)](https://github.com/pabluk/pygments-promql/actions)
[![PyPI](https://img.shields.io/pypi/v/pygments-promql)](https://pypi.org/project/pygments-promql/)
[![PyPI - License](https://img.shields.io/pypi/l/pygments-promql)](https://raw.githubusercontent.com/pabluk/pygments-promql/master/LICENSE)

A PromQL lexer for Pygments.

This Python package provides a [Pygments](https://pygments.org/) lexer for the [Prometheus Query Language](https://prometheus.io/docs/prometheus/latest/querying/basics/). It allows Pygments and other tools ([Sphinx](https://sphinx-doc.org/), [Chroma](https://github.com/alecthomas/chroma), etc) to highlight PromQL queries.

![PromQL syntax highlighted](https://raw.githubusercontent.com/pabluk/pygments-promql/master/tests/example.png)

# Installation

## Using pip

To get the latest version from pypi.org:

```console
pip install pygments-promql
```

# Usage

## Command-line

In a terminal you can echo and pipe a query directly from stdin:

```console
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](https://github.com/pabluk/pygments-promql/blob/master/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:

```console
pygmentize example.promql
```

To generate a PNG file:

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

## Python code

The following example:

```python
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:

```html
<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.

## Sphinx

In order to highlight PromQL syntax in your [Sphinx documentation site](https://www.sphinx-doc.org/en/1.8/index.html)
you just need to add this 3 lines of Python code at the end of your site's `conf.py` file:

```python
from sphinx.highlighting import lexers
from pygments_promql import PromQLLexer
lexers['promql'] = PromQLLexer()
```

Then you will be able to use it like this:

```rst
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:

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

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/pabluk/pygments-promql",
    "name": "pygments-promql",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "pygments-lexer promql highlighting",
    "author": "Pablo Seminario",
    "author_email": "pablo@seminar.io",
    "download_url": "https://files.pythonhosted.org/packages/b0/85/71f7ec3a84b30f73164b20b39c13bbc5d93269c6a18cf9ee88f9f5ead2a3/pygments-promql-0.1.1.tar.gz",
    "platform": null,
    "description": "# pygments-promql\n\n[![Python package](https://github.com/pabluk/pygments-promql/workflows/Python%20package/badge.svg)](https://github.com/pabluk/pygments-promql/actions)\n[![PyPI](https://img.shields.io/pypi/v/pygments-promql)](https://pypi.org/project/pygments-promql/)\n[![PyPI - License](https://img.shields.io/pypi/l/pygments-promql)](https://raw.githubusercontent.com/pabluk/pygments-promql/master/LICENSE)\n\nA PromQL lexer for Pygments.\n\nThis Python package provides a [Pygments](https://pygments.org/) lexer for the [Prometheus Query Language](https://prometheus.io/docs/prometheus/latest/querying/basics/). It allows Pygments and other tools ([Sphinx](https://sphinx-doc.org/), [Chroma](https://github.com/alecthomas/chroma), etc) to highlight PromQL queries.\n\n![PromQL syntax highlighted](https://raw.githubusercontent.com/pabluk/pygments-promql/master/tests/example.png)\n\n# Installation\n\n## Using pip\n\nTo get the latest version from pypi.org:\n\n```console\npip install pygments-promql\n```\n\n# Usage\n\n## Command-line\n\nIn a terminal you can echo and pipe a query directly from stdin:\n\n```console\necho 'prometheus_http_requests_total{code=\"200\"}' | pygmentize -l promql\n```\n\nOr use a file, for example, create the `example.promql` file with queries from\n[tests/example.promql](https://github.com/pabluk/pygments-promql/blob/master/tests/example.promql).\nIn this case the option `-l promql` is not needed because the lexer will be\ndetected based on the file extension.\n\nShowing colorized output in a terminal:\n\n```console\npygmentize example.promql\n```\n\nTo generate a PNG file:\n\n```console\npygmentize -f png -O \"line_numbers=False,style=monokai\" -o example.png example.promql\n```\n\n## Python code\n\nThe following example:\n\n```python\nfrom pygments import highlight\nfrom pygments.formatters import HtmlFormatter\nfrom pygments_promql import PromQLLexer\n\nquery = 'http_requests_total{handler=\"/api/comments\"}'\nprint(highlight(query, PromQLLexer(), HtmlFormatter()))\n```\n\nWill generate this HTML output:\n\n```html\n<div class=\"highlight\">\n    <pre>\n        <span></span>\n\t<span class=\"nv\">http_requests_total</span>\n\t<span class=\"p\">{</span>\n\t<span class=\"nl\">handler</span>\n\t<span class=\"o\">=</span>\n\t<span class=\"s\">&quot;/api/comments&quot;</span>\n\t<span class=\"p\">}</span>\n\t<span class=\"w\"></span>\n    </pre>\n</div>\n```\n\nUse `HtmlFormatter(noclasses=True)` to include CSS inline styles on every `<span>` tag.\n\n## Sphinx\n\nIn order to highlight PromQL syntax in your [Sphinx documentation site](https://www.sphinx-doc.org/en/1.8/index.html)\nyou just need to add this 3 lines of Python code at the end of your site's `conf.py` file:\n\n```python\nfrom sphinx.highlighting import lexers\nfrom pygments_promql import PromQLLexer\nlexers['promql'] = PromQLLexer()\n```\n\nThen you will be able to use it like this:\n\n```rst\nHere's a PromQL example:\n\n.. code-block:: promql\n\n\t# A metric with label filtering\n\tgo_gc_duration_seconds{instance=\"localhost:9090\"}\n\n```\n\n# Testing\n\nIf you want to test, play or contribute to this repo:\n\n```console\ngit clone https://github.com/pabluk/pygments-promql.git\ncd pygments-promql/\npip install -r requirements.txt\npip install -e .\npytest -v\n```\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "A PromQL lexer for Pygments",
    "version": "0.1.1",
    "project_urls": {
        "Homepage": "https://github.com/pabluk/pygments-promql"
    },
    "split_keywords": [
        "pygments-lexer",
        "promql",
        "highlighting"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d6698fac162fcf20c61351d730faaf0e30a7f7ed6858114371faf74b0b4cc192",
                "md5": "e70eb4688723934189b5b0958bf8dc5d",
                "sha256": "01eb5e3977a1953d305bc1ac572409e5e74240ed5ffd53342934c701270f6c1b"
            },
            "downloads": -1,
            "filename": "pygments_promql-0.1.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "e70eb4688723934189b5b0958bf8dc5d",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 5284,
            "upload_time": "2023-11-04T10:38:05",
            "upload_time_iso_8601": "2023-11-04T10:38:05.806161Z",
            "url": "https://files.pythonhosted.org/packages/d6/69/8fac162fcf20c61351d730faaf0e30a7f7ed6858114371faf74b0b4cc192/pygments_promql-0.1.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b08571f7ec3a84b30f73164b20b39c13bbc5d93269c6a18cf9ee88f9f5ead2a3",
                "md5": "03a00917deee08fe15491965f57bc997",
                "sha256": "fa38a1d63c483243acc915d8b2eaa7581093b61ad9b6b6339b37aff8b747017c"
            },
            "downloads": -1,
            "filename": "pygments-promql-0.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "03a00917deee08fe15491965f57bc997",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 6495,
            "upload_time": "2023-11-04T10:38:07",
            "upload_time_iso_8601": "2023-11-04T10:38:07.224082Z",
            "url": "https://files.pythonhosted.org/packages/b0/85/71f7ec3a84b30f73164b20b39c13bbc5d93269c6a18cf9ee88f9f5ead2a3/pygments-promql-0.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-11-04 10:38:07",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "pabluk",
    "github_project": "pygments-promql",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "pygments-promql"
}
        
Elapsed time: 0.16855s