Registry / data / madoka

madoka

JSON →
library0.7.2.1pypypi✓ verified 83d ago

Madoka is a Python library that provides a memory-efficient implementation of the CountMin Sketch probabilistic data structure, based on the Madoka C++ library. It's designed for estimating frequencies of items in a data stream with limited memory. The current version is 0.7.2.1, and releases occur infrequently, primarily for maintenance or updates to the underlying C++ library.

pip install madoka
INSTALL
IMPORT
SIG · MADOKA
M
madoka
datapythonv0.7.2.1
Install
1.6s avg
Import
Disk
20MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.7.2.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.000s · 23.8MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 1.6s · import 0.000s · 21MB
20MB installed
● package 20MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Sketch
from madoka import Sketch
from madoka import CountMinSketch
madoka
import madoka

Initializes a CountMin Sketch, adds byte-encoded items, queries their approximate frequencies, and demonstrates resetting the sketch.

import madoka # Create a CountMin Sketch with desired depth and width (or epsilon/delta) sketch = madoka.CountMinSketch(depth=4, width=2**20) # Add items (must be bytes) sketch.add(b"user_id_1") sketch.add(b"product_page_A") sketch.add(b"user_id_1") # Query approximate counts count_user1 = sketch.query(b"user_id_1") count_pageA = sketch.query(b"product_page_A") count_unknown = sketch.query(b"non_existent_item") print(f"Approximate count for 'user_id_1': {count_user1}") print(f"Approximate count for 'product_page_A': {count_pageA}") print(f"Approximate count for 'non_existent_item': {count_unknown}") # Reset the sketch sketch.reset()
Debug
Known issues
gotchaMadoka requires keys to be `bytes` objects, not strings. Passing a string will result in a `TypeError`.
fix
Ensure all keys passed to `add()` or `query()` are byte strings. For example, use `b'your_key'` or `key.encode('utf-8')`.
affects: All versions
gotchaInstallation may fail if a C++ compiler is not available on your system, especially if pre-built wheels are not provided for your specific OS and Python version.
fix
Install build tools (e.g., `build-essential` on Debian/Ubuntu, Xcode Command Line Tools on macOS, Visual C++ Build Tools on Windows) before running `pip install madoka`.
affects: All versions
gotchaThe `width` parameter (or implied by `epsilon`) directly impacts memory usage. A very large `width` can lead to significant memory consumption, potentially exceeding available RAM.
fix
Carefully choose `width` (or `epsilon`) based on your memory constraints and desired accuracy. Monitor memory usage in production environments.
affects: All versions
Upgrade
Version history
0.7.2.1latest on PyPI · released Nov 30, 2025
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
madoka — pip install madoka · libregistry