bloom-filter2 is a pure Python Bloom filter module, providing a space-efficient and probabilistic set data structure. It supports mmap, in-memory, and disk-seek backends, offering a balance between memory usage and performance. The library automatically calculates optimal Bloom filter parameters based on user-specified maximum elements and desired false positive rate. It is compatible with CPython 3.x, Pypy, and Jython and is actively maintained.
pip install bloom-filter2Verified import paths — ran on the pinned version, not inferred.
Initialize a BloomFilter, add elements, and check for membership using the `in` operator. The `max_elements` and `error_rate` parameters control the filter's capacity and false positive probability.
Always account for the possibility of false positives in your application logic, especially when querying items that are not expected to be present.
Accurately estimate `max_elements` for your use case and consider re-initializing or creating a new Bloom filter if the number of elements grows beyond expectations. Monitor the actual false positive rate if critical.
Uninstall `bloom-filter` and `pip install bloom-filter2`. Update all import statements to `from bloom_filter2 import BloomFilter`.
Carefully consider the expected maximum number of elements and the tolerable false positive rate for your application to choose optimal parameters. The library handles the internal bit array size and hash function count based on these inputs.
First, ensure `bloom-filter2` is installed: `pip install bloom-filter2`. Then, update your import statements from `from bloom_filter import BloomFilter` to `from bloom_filter2 import BloomFilter`.
Install the package using pip: `pip install bloom-filter2`. If using a virtual environment, ensure it is activated before installation.
Bloom filters inherently do not support individual element removal. If an element needs to be 'removed', it typically implies a need for a different data structure, a counting Bloom filter (not a feature of `bloom-filter2`), or re-initializing the Bloom filter with the remaining desired elements. To empty the entire filter, use `bloom_filter_instance.clear()`.
Carefully estimate the maximum number of elements (`max_elements`) your Bloom filter is expected to hold and select a tolerable `error_rate` when instantiating `BloomFilter`. If the number of elements grows beyond expectations, consider re-initializing with larger parameters or using multiple Bloom filters.
No dependency data recorded yet.