Skip to main content

larzmetrics

Application metrics with Prometheus export. Pure Python, zero dependencies.

Instrument your code and expose the numbers in the Prometheus text format every scraper and dashboard understands — without pulling in the official client (and its protobuf).

from larzmetrics import Registry

reg = Registry()
reqs = reg.counter("http_requests_total", "requests", labelnames=["method"])
reqs.labels(method="GET").inc()

reg.gauge("temperature", "temp").set(21.5)

lat = reg.histogram("request_seconds", "latency")
with lat.time():
    handle_request()

print(reg.render())          # Prometheus text exposition format

Why

  • Counters, gauges, histograms — monotonic counters, settable gauges, and histograms with configurable buckets, _sum/_count, and a time() context manager for latencies.
  • Labelsmetric.labels(method="GET").inc(), exactly like the Prometheus client.
  • Scrape-readyrender() produces the standard text exposition format (# HELP/# TYPE, _bucket{le=...}, +Inf), so any Prometheus/Grafana/ OpenMetrics tool reads it. Serve it at /metrics and you're done.
  • Zero dependencies. No prometheus_client, no protobuf.

Install

pip install larzmetrics

Usage

reg = Registry()
c = reg.counter("name", "help", labelnames=["a", "b"])
c.labels(a="1", b="2").inc(5)

g = reg.gauge("temp", "help"); g.set(20); g.inc(); g.dec(2)

h = reg.histogram("lat", "help", buckets=[0.1, 0.5, 1, 2, 5])
h.observe(0.3)
with h.time():
    work()

reg.render()      # str, Prometheus format

Pairs with larzlog for observability and any WSGI app (serve render() at /metrics).

Tests

python -m unittest discover -s tests -v   # 10 tests

The Larz stack

One of 30+ pure-Python, zero-dependency libraries at github.com/larz-scripter.

License

MIT © larz-scripter

Download files

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

Source Distribution

larzmetrics-0.1.0.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

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

larzmetrics-0.1.0-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

Details for the file larzmetrics-0.1.0.tar.gz.

File metadata

  • Download URL: larzmetrics-0.1.0.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.13

File hashes

Hashes for larzmetrics-0.1.0.tar.gz
Algorithm Hash digest
SHA256 5d52f5c06a75fbd908cdee9bca8e257e9590dfc4a86af4a3f1eabad2d33be108
MD5 7e301c4a74eeda45c5aa2b7210ddea3a
BLAKE2b-256 2d2ce661288a572bfd33c2ad01de356e8c10fcc402d2b8a1c2ed038d57003fdc

See more details on using hashes here.

File details

Details for the file larzmetrics-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: larzmetrics-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.13

File hashes

Hashes for larzmetrics-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f9e3539e9790ab4088bede5745301ee95936d479ffb40afd079bb333397405db
MD5 d39a586ddf4c0e45d9c04ff0c18b9ed8
BLAKE2b-256 6d7f99acf7ca2b018bff8515fdfcd343fef9875c00ed93168e50c24a4ae5d53e

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page