Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix versions #3

Merged
merged 2 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 43 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
# Prym

A Python interface for converting results of PromQL range queries into numpy arrays or pandas DataFrames.
A Python interface for converting results of PromQL range queries into numpy
arrays or pandas DataFrames.

## Dependencies
- Python 3.6+
- Python 3.10+
- requests
- numpy
- pandas

## Installation

Prym can be installed directly from Github using pip:
```
pip3 install git+https://github.com/chime-experiment/prym.git
pip install git+https://github.com/chime-experiment/prym.git
```

## Usage
## Example

```
import prym
Expand All @@ -32,6 +34,9 @@ num_array = client.query_range(query, start, end, "5m", pandas=False)
pandas_df = client.query_range(('http_requests_total[5m]'), start, end, "5m", pandas=True)
```

## Usage

Create the prometheus query object:
```
prym.Prometheus(self, url: str)

Expand All @@ -43,22 +48,49 @@ url
Address for the prometheus server to query.
```

Perform an actual range query:
```
prym.Prometheus.query_range(self, query: str, start: float or datetime, end: float or datetime, step: float, int or str, sort: func(dict)=None, pandas: bool=False)

Perform a prometheus range query. This will evaluate a PromQL query and return the results as either a numpy array, or as a pandas DataFrame.
prym.Prometheus.query_range(
self,
query: str,
start: float | datetime,
end: float | datetime,
step: float | int | str,
*,
sort: Callable[[dict], Any] | None = None,
pandas: bool = False,
) -> ResultsTuple | pd.DataFrame:

Perform a prometheus range query.

This will evaluate a PromQL query and return the results as either a numpy
array, or as a pandas DataFrame.

Parameters
-----------
----------
query
A PromQL query string.
start, end
The start and end of the time interval. Either as a datetime or as a floating point UNIX timestamp.
The start and end of the time interval. Either as a datetime or as a
floating point UNIX timestamp.
step
The sample interval, as a prometheus duration string, or as seconds.
sort
An optional function can be passed that generates a sort key from a metric dictionary.
An optional function can be passed that generates a sort key from a
metric dictionary.
pandas
If true, return a `pd.DataFrame` with a DateTimeIndex for the times and a MultiIndex for the column labels.
If true, return a `pd.DataFrame` with a DateTimeIndex for the times and a
MultiIndex for the column labels.

Returns
-------
data
The main dataset, either a numpy array or if `pandas` is set then a
`pd.DataFrame`.
metrics
Only returned if pandas not set. A list of the metric label dictionaries.
times
Only returned if pandas not set. An array of the UNIX timestamps of the
samples.
```

3 changes: 1 addition & 2 deletions prym/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@
from datetime import datetime
from typing import Any

import dunamai as _dunamai
import numpy as np
import pandas as pd
import requests

__version__ = _dunamai.Version.from_any_vcs().serialize(dirty=True)
__version__ = "2023.11.0"

# Get a logger object
logger = logging.getLogger(__name__)
Expand Down
4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ dependencies = [
"requests",
"numpy",
"pandas",
"dunamai",
]
dynamic = ["version"]

[tool.setuptools]
packages = ["prym"]

[tool.setuptools.dynamic]
version = {attr = "prym.__version__"}

[tool.ruff]
select = ["ALL"]
ignore = [
Expand Down
Loading