The Apache DataSketches Library for Python provides a collection of high-performance, stochastic streaming algorithms (sketches) for approximate queries on massive datasets. These sketches offer mathematically proven error bounds and are designed for problems like count distinct, quantiles, most-frequent items, joins, matrix computations, and graph analysis. The current version is 5.2.0, with a regular release cadence as part of the Apache DataSketches project.
pip install datasketchesVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to create and use a KLL (Kaplan-Meier-Louis) integer sketch to estimate quantiles and ranks from a stream of data. The KLL sketch is an efficient way to get approximate quantile information with strong error guarantees.
Review your code for C++-style copy constructors and `str()` calls. Adapt to Pythonic `obj.copy()` methods and argument-less `str()` for object representation. Ensure `nanobind` is installed instead of `pybind11`.
Be aware of potential discrepancies when comparing sketch results or binary serializations across different language implementations. Loading sketches serialized from other languages into Python will work as expected, but the creation process may differ.
Migrate existing code using 'Quantiles Sketch' to `kll_ints_sketch`, `kll_floats_sketch`, or `req_ints_sketch`, `req_floats_sketch` for better accuracy and performance.
Consult the `datasketches-spark` documentation for detailed Spark configuration settings, including `spark.driver.userClassPathFirst`, `spark.executor.userClassPathFirst`, and the necessary Java options for module exports.
Ensure the library is correctly installed using pip: `pip install datasketches`
Access the specific sketch type using its correct factory function, such as `datasketches.kll_doubles_sketch()` or `datasketches.kll_ints_sketch()`.
Ensure the data type being passed to the `update()` method matches the expected type of the specific sketch instance (e.g., `kll_ints_sketch` expects integers, `kll_doubles_sketch` expects doubles/floats, `kll_items_sketch` expects comparable Python objects).