Yet another bloomfilter implementation in Python
Project description
bloomfilter-py
Overview
Yet another Bloomfilter implementation in Python, compatible with Java's Guava library.
I was looking for a Python library which is capable of reading what Bloomfilter of Java's Guava library serializes and is also able to output byte array which is recognizable by Java. But unfortunately failed. Hence I developed this library by borrowing how Guava implements Bloomfilter serialization/deserialization a lot to deal with Bloomfilters on both Python and Java sides.
As for Bloomfilter usage in Java world, please refer to this post.
Here's a brief introduction to Bloomfilter.
Requirements
- Python 3.7+
This library is not tested under Python 3.6 and lower versions.
Install
pip install bloomfilter-py
Usage Examples
Basic Usage
>>> from bloomfilter import BloomFilter
>>> bloom_filter = BloomFilter(expected_insertions=500, err_rate=0.01)
>>> for i in range(100):
... bloom_filter.put(i)
...
>>> 1 in bloom_filter
True
>>> 100 in bloom_filter
False
>>>
Serialize Bloomfilter
You can easily serialize BloomFilter
instance to a byte array
>>> dumps = bloom_filter.dumps()
>>> with open("dumps.out", "wb") as f:
... f.write(dumps)
...
>>>
or to a hex string
>>> hex_str = bloom_filter.dumps_to_hex()
or to a base64 encoded bytes
base64_bytes = bloom_filter.dumps_to_base64()
Deserialize Bloomfilter
And you can easily initialize a BloomFilter
instance from a byte array
>>> with open("dumps.out", "rb") as f:
... bf = BloomFilter.loads(f.read())
...
>>> 1 in bf
True
>>> 100 in bf
False
>>>
or from a hex string
>>> bf = BloomFilter.loads_from_hex(hex_str)
>>> 1 in bf
True
>>> 100 in bf
False
or from a base64 encoded bytes
>>> bf = BloomFilter.loads_from_base64(base64_bytes)
>>> 100 in bf
False
>>> 200 in bf
False
>>> 1 in bf
True
>>> 99 in bf
True
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file bloomfilter-py-0.2.0.tar.gz
.
File metadata
- Download URL: bloomfilter-py-0.2.0.tar.gz
- Upload date:
- Size: 5.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8ae15471cb76f1eb7d14d1d00be24ae14494f04368903cda09b8438efa4433af |
|
MD5 | 9c142983bbaa2590780ae07a32136672 |
|
BLAKE2b-256 | ce7089b21de4c4389c6b13f7729b4d9ead013d557a83205328c0efde1c20141a |
File details
Details for the file bloomfilter_py-0.2.0-py3-none-any.whl
.
File metadata
- Download URL: bloomfilter_py-0.2.0-py3-none-any.whl
- Upload date:
- Size: 5.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e9f040b9ed00d6608006329f0f34f24e2040dca13c16c9d6abf99a1b2701a996 |
|
MD5 | b47f8ad0c364adaeb0eae7d0ff5bd6a1 |
|
BLAKE2b-256 | acf8cf89a2d3a0378d1de01bf3b2f68f072f4126df88583db050e3ab73573f53 |