Skip to main content

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

Development and Testing

From the repository root, create an isolated virtual environment and install the project in editable mode with pytest:

python -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade pip
python -m pip install -e . pytest

Run the complete test suite:

python -m pytest -v

To run the same formatting, type, and security checks used during development, install the additional tools and execute:

python -m pip install black mypy bandit
python -m black --check bloomfilter tests
python -m mypy bloomfilter --strict
python -m bandit -r bloomfilter

On Windows PowerShell, activate the virtual environment with .venv\Scripts\Activate.ps1 instead of source .venv/bin/activate.

Metadata

Release files for bloomfilter-py 1.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for bloomfilter-py 1.2.0
File Size Uploaded
bloomfilter_py-1.2.0.tar.gz 9.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for bloomfilter-py 1.2.0
File Interpreter ABI Platform
bloomfilter_py-1.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 17.1 kB

Release files / bloomfilter_py-1.2.0.tar.gz

Download URL bloomfilter_py-1.2.0.tar.gz
Size 9.3 kB
Tags Source
SHA-256 checksum
How to use checksums
1d5e741ce30df25d0b1c2af36d8f0f108b0375169744748fd16071aff5a334fa
BLAKE2b-256 checksum
How to use checksums
e23da59d343e9f10b62142bf489c854bb7166c4c848cc11ccbf79530232db68f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / bloomfilter_py-1.2.0-py3-none-any.whl

Download URL bloomfilter_py-1.2.0-py3-none-any.whl
Size 7.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b17f4b9c8278618e4c36f26a97a407a68ff0366f2a8b975ecf6afa4ca5996dcd
BLAKE2b-256 checksum
How to use checksums
e955d83df9c7488115790d1aa62c56198714f142f3546cd8c43805a8fb499a51
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release history Release notifications | RSS feed

1.3.0

2 release files

This release

1.2.0 This release

2 release files

1.1.0

2 release files

1.0.0

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.0

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page