{"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,"last_verified":"2026-05-12T13:40:16.001Z","next_check":"2026-06-26T00:00:00.000Z","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,"install_tag":"verified","quickstart_score":0,"quickstart_tag":"stale","pypi_latest":null,"install_checks":{"last_tested":"2026-05-12","tag":"verified","tag_description":"installs cleanly on critical runtimes, fast import, recently tested","results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.21,"mem_mb":6.3,"disk_size":"18.3M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.18,"mem_mb":6.3,"disk_size":"19M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.3,"mem_mb":6.9,"disk_size":"20.3M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.27,"mem_mb":6.9,"disk_size":"21M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.23,"mem_mb":6.5,"disk_size":"12.1M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.24,"mem_mb":6.5,"disk_size":"13M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.23,"mem_mb":6.6,"disk_size":"11.7M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.23,"mem_mb":6.6,"disk_size":"12M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.17,"mem_mb":6.2,"disk_size":"17.8M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.15,"mem_mb":6.2,"disk_size":"18M"}]},"quickstart_checks":{"last_tested":"2026-04-23","tag":"stale","tag_description":"widespread failures or data too old to trust","results":[{"runtime":"python:3.10-alpine","exit_code":-1},{"runtime":"python:3.10-slim","exit_code":-1},{"runtime":"python:3.11-alpine","exit_code":-1},{"runtime":"python:3.11-slim","exit_code":-1},{"runtime":"python:3.12-alpine","exit_code":-1},{"runtime":"python:3.12-slim","exit_code":-1},{"runtime":"python:3.13-alpine","exit_code":-1},{"runtime":"python:3.13-slim","exit_code":-1},{"runtime":"python:3.9-alpine","exit_code":-1},{"runtime":"python:3.9-slim","exit_code":-1}]}}