Skip to main content
https://readthedocs.org/projects/pymetrics/badge/ https://pepy.tech/badge/pymetrics https://img.shields.io/pypi/l/pymetrics.svg https://api.travis-ci.org/eventbrite/pymetrics.svg https://img.shields.io/pypi/v/pymetrics.svg https://img.shields.io/pypi/wheel/pymetrics.svg https://img.shields.io/pypi/pyversions/pymetrics.svg

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):

METRICS_CONFIG = {
    '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.counter('counter.name').increment()

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

metrics.histogram('histogram.name').set(1730)

with metrics.timer('timer.name'):
    do_something()

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

metrics.publish_all()

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.

License

PyMetrics is licensed under the Apache License, version 2.0.

Installation

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

pip install 'pymetrics~=1.0'
install_requires=[
    ...
    'pymetrics~=1.0',
    ...
]
pymetrics~=1.0
pymetrics = {version="~=1.0"}

Documentation

The complete PyMetrics documentation is available on Read the Docs!

Release files for pymetrics 1.0.10

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pymetrics 1.0.10
File Size Uploaded
pymetrics-1.0.10.tar.gz 24.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pymetrics 1.0.10
File Interpreter ABI Platform
pymetrics-1.0.10-py27.py35.py36.py37.py38-none-any.whl Python 3.7, Python 3.6, Python 2.7, Python 3.8, Python 3.5 none any Details

Total release size: 54.3 kB

Release files / pymetrics-1.0.10.tar.gz

Download URL pymetrics-1.0.10.tar.gz
Size 24.0 kB
Tags Source
SHA-256 checksum
How to use checksums
6170c8294263b93603f3e7f396f6dc7972b6a2fed45d4614678d4e0d7f0e35cf
BLAKE2b-256 checksum
How to use checksums
c7aaddc5e653a56e4c74f14bde58c7c93b8f3a1570a2b88addf028b456b37b65
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.7.13

Release files / pymetrics-1.0.10-py27.py35.py36.py37.py38-none-any.whl

Download URL pymetrics-1.0.10-py27.py35.py36.py37.py38-none-any.whl
Size 30.3 kB
Tags Python 2.7 Python 3.5 Python 3.6 Python 3.7 Python 3.8
SHA-256 checksum
How to use checksums
ef2b1eae7b7711d352864e10b9a786f07f3dcada1fef7d4a7fcc30a9aa7e0407
BLAKE2b-256 checksum
How to use checksums
c6db54cfc87868cb495105664886ba84163ddcb90e8a705b6603f6a472a960d2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.7.13

Release history Release notifications | RSS feed

This release

1.0.10 This release

2 release files

1.0.8

2 release files

1.0.7

2 release files

1.0.6

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.21.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page