{"id":413,"library":"prometheus-client","title":"Prometheus Client","description":"Python client for the Prometheus monitoring system, currently at version 0.24.1. It is actively maintained with frequent updates for enhancements and bug fixes.","status":"active","version":"0.24.1","language":"python","source_language":"en","source_url":"https://github.com/prometheus/client_python","tags":["monitoring","metrics","prometheus","client"],"install":[{"cmd":"pip install prometheus-client","lang":"bash","label":"Install Prometheus Client"}],"dependencies":[],"imports":[{"note":"Ensure you import from prometheus_client, not any incorrect paths.","symbol":"CollectorRegistry","correct":"from prometheus_client import CollectorRegistry"}],"quickstart":{"code":"from prometheus_client import start_http_server, CollectorRegistry\nimport time\n\nregistry = CollectorRegistry()\nstart_http_server(8000)\nwhile True:\n    time.sleep(1)","lang":"python","description":"Start a Prometheus server on port 8000."},"warnings":[{"fix":"Ensure your HTTP methods conform to GET or OPTIONS to avoid requests being rejected.","message":"Breaking changes in HTTP method validation introduced in v0.21.0.","severity":"breaking","affected_versions":"< 0.21.0"},{"fix":"Always create and use a CollectorRegistry instance for metric registration.","message":"Incorrect usage of CollectorRegistry may lead to metrics not appearing.","severity":"gotcha","affected_versions":"all"},{"fix":"Investigate application logs, system metrics, and resource usage for the tests. Consider increasing timeouts, optimizing code, or checking for infinite loops/deadlocks.","message":"A timeout occurred during test execution, indicating a potential long-running operation, deadlock, or resource exhaustion.","severity":"gotcha","affected_versions":"all"},{"fix":"Investigate the application's execution flow for potential deadlocks, infinite loops, or resource contention that could cause extended execution times.","message":"The test timed out, indicating a potential infinite loop, deadlock, or an exceptionally long-running operation.","severity":"breaking","affected_versions":"unknown"}],"env_vars":null,"search_vec":"'0.24.1':13 'activ':16 'bug':24 'client':2,4,29 'current':10 'enhanc':22 'fix':25 'frequent':19 'maintain':17 'metric':27 'monitor':8,26 'prometheus':1,7,28 'python':3 'system':9 'updat':20 'version':12","created_at":"2026-03-28T11:15:34.051003+00:00","updated_at":"2026-04-16T18:11:23.742287+00:00","problems":[{"fix":"Ensure the library is installed using `pip install prometheus-client` and then import it correctly using `import prometheus_client` or `from prometheus_client import ...`","cause":"This error occurs when the `prometheus-client` library is not installed, not installed in the active Python environment, or imported incorrectly. A common mistake is trying to import `prometheus.client` instead of `prometheus_client`.","error":"ModuleNotFoundError: No module named 'prometheus_client'"},{"fix":"When creating the metric, define the label names as a list of strings. Then, to set label values, call the `.labels()` method with the corresponding values. For example: `my_gauge = Gauge('my_gauge', 'Description', ['label_name'])` and then `my_gauge.labels('value').set(10)`","cause":"This error typically arises when attempting to access a `.labels()` method directly on a metric object (like a `Gauge` or `Counter`) that was created without specifying label names in its constructor. Labels must be defined when the metric is initialized to allow setting their values later.","error":"AttributeError: 'Gauge' object has no attribute 'labels'"},{"error":"ValueError: Duplicated timeseries in CollectorRegistry"},{"fix":"Ensure each metric is registered only once. Define metrics at the module level or use a pattern to prevent re-registration, especially in tests or applications with hot-reloading. You can pass a specific `registry` to the metric constructor to avoid interfering with the default global registry. For example: `my_gauge = Gauge('my_unique_gauge_name', 'Help text')` (defined once) or use `REGISTRY.unregister(metric)` for testing scenarios, though it's generally discouraged in production.","cause":"This error indicates that you are attempting to register a metric with the same name multiple times within the same `CollectorRegistry`. Prometheus metrics must have unique names within a registry. This often happens when metrics are defined globally and imported multiple times, or when a function creating metrics is called repeatedly.","error":"Collector already registered that provides name: <metric_name>"},{"fix":"Change the port number passed to `start_http_server()` to an available one, or identify and terminate the process currently using the desired port. You can use OS commands like `netstat -tulnp | grep <port>` (Linux) or `lsof -i :<port>` (macOS) to find the offending process.","cause":"This error occurs when `prometheus_client.start_http_server()` is called, but the specified port is already in use by another process on the system.","error":"OSError: [Errno 98] Address already in use"}],"ecosystem":"pypi","meta_description":null,"install_score":100,"quickstart_score":0,"quickstart_tag":"stale","pypi_latest":"0.25.0","cli_name":"","cli_version":null,"type":"library","homepage":"https://prometheus.io","github":"https://github.com/prometheus/client_python","docs":"https://prometheus.github.io/client_python/","changelog":null,"pypi":"https://pypi.org/project/prometheus-client/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["observability","devops"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-28","last_verified":"2026-06-28","next_check":"2026-07-28","install_tag":"verified"}}