{"id":9216,"library":"pyformance","title":"Pyformance","description":"Pyformance is a Python library for performance metrics, inspired by Coda Hale's Yammer metrics (now Dropwizard Metrics). It provides various metric types like Counters, Timers, Gauges, and Histograms, along with different reporters (e.g., Console, Graphite). The current version is 0.4, released in 2016. The project is no longer actively maintained.","status":"abandoned","version":"0.4","language":"en","source_language":"en","source_url":"https://github.com/PyCQA/pyformance","tags":["metrics","monitoring","performance","legacy"],"install":[{"cmd":"pip install pyformance","lang":"bash","label":"Install Pyformance"}],"dependencies":[],"imports":[{"note":"MetricRegistry is located in the 'registry' submodule, not directly under the top-level package.","wrong":"from pyformance import MetricRegistry","symbol":"MetricRegistry","correct":"from pyformance.registry import MetricRegistry"},{"note":"Metric types like Counter, Timer, and Gauge are found within the 'meters' submodule.","wrong":"from pyformance import Counter","symbol":"Counter","correct":"from pyformance.meters import Counter"},{"note":"Metric types like Counter, Timer, and Gauge are found within the 'meters' submodule.","wrong":"from pyformance import Timer","symbol":"Timer","correct":"from pyformance.meters import Timer"},{"note":"Metric types like Counter, Timer, and Gauge are found within the 'meters' submodule.","wrong":"from pyformance import Gauge","symbol":"Gauge","correct":"from pyformance.meters import Gauge"}],"quickstart":{"code":"import time\nfrom pyformance import registry, meters, reporters\n\n# 1. Initialize a MetricRegistry\nmetrics = registry.MetricRegistry()\n\n# 2. Create and use a Counter\nrequest_counter = metrics.get_or_create_metric('app.requests.total', meters.Counter)\nrequest_counter.inc() # Increment by 1\nrequest_counter.inc(5) # Increment by 5\n\n# 3. Create and use a Timer\nprocessing_timer = metrics.get_or_create_metric('app.processing_time', meters.Timer)\nwith processing_timer.time():\n    time.sleep(0.05) # Simulate some work\n\n# 4. Create and use a Gauge (custom implementation for dynamic values)\nclass QueueSizeGauge(meters.Gauge):\n    def __init__(self, queue_list):\n        super().__init__()\n        self._queue_list = queue_list\n    def get_value(self):\n        return len(self._queue_list)\n\nmy_queue_data = [1, 2, 3, 4, 5]\nmetrics.add_metric('app.queue.size', QueueSizeGauge(my_queue_data))\n\n# 5. Report metrics (e.g., to console)\nconsole_reporter = reporters.ConsoleReporter()\nconsole_reporter.add_metric_registry(metrics)\nprint(\"\\n--- Pyformance Metrics Report ---\")\nconsole_reporter.report()\nprint(\"---------------------------------\")","lang":"python","description":"This quickstart demonstrates how to initialize a MetricRegistry, create and interact with common metric types (Counter, Timer, Gauge), and report their values using the ConsoleReporter."},"warnings":[{"fix":"For new projects, evaluate actively maintained libraries like `prometheus_client` or `opentelemetry` for robust metrics and monitoring solutions.","message":"Pyformance is not actively maintained since 2016. It may not be compatible with newer Python versions (3.8+) and will not receive security updates or bug fixes. Consider more modern alternatives for new projects.","severity":"breaking","affected_versions":"0.4 and earlier"},{"fix":"If encountering issues on newer Python versions, try running in a Python 3.4-3.7 environment or migrate to a different metrics library. Check your `python_requires` setting if packaging.","message":"The library explicitly requires Python >=2.7 and !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*. While it supports Python 3.4+, compatibility with very recent Python versions (3.8+) is not guaranteed due to lack of testing and maintenance.","severity":"gotcha","affected_versions":"0.4"},{"fix":"Define a custom class inheriting from `meters.Gauge` and override `get_value()`. Then, use `metrics.add_metric('metric.name', MyCustomGauge())` to register it.","message":"When creating a Gauge, you must subclass `pyformance.meters.Gauge` and implement the `get_value` method to return the current metric value. Unlike Counters or Timers, Gauges are not updated directly but rather poll their value.","severity":"gotcha","affected_versions":"0.4"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Import MetricRegistry from its specific submodule: `from pyformance.registry import MetricRegistry`.","cause":"Attempting to import MetricRegistry directly from the top-level 'pyformance' package.","error":"AttributeError: module 'pyformance' has no attribute 'MetricRegistry'"},{"fix":"Import metric types from the 'meters' submodule: `from pyformance.meters import Counter` (or Timer, Gauge).","cause":"Attempting to import metric types (Counter, Timer, Gauge) directly from the top-level 'pyformance' package.","error":"AttributeError: module 'pyformance' has no attribute 'Counter'"},{"fix":"Ensure you are using the correct metric type when calling `get_or_create_metric`. If a metric name needs to change type, it's best to use a new, unique name or clear and reinitialize the registry.","cause":"Trying to register a metric name with `get_or_create_metric` but providing a different metric type than one already registered under that name.","error":"TypeError: Cannot create a new metric 'app.gauge.value' with type <class 'pyformance.meters.Counter'>. A metric with type <class 'pyformance.meters.Gauge'> already exists and types are different."}]}