DDSketch (Distributed Quantile Sketches)

3.0.1 · active · verified Thu Apr 09

DDSketch is a Python library for distributed quantile sketches, an algorithm for estimating quantiles with guaranteed relative accuracy. It allows for merging sketches from different sources while maintaining accuracy. The current version is 3.0.1. Releases are made as needed for bug fixes, Python version compatibility, or feature enhancements.

Warnings

Install

Imports

Quickstart

This example demonstrates initializing a DDSketch, adding data points, retrieving quantiles, and merging with another sketch.

from ddsketch import DDSketch

# Initialize a DDSketch with a desired relative accuracy
s = DDSketch(relative_accuracy=0.01) # 1% relative accuracy

# Add data points
s.add(1.0)
s.add(2.0)
s.add(3.0)
s.add(10.0, count=5) # Add 10.0 five times

# Get quantiles
print(f"Value at 0.5 quantile: {s.get_value_at_quantile(0.5)}")
print(f"Value at 0.9 quantile: {s.get_value_at_quantile(0.9)}")

# Get min/max values
print(f"Min value: {s.min_value}")
print(f"Max value: {s.max_value}")

# Merge another sketch
s2 = DDSketch(relative_accuracy=0.01)
s2.add(20.0)
s.merge(s2)
print(f"Value at 0.95 quantile after merge: {s.get_value_at_quantile(0.95)}")

view raw JSON →