{"id":3385,"library":"prometheus-api-client","title":"Prometheus API Client for Python","description":"prometheus-api-client is a Python wrapper for the Prometheus HTTP API, providing tools for collecting and processing metrics. The library is currently at version 0.7.0 and maintains an active development cadence with regular updates and feature additions.","status":"active","version":"0.7.0","language":"en","source_language":"en","source_url":"https://github.com/4n4nd/prometheus-api-client-python","tags":["prometheus","monitoring","metrics","api","client","time-series","observability"],"install":[{"cmd":"pip install prometheus-api-client","lang":"bash","label":"Basic Installation"},{"cmd":"pip install prometheus-api-client[dataframe]","lang":"bash","label":"With DataFrame support (pandas, numpy)"},{"cmd":"pip install prometheus-api-client[analytics]","lang":"bash","label":"With Analytics support"},{"cmd":"pip install prometheus-api-client[plot]","lang":"bash","label":"With Plotting support (matplotlib)"}],"dependencies":[{"reason":"Handles HTTP communication with the Prometheus server.","package":"requests","optional":false},{"reason":"HTTP client library, often a dependency of requests.","package":"urllib3","optional":false},{"reason":"Required for DataFrame functionality (e.g., MetricRangeDataFrame, MetricSnapshotDataFrame). Optional since v0.7.0.","package":"pandas","optional":true},{"reason":"Often a dependency of pandas, used for numerical operations within DataFrames. Optional since v0.7.0.","package":"numpy","optional":true},{"reason":"Required for plotting capabilities. Optional since v0.7.0.","package":"matplotlib","optional":true}],"imports":[{"symbol":"PrometheusConnect","correct":"from prometheus_api_client import PrometheusConnect"},{"symbol":"Metric","correct":"from prometheus_api_client import Metric"},{"symbol":"MetricRangeDataFrame","correct":"from prometheus_api_client import MetricRangeDataFrame"},{"symbol":"MetricSnapshotDataFrame","correct":"from prometheus_api_client import MetricSnapshotDataFrame"}],"quickstart":{"code":"import os\nfrom prometheus_api_client import PrometheusConnect\nfrom datetime import datetime, timedelta\n\n# Configure your Prometheus URL. Use environment variable for production.\nprom_url = os.environ.get('PROMETHEUS_URL', 'http://localhost:9090')\n\n# Establish connection to Prometheus\nprom = PrometheusConnect(url=prom_url, disable_ssl=True)\n\n# Get a list of all available metric names\nall_metrics = prom.all_metrics()\nprint(f\"Found {len(all_metrics)} metrics. Example: {all_metrics[:5]}\")\n\n# Query a specific metric for a range of data\nend_time = datetime.now()\nstart_time = end_time - timedelta(hours=1)\nmetric_data = prom.get_metric_range_data(\n    query='up',\n    start_time=start_time,\n    end_time=end_time,\n    step='5m'\n)\nprint(f\"'up' metric data points fetched: {len(metric_data)}\")\n\n# Example of getting current value\ncurrent_up = prom.get_current_metric_value(query='up')\nprint(f\"Current 'up' metric values: {current_up[:2]}\")","lang":"python","description":"This quickstart demonstrates how to connect to a Prometheus host, retrieve all available metric names, query a metric for a specific time range, and fetch its current value. It uses environment variables for the Prometheus URL for better practice."},"warnings":[{"fix":"Update date/time arguments in your code to use `datetime.datetime.now()`, `datetime.timedelta()`, or similar `datetime` objects instead of string representations.","message":"Breaking change in v0.2.0: Date and time range inputs for `Metric` objects and querying methods (`get_metric_range_data`, etc.) changed from accepting strings to requiring `datetime.datetime` or `datetime.timedelta` objects.","severity":"breaking","affected_versions":"<0.2.0"},{"fix":"Install the necessary optional dependencies using `pip install prometheus-api-client[dataframe]`, `[analytics]`, or `[plot]` as required by your application's functionality.","message":"Starting from v0.7.0, `pandas`, `numpy`, and `matplotlib` are no longer default dependencies. If your application relies on DataFrame or plotting functionalities, you must install the library with the corresponding extras (e.g., `pip install prometheus-api-client[dataframe]`).","severity":"breaking","affected_versions":">=0.7.0"},{"fix":"While this might be an internal library issue, if you manually manipulate DataFrames returned by `prometheus-api-client` and use `.append()`, consider migrating to `pd.concat()` for better performance and to avoid future deprecation warnings.","message":"Internal use of `DataFrame.append` (a `pandas` method) may trigger `FutureWarning` in versions where it's still present. The `pandas.DataFrame.append` method is deprecated and will be removed in future `pandas` versions, recommending `pandas.concat` instead.","severity":"deprecated","affected_versions":"All versions (due to `pandas` dependency update)"},{"fix":"For `PrometheusConnect` instances, set a `timeout` parameter in query methods or during initialization. Ensure your Prometheus server, network, and any proxies are configured for appropriate timeout values.","message":"Prometheus queries, especially complex ones or those over large time ranges, can lead to request timeouts. The library added timeout functionality in v0.5.7.","severity":"gotcha","affected_versions":"<0.5.7 (no explicit timeout support), >=0.5.7 (timeouts can be configured)"},{"fix":"Verify the `url` parameter passed to `PrometheusConnect`. If connecting to an HTTPS endpoint with self-signed or untrusted certificates, set `disable_ssl=True` (for development/testing only) or configure proper certificate validation.","message":"Ensure the Prometheus host URL is correct and accessible. Common issues include incorrect protocol (http/https), port (default 9090), or SSL certificate verification failures.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}