fastdigest: Fast online statistics using t-digest · Pythie
Merging : Merge many t-digests into one, enabling parallel compute operations such as map-reduce.
Serialization : Transform t-digests to/from dict or binary format, or simply use the pickle module.
Easy API : The fastDigest API is designed to be intuitive and to keep high overlap with popular libraries.
Blazing fast : Rust-powered performance, up to hundreds of times faster than other Python implementations.
Installation
Installing from PyPI Compiled wheels are available on PyPI. Simply install via pip:
Installing from source Install Python 3.10+ and Rust , then download or clone this repository and open a terminal in its root directory.
Directly build and install fastDigest in your active Python environment in a single step:
pip install .
Or use uv to build a release wheel with the project's locked dependencies:
uv run --locked maturin build --release
Usage The following examples are intended to give you a quick start. See the API reference for the full documentation.
Initialization Simply call TDigest() to create a new instance, or use TDigest.from_values to directly create a digest of any sequence of numbers:
from fastdigest import TDigest
digest = TDigest()
digest = TDigest.from_values([2.71, 3.14, 1.42])
Mathematical functions Estimate the value at the rank q using quantile(q):
digest = TDigest.from_values(range(1001))
print("99th percentile:", digest.quantile(0.99))
Or the inverse — use cdf to find the rank (cumulative probability) of a given value:
print("cdf(990) =", digest.cdf(990))
Compute the arithmetic mean, or the trimmed_mean between two quantiles:
data = list(range(11)) # numbers 1-10
data[-1] = 100_000 # extreme outlier
digest = TDigest.from_values(data)
print(f" Mean: {digest.mean()}")
print(f"Trimmed mean: {digest.trimmed_mean(0.1, 0.9)}")
Updating a TDigest Use batch_update to merge a sequence of many values at once, or update to add one value at a time.
Note: These methods are optimized for different use-cases and have different performance characteristics. See API.md for details.
digest = TDigest()
digest.batch_update([0, 1, 2])
digest.update(3)
Optionally specify weights in the second argument w:
digest.update(4, 0.4) # single weighted value
digest.batch_update([5, 6, 7], w=1.5) # whole-batch weight
digest.batch_update([8, 9], [1.0, 2.0]) # per-value weights
Merging TDigest objects Use the + operator to create a new instance from two TDigests, or += to merge in-place:
digest1 = TDigest.from_values(range(20))
digest2 = TDigest.from_values(range(20, 51))
digest3 = TDigest.from_values(range(51, 101))
digest1 += digest2
merged_new = digest1 + digest3
The merge_all function offers an easy way to merge an iterable of many TDigests:
from fastdigest import TDigest, merge_all
digests = [TDigest.from_values(range(i, i+10)) for i in range(0, 100, 10)]
merged = merge_all(digests)
Dict conversion Obtain a dictionary representation by calling to_dict() and load it into a new instance with TDigest.from_dict:
from fastdigest import TDigest
import json
digest = TDigest.from_values(range(101))
td_dict = digest.to_dict()
print(json.dumps(td_dict, indent=2))
restored = TDigest.from_dict(td_dict)
Migration The fastDigest API is designed to be backward compatible with the tdigest Python library. Migrating is as simple as changing your import statement.
Dicts created by tdigest can also natively be used by fastDigest .
Benchmarks
Task: Construct a digest of 1,000,000 uniformly distributed random values and estimate their median (average of 10 consecutive runs).
Test environment: Python 3.12.12, MacBook Pro (M4 Pro), macOS 15.7.2 Sequoia
Library Time (ms) Relative speed tdigest 9,773 1x pytdigest 66 148x fastdigest 20 480x
If you want to try it yourself, install fastDigest (and optionally tdigest and/or pytdigest ) and run:
License fastDigest is licensed under the MIT License. See the LICENSE file for details.
Acknowledgements Credit goes to Ted Dunning for inventing the t-digest . Special thanks to Andy Lok and Paul Meng for creating the tdigests and tdigest Rust libraries, respectively, as well as to all PyO3 contributors .
Popularity
Downloads, last 7 days 42.9K-36%
Stars, last 7 days –
Direct dependents 5
All dependents 5 62
Fair
Maintenance, out of 100
Recent release
last release 13 days ago
Commit activity
2/26 weeks with commits
Release cadence
9 releases in 12 months
Issues & PRs handled
87% closed in the past year
Contributor spread
1 authors in last 100 commits
OpenSSF Scorecard
not evaluated
Releases
Latest 0.14.0
Released Nov 15, 2026
Releases, 12 months 9
First release Feb 16, 2025 Compatibility
Requires Python >=3.10
Tested on 3.10 · 3.11 · 3.12 · 3.13 · 3.14 · 3.15
License MIT (Permissive) AlternativesUse instead of fastdigest: tools that do the same job, closest first.
Compare with pytdigest → Compare with tdigest → Compare with crick → Compare all 4 →
Python package for *fast* TDigest calculation.
tdigest 0.5.2.2 Inactive Pythie’s Index: 18T-Digest data structure
crick 0.0.8 Maintained Pythie’s Index: 28High performance approximate and streaming algorithms
ddsketch 3.0.1 Maintained Pythie’s Index: 24Distributed quantile sketches
Python Implementation of Graham Cormode and S. Muthukrishnan's Effective Computation of Biased Quantiles over Data Streams in ICDE'05