Python metrics libraries

Updated Nov 2026

Python metrics libraries record numeric measurements from a running application, such as request counts, latencies, and queue lengths. An instrument such as a counter or histogram records each value with labels before an exporter sends the totals to a monitoring backend. These libraries let developers and on-call engineers see how production services behave over time.

Popularity

opentelemetry-api has the most monthly downloads in this comparison, at 721.7M.

LibraryMonthly downloadsStarsLast releaseLicense
opentelemetry-api
721.7M
2.7KOct 2026Apache-2.0
prometheus-client
175.4M
4.4KJul 2026Apache-2.0 AND BSD-2-Clause
Sentry SDK
157.9M
2.2KNov 2026MIT
Datadog
58.1M
674Nov 2026BSD-3-Clause
Logfire
19.2M
4.6KNov 2026MIT
Powertools for AWS Lambda
15.6M
3.3KNov 2026MIT
statsd
9.9M
553Nov 2022MIT
AWS Embedded Metrics
2.3M
232Mar 2026Apache-2.0
Downloads: PyPI, last thirty days. Stars and releases: GitHub. Amber: no release in over a year.

Libraries and code examples

opentelemetry-api

Defines metric instruments and provider interfaces; an SDK supplies collection and exporters supply delivery.

Downloads / mo
721.7M
Stars
2.7K
Last release
1.45.2
License
Apache-2.0

Strengths

  • Separates instrumentation from collection. Instrument library code without selecting its application’s metrics backend.
  • Associates attributes with measurements. Attach dimensions to measurements through the metrics API and an installed SDK.

Limitations

  • API alone records nothing. Install and configure an SDK provider to collect measurements.
  • Global provider binds once. Configure the provider once during application startup.

Quickstart

From example.py
$ pip install opentelemetry-api opentelemetry-sdk
from opentelemetry import metrics
from opentelemetry.sdk.metrics import MeterProvider
from opentelemetry.sdk.metrics.export import InMemoryMetricReader
reader = InMemoryMetricReader()
metrics.set_meter_provider(MeterProvider(metric_readers=[reader]))
counter = metrics.get_meter("demo").create_counter("requests")
counter.add(1)

opentelemetry-api examples

From open-source projects on GitHub

prometheus-client

Records application metrics and exposes an HTTP endpoint for Prometheus to scrape.

Downloads / mo
175.4M
Stars
4.4K
Last release
0.26.0
License
Apache-2.0 AND BSD-2-Clause

Strengths

  • Serves a scrape endpoint. Expose metrics over HTTP with the built-in server.
  • Groups observations with labels. Separate related time series by method, endpoint, or other declared dimensions.

Limitations

  • Summaries omit local quantiles. Choose a histogram when queries need latency percentiles.
  • Multiprocess mode restricts features. Custom collectors and label removal are unavailable in multiprocess deployments.

Quickstart

From _index.md
$ pip install prometheus-client
from prometheus_client import Counter
requests = Counter("demo_requests_total", "Processed requests")
requests.inc()

prometheus-client examples

From open-source projects on GitHub

Connects Python applications to Sentry.

Downloads / mo
157.9M
Stars
2.2K
Last release
2.75.0
License
MIT

Quickstart

From metrics.py
$ pip install sentry-sdk
import os
import sentry_sdk
sentry_sdk.init(dsn=os.environ["SENTRY_DSN"])
sentry_sdk.metrics.count("demo.requests", 1)

Sentry SDK examples

From open-source projects on GitHub

Submits application metrics to the Datadog Agent through its DogStatsD client.

Downloads / mo
58.1M
Stars
674
Last release
0.56.0
License
BSD-3-Clause

Strengths

  • Tags individual measurements. Attach tags and a sample rate when incrementing counters.
  • Supports UDP and Unix sockets. Choose the transport that fits the Agent deployment.

Limitations

  • Requires a running Agent. Provide a reachable Datadog Agent for DogStatsD metrics.
  • Buffered metrics need draining. Wait for pending payloads before shutting down a buffered sender.

Quickstart

From index.rst
$ pip install datadog
from datadog import DogStatsd
client = DogStatsd(host="127.0.0.1", port=8125)
client.increment("demo.requests")

Provides the Pydantic Logfire SDK and command-line interface.

Downloads / mo
19.2M
Stars
4.6K
Last release
6.0.0
License
MIT

Quickstart

From README.md
$ pip install logfire
import os
import logfire
logfire.configure(token=os.environ["LOGFIRE_TOKEN"])
counter = logfire.metric_counter("demo.requests")
counter.add(1)

Logfire examples

From open-source projects on GitHub

Powertools for AWS Lambda

Implements serverless best practices in AWS Lambda functions.

Downloads / mo
15.6M
Stars
3.3K
Last release
3.41.0
License
MIT

Quickstart

From metrics.html
$ pip install aws-lambda-powertools
from aws_lambda_powertools import Metrics
from aws_lambda_powertools.metrics import MetricUnit
metrics = Metrics(namespace="Demo")
metrics.add_metric(name="Requests", unit=MetricUnit.Count, value=1)
metrics.flush_metrics()

Powertools for AWS Lambda examples

From open-source projects on GitHub

Sends counters and timings from Python applications to a StatsD daemon.

Downloads / mo
9.9M
Stars
553
Last release
4.0.1
License
MIT

Strengths

  • Batches measurements into packets. Use a pipeline to send several measurements together.
  • Prefixes metric names. Apply a shared prefix when constructing the client.

Limitations

  • Pipelines need thread isolation. Create a separate pipeline for each thread.
  • Timings use milliseconds. Convert durations before passing them to timing.

Quickstart

From README.rst
$ pip install statsd
from statsd import StatsClient
client = StatsClient(host="127.0.0.1", port=8125)
client.incr("demo.requests")

AWS Embedded Metrics

Provides the AWS Embedded Metrics package for Python.

Downloads / mo
2.3M
Stars
232
Last release
3.5.0
License
Apache-2.0

Quickstart

From README.md
$ pip install aws-embedded-metrics
from aws_embedded_metrics import metric_scope
@metric_scope
def record_request(metrics):
    metrics.put_metric("Requests", 1, "Count")
record_request()

AWS Embedded Metrics examples

From open-source projects on GitHub

FAQ

opentelemetry-api suits applications that want vendor-neutral instruments and a choice of backend. prometheus-client suits services that Prometheus scrapes over HTTP. Powertools for AWS Lambda suits Lambda functions that publish to CloudWatch.

opentelemetry-api defines vendor-neutral instruments and leaves collection and export to a configured SDK. prometheus-client records labeled instruments in process and serves them in the Prometheus format over HTTP.

Logfire is the Python SDK and command-line interface for Pydantic Logfire. It provides instruments and readers compatible with OpenTelemetry.

prometheus-client creates labeled counters, histograms, and summaries in the application process. It then serves their values over HTTP for Prometheus to scrape.

Powertools for AWS Lambda is a toolkit for Lambda functions with a metrics facade that writes the CloudWatch Embedded Metric Format by default.

For coding agents

Found your metrics library? Help your agent use it.

Connect Exa so your coding agent can find the library’s documentation, check its API, and look up implementations while you build.

Run in your terminal

claude plugin install exa@claude-plugins-official