frequenz-resampling provides fast, typed resampling for timestamped numeric
data in Python.
The library is backed by the Rust resampler
frequenz-floss/frequenz-resampling-rs
and exposed through a small Python API. It supports incremental stream
resampling through a Resampler object as well as one-shot resampling with the
resample() convenience function.
Main capabilities:
- fixed-interval resampling with timezone-aware
datetimetimestamps - configurable interval semantics via
ClosedandLabel - multiple aggregation functions via
ResamplingFunction:AVERAGE,SUM,MAX,MIN,FIRST,LAST,COUNT,COALESCE - typed Python API (
py.typed) and generated API docs
The following platforms are officially supported (tested):
- Python: 3.11, 3.12, 3.13, 3.14
- Operating System: Ubuntu Linux 24.04, Windows, macOS
- Architectures: amd64, arm64
python -m pip install frequenz-resamplingimport datetime as dt
from frequenz.resampling import Closed, Label, Resampler, ResamplingFunction
start = dt.datetime(1970, 1, 1, tzinfo=dt.timezone.utc)
step = dt.timedelta(seconds=1)
resampler = Resampler(
dt.timedelta(seconds=5),
ResamplingFunction.AVERAGE,
max_age_in_intervals=1,
start=start,
closed=Closed.LEFT,
label=Label.RIGHT,
)
for i in range(10):
resampler.push_sample(timestamp=start + i * step, value=float(i + 1))
result = resampler.resample(start + 10 * step)
print(result)
# [(1970-01-01 00:00:05+00:00, 3.0), (1970-01-01 00:00:10+00:00, 8.0)]import datetime as dt
from frequenz.resampling import Closed, Label, ResamplingFunction, resample
start = dt.datetime(1970, 1, 1, tzinfo=dt.timezone.utc)
step = dt.timedelta(seconds=1)
data = [(start + i * step, float(i + 1)) for i in range(10)]
result = resample(
data,
dt.timedelta(seconds=5),
ResamplingFunction.SUM,
closed=Closed.LEFT,
label=Label.RIGHT,
)
print(result)- User and API documentation: https://frequenz-floss.github.io/frequenz-resampling-python/
- Changelog / releases: https://github.com/frequenz-floss/frequenz-resampling-python/releases
Contributions are welcome. For development setup, testing, docs, and release workflow, see the Contributing Guide.
This project is licensed under the MIT License.