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.6-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a69fccb965677c5ac863070e70492d8d99d682a5f72dcd189a26977717f5935a |
|
MD5 | b38e13b25247f3ef2faf3bd3ce0648f9 |
|
BLAKE2b-256 | d1034043d3acb3373c912224b04c2693fff04eaa72058eca1686d302e718dcb2 |
Hashes for pypdu-0.0.6-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 97447d57f0389dad6a2a45f41f03905e07233cf2a8e6e0af332988b51bd20d9c |
|
MD5 | c7b6d4387d96753ce9ea1e65cffc612d |
|
BLAKE2b-256 | 0dd6426bbcd21ddd95e098bdbdb26c18fd390d64dee6ace343ef75d422a23d0b |
Hashes for pypdu-0.0.6-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4e15b12d5bc81bef29aa3d9abbcd214c5dee7f8da240d2ccdc4ba7803282e415 |
|
MD5 | afaaa8527131adc1ae78c2232df74e2e |
|
BLAKE2b-256 | 12ea88520a229fff3cbd3f70600479e13df8d9acd30a4460c3fbff7b5228875e |
Hashes for pypdu-0.0.6-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1717dafd2b40eceb7b407a4057cb604b146b1c8223a09cbe27ff3d1cf45224d3 |
|
MD5 | 281e53b78fc979e6e245f5859a56122f |
|
BLAKE2b-256 | b61f78f3b055165054fc61a004d12b50f5833e8915d6f6467f15e45c646fe7ed |
Hashes for pypdu-0.0.6-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d760b8c3385d714d14fb4c86f196299b328233ca2cda80f628cd50407e89b73b |
|
MD5 | 364dd276adead1f3c3f52581221261db |
|
BLAKE2b-256 | e625b2daf0627b4ebe084b18f696f3d9e03399c4bd21c5e94e65993bd3cad2c4 |
Hashes for pypdu-0.0.6-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5ddf88927a1560b395c0c7bd6c687d79b8400da370a2c84c0af9b234232d2b99 |
|
MD5 | 93776167caa03a3897a9d8c72f3289f0 |
|
BLAKE2b-256 | 7899beaa34b3f9294c1dc6fc02ce9758becac91d5722bf99959e3d5dd0d9baa3 |
Hashes for pypdu-0.0.6-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 72814c69b2d8a572fcf26352840fa2b39e6550e2e21e246fbde57aa87a7a08c8 |
|
MD5 | eab59f5bce2b34d5557f54039d1269a2 |
|
BLAKE2b-256 | 6bdb96b9ed29238cc0163cea41c45e0906986758057a44730b4e7ad522bc7fbb |
Hashes for pypdu-0.0.6-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1afdf19aee26161c88ab75959fceabfc484130c6bb1a67cab5c261b1183b9e97 |
|
MD5 | 4fd90de454f6457361aeab5e61653416 |
|
BLAKE2b-256 | eca67d9d72355732a91e436a75264d3c96fb97d7ea5a33336f053eda1c91884b |
Hashes for pypdu-0.0.6-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aee95e7fa1ed156ad8acfac3d5fb92907e19602aacb292fe29848a72f72b77fc |
|
MD5 | 5bc62623c8e7acf81cbeebab2b4758df |
|
BLAKE2b-256 | 8477edc479e03dd1dfe34d399846b9734ead374e8d9bbe35de8f0a9aac87ad29 |
Hashes for pypdu-0.0.6-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 98fb97f8565347e4d45251567545a44f26519b2d6f541e2f59a3dd02d98a5252 |
|
MD5 | 3342c572f239414b6b633473a5db381a |
|
BLAKE2b-256 | 225c2f101fffb580d2052676fbed8fc0a4e36c29ecbac6fb8ba8707ff54c3786 |
Hashes for pypdu-0.0.6-cp27-cp27mu-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a9f3e2a54b5887f9fb299907834a2ae607de316474ec5b2812043fbdcc93dddd |
|
MD5 | 3bae0416f742d335040541951a5711f5 |
|
BLAKE2b-256 | c332196aaefa7ff638297b412cf4a019dc69190e9d3cb5c320fbcb86bce9ef0a |
Hashes for pypdu-0.0.6-cp27-cp27m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3a3f3b95c2807a3d5dc08dfc147cfda61039b25b7deb2bd5731c3f7bf99b628f |
|
MD5 | b49e33ac790bf0438e1e10362148a224 |
|
BLAKE2b-256 | 823140b24eb47c231d81257632abf8a8f1c78220eebf1166c10a720482983e75 |