{"id":1447,"library":"ddsketch","title":"DDSketch (Distributed Quantile Sketches)","description":"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.","status":"active","version":"3.0.1","language":"en","source_language":"en","source_url":"https://github.com/datadog/sketches-py","tags":["data-structures","quantiles","sketches","distributed-systems","streaming","statistics"],"install":[{"cmd":"pip install ddsketch","lang":"bash","label":"Base installation"},{"cmd":"pip install ddsketch[serialization]","lang":"bash","label":"With Protobuf serialization support"}],"dependencies":[{"reason":"Required for serializing/deserializing DDSketch objects to/from Protocol Buffers. This is an optional dependency.","package":"protobuf","optional":true}],"imports":[{"note":"The DDSketch class was moved to the top-level package namespace in v2.0.0 for easier access.","wrong":"from ddsketch.ddsketch import DDSketch","symbol":"DDSketch","correct":"from ddsketch import DDSketch"}],"quickstart":{"code":"from ddsketch import DDSketch\n\n# Initialize a DDSketch with a desired relative accuracy\ns = DDSketch(relative_accuracy=0.01) # 1% relative accuracy\n\n# Add data points\ns.add(1.0)\ns.add(2.0)\ns.add(3.0)\ns.add(10.0, count=5) # Add 10.0 five times\n\n# Get quantiles\nprint(f\"Value at 0.5 quantile: {s.get_value_at_quantile(0.5)}\")\nprint(f\"Value at 0.9 quantile: {s.get_value_at_quantile(0.9)}\")\n\n# Get min/max values\nprint(f\"Min value: {s.min_value}\")\nprint(f\"Max value: {s.max_value}\")\n\n# Merge another sketch\ns2 = DDSketch(relative_accuracy=0.01)\ns2.add(20.0)\ns.merge(s2)\nprint(f\"Value at 0.95 quantile after merge: {s.get_value_at_quantile(0.95)}\")","lang":"python","description":"This example demonstrates initializing a DDSketch, adding data points, retrieving quantiles, and merging with another sketch."},"warnings":[{"fix":"Upgrade your Python environment to 3.7 or newer. If you need older Python support, use `ddsketch<3.0.0`.","message":"Python 2.x and Python 3.6 support has been dropped. The library now requires Python >= 3.7.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"No action needed for `ddsketch` functionality, but if you require `numpy`, add `pip install numpy` to your project's dependencies.","message":"The `numpy` dependency was removed. If your project explicitly relied on `ddsketch` pulling in `numpy`, you will need to add it as a direct dependency to your project.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Access these attributes via new properties or methods (e.g., `s.min_value`, `s.max_value`) or use the newly exposed top-level `stores` and `mappings` for custom implementations. Review the v2.0.0 release notes for specific attribute replacements.","message":"Many `DDSketch` attributes such as `mapping`, `store`, `negative_store`, `zero_count`, `relative_accuracy`, `min`, and `max` were removed from direct access.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Install with `pip install ddsketch[serialization]` to ensure Protobuf functionality is available.","message":"Protobuf serialization is now an optional dependency. If you use `DDSketch.to_proto()` or `DDSketch.from_proto()`, you must install the `serialization` extra.","severity":"deprecated","affected_versions":">=3.0.0"},{"fix":"Update import statements from `from ddsketch.ddsketch import DDSketch` to `from ddsketch import DDSketch`.","message":"The import path for `DDSketch` changed from `ddsketch.ddsketch.DDSketch` to `ddsketch.DDSketch` to simplify top-level access.","severity":"gotcha","affected_versions":">=2.0.0"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}