prometheus-fastapi-instrumentator
Instrument your FastAPI app with Prometheus metrics
What it is and what it does
prometheus-fastapi-instrumentator is a middleware library that automatically collects and exposes Prometheus metrics from FastAPI applications. It wraps your FastAPI app to track HTTP request counts, response sizes, request sizes, and request duration across multiple histogram buckets, with metrics grouped by handler, status code, and HTTP method. The library exposes these metrics on a `/metrics` endpoint ready for Prometheus scraping.
Out of the box it provides five default metrics: a counter for total requests, summaries for request and response sizes, and histograms for request duration at both standard and high-resolution bucket levels. You can customize or extend metrics using pre-built closures from the metrics module or write your own instrumentation functions. Configuration options include regex-based route exclusion, environment variable control, label customization, gzip compression, and in-progress request tracking.
Use it for:
- Monitor request latency and throughput across FastAPI endpoints for performance analysis
- Track HTTP response and request sizes to identify bandwidth bottlenecks
- Expose metrics to Prometheus for alerting on error rates or slow endpoints
- Build custom metrics to track application-specific events like language preferences or business logic counters
- Conditionally enable metrics collection in multi-service deployments via environment variables
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Adds Prometheus metrics collection and exposure to FastAPI applications with minimal setup, tracking HTTP request counts, sizes, durations, and custom metrics.
Yes. Low install friction, active maintenance, permissive license, and no known vulnerabilities make this a safe choice. The two-line fast-track setup with sensible defaults covers common monitoring needs, while advanced configuration options support specialized use cases. Suitable for production FastAPI deployments that need Prometheus integration.
Install
prometheus-fastapi-instrumentator on PyPI
pip
pip install prometheus-fastapi-instrumentatoruv
uv add prometheus-fastapi-instrumentatorpoetry
poetry add prometheus-fastapi-instrumentatorInstalling prometheus-fastapi-instrumentator
Before you install
Low install friction with only two runtime dependencies (prometheus-client and starlette). Actively maintained with recent releases; last commit 2026-08-01 and latest release 2026-07-26. Supports current Python versions (3.10 through 3.14).
License in practice
Licensed under ISC (permissive), allowing use in commercial and private projects with minimal restrictions.
Quickstart
pip install prometheus-fastapi-instrumentator
from prometheus_fastapi_instrumentator import Instrumentator
from fastapi import FastAPI
app = FastAPI()
Instrumentator().instrument(app).expose(app)
Requires Python 3.10 or later.
Verify before relying
- Performance overhead of middleware instrumentation under high request volumes
- Cardinality explosion risk with high-dimensionality labels in custom metrics
Package facts
| License | ISC (permissive) |
| Python support | supports the current Python release (>=3.10) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 2 — prometheus-client, starlette |
| Maintenance | actively maintained — 19 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 16,089,530/month — #1,162 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: prometheus_fastapi_instrumentator-8.1.0-py3-none-any.whl
Keywords: prometheus, instrumentation, fastapi, exporter, metrics
Tags
More Monitoring packages
Wraps any iterable to display a real-time…
copyleft · top 100 on PyPI
opentelemetry-semantic-conventionsProvides generated Python code for…
permissive · top 100 on PyPI
opentelemetry-sdkProvides the reference implementation of the…
permissive · top 100 on PyPI
opentelemetry-apiProvides the abstract API and interfaces for…
permissive · top 100 on PyPI
opentelemetry-exporter-otlp-proto-httpExports OpenTelemetry observability data to an…
permissive · top 1,000 on PyPI
opentelemetry-instrumentationProvides automatic instrumentation commands and…
permissive · top 1,000 on PyPI
fan-toolsA collection of internal testing utilities,…
permissive · top 15,000 on PyPI
starlette-exporterCollects and exports Prometheus metrics for…
permissive · top 5,000 on PyPI
prometheus-api-clientConnects to Prometheus monitoring systems and…
permissive · top 5,000 on PyPI
py-grpc-prometheusAdds Prometheus metrics collection to gRPC…
unclear · top 5,000 on PyPI
aioprometheusA Prometheus client library for asyncio…
permissive · top 15,000 on PyPI
starlette-prometheusAdds Prometheus metrics collection and exposure…
copyleft · top 15,000 on PyPI
prometheus-clientInstruments Python applications to expose…
permissive · top 1,000 on PyPI
prometheus-flask-exporterExports HTTP request metrics from Flask…
permissive · top 5,000 on PyPI
airflow-exporterExposes Airflow DAG and task metrics to…
permissive · top 15,000 on PyPI
opentelemetry-exporter-prometheusExports OpenTelemetry metrics to Prometheus for…
permissive · top 1,000 on PyPI