Pangolier

build PromQL by Python code.

install

pip install pangolier

simple usage

basic

For a metric with filters:

from pangolier.metrics import Metric

print(Metric('http_requests_total').filter(
    job='prometheus',
    group='canary'
).to_str())

or with label style and method where:

from pangolier.metrics import Metric
from pangolier.label import Label

print(Metric('http_requests_total').where(
     Label('job') == 'prometheus',
     Label('group') == 'canary',
).to_str())

output:

http_requests_total{job="prometheus", group="canary"}

pretty output

Add pretty=True in to_str for better readability:

from pangolier.metrics import Metric

print(Metric('http_requests_total').filter(
    job='prometheus',
    group='canary'
).to_str(pretty=True))

output:

http_requests_total{
    job="prometheus",
    group="canary"
}

I will always use pretty=True in rest of this document.

read more: