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":pyp.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.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 81347f6cbe90f27be022ef1de1144cb4c9be3f44123cd79120bb57496fb95f9c |
|
MD5 | 0d1bfe4fee300148f764a51f4dc873c8 |
|
BLAKE2b-256 | 390494e9e4062a434b8a4e03f83db3d0ac92c267292f0003f51cf6d1e387947a |
Hashes for pypdu-0.0.2-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5894f7a0c1dfba29181fde2f353a4de7483ee1d48898aa28c23451665c281c7f |
|
MD5 | 4b6857d4d09e3ebc33ce8825762e8264 |
|
BLAKE2b-256 | 1a9f165319c2fd6f56b38ef1e736c5c51cac52730b58d1b19ceec039c4b0bba5 |
Hashes for pypdu-0.0.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9423799e389a8b94ef006c67050e427e54dd3053b3fb32943bddc7f573676b1c |
|
MD5 | e23985aa4a90db9a0bc8326d72bd5664 |
|
BLAKE2b-256 | 0fb4c2816fa03f06ef2b1c13687676ea7b0abeb2ff89e98221b7f12740407a0f |
Hashes for pypdu-0.0.2-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d9eb78d0fb0e9b5129a69bf81c766ac9a36089d9410b223228153f7fd8074654 |
|
MD5 | 1cc78d3945e2071d522ae0c0d1c33f98 |
|
BLAKE2b-256 | 7db5325e1502ea8ef7b11c1753f86ce1722470db497127f948f787848e597aa3 |
Hashes for pypdu-0.0.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fbe66006cd1f2fd412a7219bfa4f0b3ddb10ed1ba649bcfb0d34e078b6d24338 |
|
MD5 | a1ee6956c626f9b952724dafe3bd21bb |
|
BLAKE2b-256 | 002ec799391742007ee0cd3e2a9ff41388890dbdf4418a94d74264c1bb00b85f |
Hashes for pypdu-0.0.2-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d860c6249ac28af985f8a959a1ba9634cf2153e96978958be5f2efb86b74ea2c |
|
MD5 | f17f3e32b9d0ad4dcfaf20d44e527dfe |
|
BLAKE2b-256 | 558254a118f933b192a04f84a57b2f1760a4ca21bb2559ea91348e47d3e5a578 |
Hashes for pypdu-0.0.2-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d1f5bb9bad4ad554dcdf67379f2a87b1eb18b139ebba0250476632f20ac26efe |
|
MD5 | 8afef583629f575675f9ae8e759016b3 |
|
BLAKE2b-256 | 9551d86759020edfad51f399d3169865a5140215fc70d8196362ba2ad4c04858 |
Hashes for pypdu-0.0.2-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6fe8180d0cc8c884b1f2a77e5c960d79df31a4cc6488d8590233624e93d2940f |
|
MD5 | 108412aa901e2ad95a66b12b07449baf |
|
BLAKE2b-256 | 2decccbfaa7d8166d944fc29fe680939f71e9c55937738a32aae5e11b35cd1de |
Hashes for pypdu-0.0.2-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3e2070eda9d15a1a7a4090126b079d3b1afb578d94a8ac82f44b4024d72734a7 |
|
MD5 | 0c02fb7a2e362bb85bc7788bb2583f64 |
|
BLAKE2b-256 | 100c1bbf333b27e75910023373ab7004bd7edd020d46db45d4ad8161731d87fe |
Hashes for pypdu-0.0.2-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7e56427af824cda6ee4731781cd1a4ff3988c68c7cd8fd387d0796e3136d7eb8 |
|
MD5 | c55eefdbffed346e9d3bf565878f42e7 |
|
BLAKE2b-256 | e53d1b8bd1007853bc190ff1ba408ac57f36f068fa51615d6449df4e26d0e704 |
Hashes for pypdu-0.0.2-cp27-cp27mu-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4c76787e7a137103fa91ce1c3984ae6cb8e2cae115de3628a9263c7ad1bbb6f0 |
|
MD5 | acb8f41da3a37e2cc86437c6286f1f24 |
|
BLAKE2b-256 | 9bc908473234dddf20a99e386c5fe4658397381e35acc459aa1dd4feec4aa4c2 |
Hashes for pypdu-0.0.2-cp27-cp27m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3477670928c832de639e19ee20b10f6ed2be81da25546b6fd97b8dc0dee7c0da |
|
MD5 | 9c7ce2330abb7b1e698dee69879118c4 |
|
BLAKE2b-256 | bf3a786aa30ff2ce77716fa0e94c6f3e73589fe02f6a02c711613bcb28b94dcc |