Registry / observability / aioprometheus

aioprometheus

JSON →
library23.12.0pypypi✓ verified 88d ago

A Prometheus Python client library for asyncio-based applications. Version 23.12.0. Supports creating metrics (Counter, Gauge, Histogram, Summary) and exposing them via an async HTTP server or pushing to Pushgateway. Compatible with Python 3.8+. Released regularly on PyPI.

pip install aioprometheus
INSTALL
IMPORT
SIG · AIOPROMETHEUS
A
aioprometheus
observabilitypythonv23.12.0
Install
2.9s avg
Import
225ms
Disk
17MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v23.12.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.236s · 19.9MB
glibc
py 3.10–3.95 runs
installs and imports cleanly · install 2.9s · import 0.214s · 20MB
17MB installed
● package 17MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Counter
✓ from aioprometheus import Counter
Gauge
✓ from aioprometheus import Gauge
Histogram
✓ from aioprometheus import Histogram
Summary
✓ from aioprometheus import Summary
MetricsMiddleware
✓ from aioprometheus import MetricsMiddleware
✗ from aioprometheus.middleware import MetricsMiddleware
Old import path removed in 21.x
Service
✓ from aioprometheus import Service
render
✓ from aioprometheus import render
✗ from aioprometheus.renderer import render
Renderer was refactored; use top-level render

Create a Counter, register it with a Service, and expose metrics on port 8080.

from aioprometheus import Counter, Service import asyncio async def main(): counter = Counter("requests_total", "Total requests") counter.inc({"endpoint": "/"}) service = Service() service.prometheus_metrics.add_collector(counter) await service.start(addr="0.0.0.0", port=8080) try: await asyncio.Event().wait() finally: await service.stop() asyncio.run(main())
Debug
Known issues
breakingVersion 21.x removed the old submodule import paths. Use top-level imports: `from aioprometheus import Counter`, not `from aioprometheus.metrics import Counter`.
fix
Update all imports to `from aioprometheus import ...`.
affects: >=21.0.0
deprecatedThe `render` function signature changed in 22.x. Previously `render(metrics, accept_header)` now `render(metrics, accept=None)`. Defaults to text format.
fix
Pass `accept` as keyword argument if needed.
affects: >=22.0.0
gotchaMetrics must be registered with a collector registry before they are exposed. Not doing so results in empty /metrics output.
fix
Always add the metric to the service's collector: `service.prometheus_metrics.add_collector(my_metric)`.
affects: all
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'aioprometheus.metrics'
Importing from old submodules removed in version 21.
fix
Use `from aioprometheus import Counter` instead.
ValueError: The 'labels' argument must be a dict
Passing labels as keyword arguments or non-dict.
fix
Pass labels as a dictionary: `counter.inc({"endpoint": "/"})`.
Upgrade
Version history
23.12.0latest on PyPI · released Dec 27, 2023
Audit
Dependencies

No dependency data recorded yet.

Agent activity
55 hits · last 30 days
node
46
Anthropic
1
OpenAI (training)
1
Resources
aioprometheus — pip install aioprometheus · libregistry