Skip to main content

Yet another bloomfilter implementation in Python

Project description

bloomfilter-py

codecov Downloads

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.8+

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bloomfilter_py-1.1.0.tar.gz (6.3 kB view details)

Uploaded Source

Built Distribution

bloomfilter_py-1.1.0-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file bloomfilter_py-1.1.0.tar.gz.

File metadata

  • Download URL: bloomfilter_py-1.1.0.tar.gz
  • Upload date:
  • Size: 6.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.5

File hashes

Hashes for bloomfilter_py-1.1.0.tar.gz
Algorithm Hash digest
SHA256 c9f65f87029adb4a9f85581ecec8ff07c88156b1e5af4ae989cc6089de1cbe95
MD5 76c05a0e7aa3d58472d915a96bff70fa
BLAKE2b-256 356a18c8aa055268ca435e4180cde13b159d4afdaf2d0a895442c2e32763f0d9

See more details on using hashes here.

File details

Details for the file bloomfilter_py-1.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for bloomfilter_py-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4a15c4dbc83f2ddeb462a3885aa03554ebfa568ac90f59ae728a8b71dd99cbda
MD5 8c9726465cbf26b066c7ca57e5561388
BLAKE2b-256 47f0a3253f5ec70994b77ece45483ae55402bed8cf870a7114ee6f39d8bd5983

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page