Skip to main content

Versatile metrics collection for Python

Project description

PyMetrics is versatile metrics collection library for Python that encapsulates the collection of counters, gauges, histograms, and timers into a generic interface with pluggable publishers so that you can helpfully instrument your applications without suffering vendor lock.

Publishing metrics is a straightforward process involving two steps. First, configure your metrics and publisher(s):

    'version': 2,
    'error_logger_name': 'pymetrics',
    'publishers': [
            'path': 'pymetrics.publishers.datadog.DogStatsdPublisher',
            'kwargs': {
                'host': 'localhost',
                'port': 8135,

Then, use a pymetrics.recorders.base.MetricsRecorder in your application to collect and publish:

from pymetrics.recorders.default import DefaultMetricsRecorder

metrics = DefaultMetricsRecorder(config=settings.METRICS_CONFIG)


metrics.gauge('', tag_name1='tag_value1', tag_name2='tag_value2').set(12)


with metrics.timer(''):

cumulative_timer = metrics.timer('')
for item in items:
    with cumulative_timer:


Provided publisher plugins include Statsd, Datadog, Python Logging, SQLite, and a null publisher. Writing your own is simple and we encourage you to share your work with the community by submitting a pull request.


PyMetrics is licensed under the Apache License, version 2.0.


PyMetrics is available in PyPi and can be installing directly via Pip or listed in, requirements.txt, or Pipfile:

pip install 'pymetrics~=1.0'
pymetrics = {version="~=1.0"}


The complete PyMetrics documentation is available on Read the Docs!

Project details

Download files

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

Files for pymetrics, version 0.21.4
Filename, size File type Python version Upload date Hashes
Filename, size pymetrics-0.21.4-py3-none-any.whl (30.5 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size pymetrics-0.21.4.tar.gz (24.4 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page