Metadata-Version: 2.4
Name: larzmetrics
Version: 0.1.0
Summary: Application metrics (counters, gauges, histograms) with Prometheus text export. Pure Python, zero dependencies.
Author: larz-scripter
License: MIT
Project-URL: Homepage, https://github.com/larz-scripter/larzmetrics
Project-URL: Repository, https://github.com/larz-scripter/larzmetrics
Project-URL: Issues, https://github.com/larz-scripter/larzmetrics/issues
Keywords: metrics,prometheus,monitoring,observability,counter,gauge,histogram,instrumentation,telemetry,zero-dependency
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: license-file

# 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).

```python
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.
- **Labels** — `metric.labels(method="GET").inc()`, exactly like the Prometheus
  client.
- **Scrape-ready** — `render()` 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

```bash
pip install larzmetrics
```

## Usage

```python
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](https://github.com/larz-scripter/larzlog) for observability
and any WSGI app (serve `render()` at `/metrics`).

## Tests

```bash
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](https://github.com/larz-scripter).

## License

MIT © larz-scripter
