Python bindings for C++ library for reading Prometheus on-disk data
Project description
pypdu
This module provides basic read-only access to the data contained in Prometheus on-disk files from Python.
pypdu
may be installed from pip (on linux and macOS):
pip install pypdu
Example usage:
#!/usr/bin/env python3
import pypdu
data = pypdu.load("/path/to/stats_data")
for series in data:
print(series.name) # equivalent to series.labels["__name__"]
print(series.labels)
print(len(series.samples)) # number of samples can be computed
# without iterating all of them
for sample in series.samples:
print(f"{sample.timestamp} : {sample.value}")
Or the series and samples can be unpacked:
for name, labels, samples in data:
print(name)
print(labels)
print(len(samples))
for timestamp, value in samples:
print(f"{timestamp} : {value}")
Filtering time series
If only a subset of the time series are desired, pypdu
can filter them based on label values, and avoid parsing unneeded series at all:
for series in data.filter({"__name__":"sysproc_page_faults_raw"}):
This will usually perform better than filtering "manually" in python after the fact.
Multiple labels can be specified:
data.filter({"__name__":"sysproc_page_faults_raw", "proc":"memcached"})
ECMAScript regexes can also be used:
data.filter({"proc":pypdu.regex("^go.*")})
Or even arbitrary Python callbacks:
data.filter({"proc":lambda x: x.startswith("go")})
As shorthand, when filtering on __name__
alone, just a string may be provided.
data.filter("sysproc_page_faults_raw")
Single series lookup
If there is only one time series matching your filter, for convenience you can do:
foobar_series = data[{"__name__":"foobar"}]
This is roughly equivalent to:
foobar_series = next(iter(data.filter({"__name__":"foobar"})))
If there are multiple time series matching your filter, this will silently discard all but the lexicographically first (sorted by the key and value of all labels).
If none match, a KeyError
is raised.
All types of filter demonstrated above with .filter(...)
may be used in this manner also.
Alternative installation steps
setup.py
pypdu
may be installed without pip
. To use, clone the repository as in the installation instructions.
Then run:
python setup.py install
This should also work on Windows, but is untested.
manual .so
Alternatively, following the cmake
steps in the installation instructions to build the project produces a module with a platform-dependent name - for example on MacOS this may be pypdu.cpython-39-darwin.so
.
This can be found either in <build dir>/src/pypdu
or in your chosen installation prefix. This can be used without installing with setup.py
, simply ensure the containing directory is in your PYTHONPATH
.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Hashes for pypdu-0.0.5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 03ce0799ea89f7cac3f51c4f2cf7ef3d32f9405b968ddaf6fb2db5156f1c663c |
|
MD5 | f433e835564481b2ce6b03329437b5f5 |
|
BLAKE2b-256 | 040747c6a4de40ac814af0a7d4552ec88c015c534e1e001ca5fefb42a58133d3 |
Hashes for pypdu-0.0.5-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f5a4ceebaf88351a03907a25b6656a07aa9c3fa38427e3b97914636a39281c3b |
|
MD5 | 28a5762ffe572c45484c899929fcf7e9 |
|
BLAKE2b-256 | 8c3f5cdfc48e03dee4b671d7dd7a47bb78d537be734ae15d8123db0911bb5570 |
Hashes for pypdu-0.0.5-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 69f0b3666b5b47d0c429d1de3c66f39a4695da4d402ad5f2dd945e5aa0cecef1 |
|
MD5 | 6e7214c9661dee0458450ce3e3835ca3 |
|
BLAKE2b-256 | 92cae6bac1daf8cbaa61bb1f495e930af0cb8e7f806f565aa67acf8a963bf4b2 |
Hashes for pypdu-0.0.5-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f6d428aa0bb0a1bf61bf707b27a0e2a492703cf4cb8ce4b8a3f87403f9cae2fe |
|
MD5 | 012d9513483116cdc74ca0507b5a4f25 |
|
BLAKE2b-256 | 49c01516cf8c6d8df02b089424ef0a54ae16ec0c38c83cb83a67b33d4ee4c944 |
Hashes for pypdu-0.0.5-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 221099b4b8a2d881a4155eae176e630d84dd2123d943fce0ea43530cf679eade |
|
MD5 | b7c42ae87c7ff84bac16018127a73ce3 |
|
BLAKE2b-256 | ba540f4e86b976aed29f19b1e7e4bf9379f0638a5b51836fe85f79a1422e8356 |
Hashes for pypdu-0.0.5-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 24a230c463be141cf16296e1b34d62fdb78704379a41bcf850a1e731fa403fce |
|
MD5 | 55158863f4239b99829311b41f2f743f |
|
BLAKE2b-256 | 8e64fd85e5d5fa7f7c198f692a950ec396b5ca1076df7f853f77ce74fd213d6a |
Hashes for pypdu-0.0.5-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1791a78bfbda8dcb5414960a9db6759be1f92c082b5c9e30ad294a7169135437 |
|
MD5 | 347d6b118a7c4efdd8ab192ed1502ff7 |
|
BLAKE2b-256 | 110d41c33dfeece312d9e221293e515070493c7ab19997d1513f532536ce5031 |
Hashes for pypdu-0.0.5-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8fc0431d5db20bcd106bdfbd95fd0325947c629960ea84d56974a4914bede2b5 |
|
MD5 | c30006967bd355fe93b7ea5b411a679d |
|
BLAKE2b-256 | 6da00323434b21f0fe69a51d9f85da3bd15bc195df452a15ffa583751b033296 |
Hashes for pypdu-0.0.5-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 187b1d3090e7fcaf970cc9624eadb078c344233f5eed68059c876416e56deb98 |
|
MD5 | 54e6f2f2e0f03bef480538dde8eff10c |
|
BLAKE2b-256 | eb10b9d6b8ee3d6d25080a0cbe3fcfa6ee9050c4d0145a622edad5cfe4684151 |
Hashes for pypdu-0.0.5-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e79e0ddb67a4bd5d2af69f4bffcdb0ba5bed1e34b282f67bcb8e4e790d9e6587 |
|
MD5 | 1f2baaa6ad6e787bbd90ba55ef4af42b |
|
BLAKE2b-256 | 4d0a02595f3c5426656424eb0974713d06684b1a8e9354ecbf4fc1fa18f91152 |
Hashes for pypdu-0.0.5-cp27-cp27mu-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c46ceffb8e0ca7e1f1e441ab510e651acf02a8a5c7eba286a65eea18c022171e |
|
MD5 | 7e20f3d3a1a78fc77a4081ee4f97dbb9 |
|
BLAKE2b-256 | 27ac97d0e5b4b35c367f05286b6acfcba4151a5ff614171ed08f17b3b18a492d |
Hashes for pypdu-0.0.5-cp27-cp27m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 40191256df86b27339560e601eeb3fd83063f997eab8689907b2248635f7f13b |
|
MD5 | 7f8c7cb8c34fb6c2974f041367e09de4 |
|
BLAKE2b-256 | fb8b10367a1e40aee895629ae3257965a9b19d5c57a0a9a9021fcab31adc80c1 |