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.8-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fb3873fb2e44efc1f0396bc90a80a37c6e92a9584263c7ab93334e01977e097e |
|
MD5 | 26f2e875e229815a92707460f674e3b6 |
|
BLAKE2b-256 | 997879162918f4e73d6b79976225b71ec067f5c667573b6ac3876d9361cfb36e |
Hashes for pypdu-0.0.8-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4ddfdb86adf82e4103ac5737f99e9ec0cd0736992d276dae6c6f95b023f588ec |
|
MD5 | e7731e95f22e0171bb64d374518233d5 |
|
BLAKE2b-256 | 531e7208e7266982861b94b976d41bc8ee41215c7d4772232629ea579cbd14e1 |
Hashes for pypdu-0.0.8-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b24e1b68df07de53d2e91e763b4068d085dd6411b3403d2b3b97a737dfd3d93a |
|
MD5 | aa37fa6c31c3dda1f0325e80cc8c2c53 |
|
BLAKE2b-256 | 36149da29723dc1dc31e973b192c10d0183c03bba07df3334be05a733702463c |
Hashes for pypdu-0.0.8-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8d5171571712c0d05c94e20f94e79a0a3ef025a9abc24aa364522f6c8c655bb3 |
|
MD5 | 4987a81afc0f6f1d2c2db1fc312a7009 |
|
BLAKE2b-256 | ee9d1cc49908cee221773669e4fd03aa1f19554230cd6ef318e2fbcd969de016 |
Hashes for pypdu-0.0.8-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0a8bc6077a00a756e45dc433b26cc804f2c9e5bc1ac11b23a0c705d3f9a1bec7 |
|
MD5 | e02aa7dc4893d55f0c200fa2a9ce791e |
|
BLAKE2b-256 | 617d48f28ef74146c9f823a0d887587c6c84dfda9bf3e0be69e044770b6136f0 |
Hashes for pypdu-0.0.8-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1dee65549a8056bd1c7d146e93124fee156869bed18d4a691dd9fa01e3f462bc |
|
MD5 | a05ee68da82c15a6dd254fbe16012d03 |
|
BLAKE2b-256 | 20ff31ca34cd316af1ef7a6df958bae89378cd0f8a9345c34131024e17683f04 |
Hashes for pypdu-0.0.8-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e1e3f3c1b503d494635ce2a8924728d3a1786797b14f287985fdaa20d1add938 |
|
MD5 | 53323a6946259f3cc8b80783dbb4693b |
|
BLAKE2b-256 | 32b0ef431df1cdd8905d8f4222d991c5e64eba54b1aa4c6a4f0599d1e4c21e70 |
Hashes for pypdu-0.0.8-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d4674cb860514afccb778be6421658ec241fc8132144502a23a11a50ed2c319f |
|
MD5 | 9a62115311a866e7bf59d6990e3f4ae0 |
|
BLAKE2b-256 | dee04d25e87682a34043fb0eef9f55d25cb1905d8d5af8efae917b10930572aa |
Hashes for pypdu-0.0.8-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7c5e8749af95760dc8f3a091e7ac01d6a364b907478ffe429b2d750d48074da1 |
|
MD5 | 92a38c3f03d61d1274c87f540b69a658 |
|
BLAKE2b-256 | 09be336de3a4f9be6bc073c1d44b7f4443a30bf2b136afb204d3e965bf069ba6 |
Hashes for pypdu-0.0.8-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 63be436289deb62414fa79df5371ca074d26b00fd095c38fbb71334d8d7139fc |
|
MD5 | 1b0722b01946a9bb209649f1f6c1c1e2 |
|
BLAKE2b-256 | ee645b9dc0bb4776428fc36fd397e6f29b6cdf1ca014673a847642b7de2fa25f |
Hashes for pypdu-0.0.8-cp27-cp27mu-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e24d0c2b20fa4975993873bc967ee6e7ed2cf64e5f0a61ee7e83a666be08af6f |
|
MD5 | 596c20ac582b9c7e5989fad8cf745dce |
|
BLAKE2b-256 | 034351ee70037d791063ed2fd2e6044f537d70b5223bf2cd20e9f23737dc81e5 |
Hashes for pypdu-0.0.8-cp27-cp27m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3814bbe690e13f8a5d18d2ecbc1455a6eee3d424ff3d6238622f82a9f4a8c359 |
|
MD5 | 4935c200bad20b51fff0be4429731f6b |
|
BLAKE2b-256 | 2941da293110d3e085f4f4abd590046e92aebdafdd903732a0a6571c8454c416 |