Prometrix - Unified Prometheus Client
Overview
This Python package provides a unified Prometheus client that can be used to connect to and query various types of Prometheus instances. The package is based on the prometheus-api-client package , which serves as the foundation for our extended functionality.
The prometrix package enhances the prometheus-api-client by adding vendor-specific authentication methods and other features to handle authorization and signatures for all supported clients. This ensures a secure and seamless connection to the various types of Prometheus instances.
- Coralogix
- GKE (Google Kubernetes Engine)
- Azure
- EKS (Amazon Elastic Kubernetes Service)
- Thanos
- Victoria Metrics
The main function, get_custom_prometheus_connect, allows you to create a custom Prometheus client based on the provided configuration. The configurations for special Prometheus versions are defined through specific classes, each extending the base PrometheusConfig class.
Installation
You can install the package using pip:
pip install prometrix
⚠️ Note: For Python 3.8 support, you must use version 0.2.3 or below of
prometrix.
From0.2.4onward,prometrixrequires Python ≥ 3.9.
Usage
Importing the package
from prometrix import get_custom_prometheus_connect
from prometrix.config import (
PrometheusConfig,
AWSPrometheusConfig,
CoralogixPrometheusConfig,
VictoriaMetricsPrometheusConfig,
AzurePrometheusConfig,
PrometheusApis,
)
Creating a Custom Prometheus Client
To create a custom Prometheus client, you need to pass the appropriate configuration to the get_custom_prometheus_connect function. The function returns an instance of the CustomPrometheusConnect class that represents the client.
# Create a custom Prometheus client for Coralogix Prometheus
coralogix_config = CoralogixPrometheusConfig(
url="https://coralogix-prometheus.example.com",
prometheus_token="YOUR_CORALOGIX_PROMETHEUS_TOKEN",
additional_labels={"job": "coralogix-prometheus"},
)
coralogix_client = get_custom_prometheus_connect(coralogix_config)
# Create a custom Prometheus client for GKE Prometheus
gke_config = PrometheusConfig(
url="https://gke-prometheus.example.com",
disable_ssl=False,
headers={"Authorization": "Bearer YOUR_GKE_PROMETHEUS_TOKEN"},
additional_labels={"job": "gke-prometheus"},
)
gke_client = get_custom_prometheus_connect(gke_config)
# Create a custom Prometheus client for Azure Prometheus
azure_config = AzurePrometheusConfig(
url="https://azure-prometheus.example.com",
disable_ssl=False,
headers={"Authorization": "Bearer YOUR_AZURE_PROMETHEUS_TOKEN"},
azure_resource="YOUR_AZURE_RESOURCE",
azure_metadata_endpoint="https://azure-metadata.example.com",
azure_token_endpoint="https://azure-token.example.com",
azure_client_id="YOUR_AZURE_CLIENT_ID",
azure_tenant_id="YOUR_AZURE_TENANT_ID",
azure_client_secret="YOUR_AZURE_CLIENT_SECRET",
additional_labels={"job": "azure-prometheus"},
)
azure_client = get_custom_prometheus_connect(azure_config)
Similar configuration and creation can be done for EKS, Thanos, and Victoria Metrics Prometheus.
NOTE: You need to replace the placeholder values (e.g., YOUR_CORALOGIX_PROMETHEUS_TOKEN) with your actual credentials and endpoints.
Supported APIs
The prometrix package extends the prometheus-api-client class PrometheusConnect with the following additional functionality:
get_prometheus_flags(self) -> Optional[Dict]
This function allows you to receive the configured flags from Prometheus. It returns a dictionary containing the flags and their respective values set in the Prometheus instance.
check_prometheus_connection(self, params: dict = None)
The check_prometheus_connection function enables you to check the connection status with the Prometheus instance. You can pass an optional dictionary of parameters to customize the connection check. This function returns true if it is able to connect.
safe_custom_query_range
The safe_custom_query_range function retrieves time-series data from Prometheus over a specified range. It returns the queried data in JSON format or raises an exception if the request fails.
Differences between custom_query_range and safe_custom_query_range:
custom_query_rangeis a feature of theprometheus_api_clientlibrary, utilized internally by Prometrix.safe_custom_query_rangereturns the entiredatadictionary from the Prometheus query response, whereascustom_query_rangeonly returns theresultsection.
safe_custom_query
The safe_custom_query function executes a single-point Prometheus query and returns the result in JSON format. It throws an exception in the event of an error.
Differences between custom_query and safe_custom_query:
custom_queryis part of theprometheus_api_clientlibrary, used internally by Prometrix.safe_custom_queryreturns the completedatadictionary of the Prometheus query response, in contrast tocustom_query, which only returns theresultsection.
Contributing
If you'd like to contribute to this package, please follow the guidelines specified in the CONTRIBUTING.md file in the repository.
Releasing
To release a new version, bump the version number in pyproject.toml and run:
poetry publish --build --username=<username> --password=<password>
We're planning to automate this with GitHub actions but it hasn't been fully setup or tested yet.
License
This project is licensed under the MIT License - see the LICENSE.md file for details.
Acknowledgments
This package was inspired by the need to have a flexible and generic Prometheus client that can be easily extended to connect with different Prometheus types. Special thanks to the Prometheus team and the open-source community for their contributions.
Metadata
Release files for prometrix 0.2.12
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| prometrix-0.2.12.tar.gz | 12.4 kB | Without provenance | Details for prometrix-0.2.12.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| prometrix-0.2.12-py3-none-any.whl | Python 3 | none | any | Details for prometrix-0.2.12-py3-none-any.whl |
Total release size: 26.0 kB
Release files / prometrix-0.2.12.tar.gz
| Download URL | prometrix-0.2.12.tar.gz |
|---|---|
| Size | 12.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7f661a86c98a1312180522c0583566ca37f0e87c97d1de67818a90e431e622e2
|
|
BLAKE2b-256 checksum How to use checksums |
a8e39501f37f8fb8d1d96ba97840a1aff67130ff61de2d41c3c25e7fa0bd61ed
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.4 CPython/3.11.9 Darwin/25.4.0
|
Release files / prometrix-0.2.12-py3-none-any.whl
| Download URL | prometrix-0.2.12-py3-none-any.whl |
|---|---|
| Size | 13.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
234ca13fc3fc9438dc31ba44d9d5ab65ccf465906c6fc69bc16531a007b21291
|
|
BLAKE2b-256 checksum How to use checksums |
2f19731364c346ae6a6f97f071245706e20fa582e4e1aafce9e70ba587cd9103
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.4 CPython/3.11.9 Darwin/25.4.0
|
Security for prometrix 0.2.12
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.