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.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5af3b0a2b8d22614f6472b1ec893edd6b8a0e92a2ab37343821eba0f2fa757b7 |
|
MD5 | 6d1391a56a0efcdde0a3bf1beed12fa7 |
|
BLAKE2b-256 | 755a7e3c9597b52c6939720160b163821ca7cc6180e10cb91cad54a9da70ab10 |
Hashes for pypdu-0.0.3-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 06b5d077f9464a3ae6eb5188dbf3bd852cc189f73f410a7d811047ca856f3bde |
|
MD5 | 220cf9eaa01fbcc740ba9d80952838b3 |
|
BLAKE2b-256 | 54b7c7244aa927447d6558c96f3402ed1772575af131edab8a25b31146df7f07 |
Hashes for pypdu-0.0.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e4996a4801ba3ec080633dbeda6ec6e8a536f9dba86196e4199213278149a56b |
|
MD5 | 8cb85e6c98363f8178be247b96c4ec26 |
|
BLAKE2b-256 | 6d2f64112676de6a6360f8e4a584bb7211db25a8d17d5f9b5708f800c34e01cb |
Hashes for pypdu-0.0.3-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7bd42de2022cc1c1038b1bfb7fd7b591a89a51d333b5993d092eb30b95de6a0b |
|
MD5 | 3a9b9dc020e06bfb7565e069b340c1c3 |
|
BLAKE2b-256 | 17a4055987e02673037a0f88447c80b346e5bbe4ebfc1e6193a413dd5794b0be |
Hashes for pypdu-0.0.3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9da7d075010db327dc2358c5f982f63e14e15666799ba7e21d27f4b6f674198c |
|
MD5 | 674e13d4e5f04f54487524ee6802d9f8 |
|
BLAKE2b-256 | d5489adf4763b1cd2eeddb829ce912f91cac5c4eef0a357e160f2728c0357b09 |
Hashes for pypdu-0.0.3-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5516b8fdfe362a702838f847c5a8a1a9a7872e37730e5bfe5ca67a7d7d0a4e78 |
|
MD5 | 0dc7d420a4ee8aa6696f4cf2c2952f01 |
|
BLAKE2b-256 | 832b80cf8a5339f00ed758d94837dbee87d6878f152e5799e08fbb6682a01999 |
Hashes for pypdu-0.0.3-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8b7fb9806ea0ba0c7ee706eebca9a70e6be7a60116b488578056fd36ffde1f00 |
|
MD5 | a90c75eabc91629bf7c792a5f85ad453 |
|
BLAKE2b-256 | 856812cee7103b1cba931e543ba73157ceccaec8891e6782725bd75507000a90 |
Hashes for pypdu-0.0.3-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 74c64def90da42d9a02fa049aba22a21eb8830f150e06dfc52b469f328df4520 |
|
MD5 | 1b0be71e293d3c5f740cfc0a25b8853a |
|
BLAKE2b-256 | 5a1e204303e30ccd1ffa0c38a765a0748634cc937d646827d4d143f6f4e7046a |
Hashes for pypdu-0.0.3-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5c6c28e9e740889fab830e02717eaa1b822fcc728ebd0111dbacef60869d03a4 |
|
MD5 | 08686c0b7baff191c68fa5de3d0b072b |
|
BLAKE2b-256 | 5811d443203f22a9460603c7296dd90febff81b45a73962fa40e119e30355dec |
Hashes for pypdu-0.0.3-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 418528bb3268233da4118fb4dca00a8cc4ae237bb22cedb567af18e4238242f4 |
|
MD5 | e326edf24c17d714c23bf63ca18c8fe6 |
|
BLAKE2b-256 | 766ac93abfe9fdaa97072c772eeed77d5a791cb71d6a7f35827e6475e1e71cd4 |
Hashes for pypdu-0.0.3-cp27-cp27mu-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1d918f6d383892965932e8fd5b0a074bfb5d964617969e893102cd41a835db7a |
|
MD5 | 159e6f634b3ff830ba6ba5d18ef8673c |
|
BLAKE2b-256 | a3d6e5f8a9ecea5a1728d663506828fd955e1729ad01e0bc5c3be8b00ef3a626 |
Hashes for pypdu-0.0.3-cp27-cp27m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | edd4bb032804bd05d14d586eee48a6b1745d9bc08444efd5343cfd793ffb3135 |
|
MD5 | ff1947a90478d2879a7728e9b4093f8d |
|
BLAKE2b-256 | d3d6a21f956cb28a2d22bab5749a9c3209ae29c4ee1ef9e77f3d4bc9eae55fcc |