Skip to main content

cbloom

A fast Bloom filter for Python, backed by a C extension.

Answers one question efficiently: "Have I seen this before?"

  • No false negatives — if it says False, the item is definitely absent
  • Tunable false positives — configure your own error rate (e.g. 0.01 = 1%)
  • Low memory — 1 million items at 1% error rate uses ~1.1 MB of bits

Installation

pip install cbloom

Usage

from cbloom import BloomFilter

# 1 million expected items, 1% false positive rate
bf = BloomFilter(capacity=1_000_000, error_rate=0.01)

bf.add("hello")
bf.add("world")

bf.contains("hello")   # True
bf.contains("world")   # True
bf.contains("python")  # False (definitely not added)

API

BloomFilter(capacity, error_rate)

  • capacity — maximum number of items you expect to insert
  • error_rate — acceptable false positive rate, e.g. 0.01 for 1%
Method Returns Description
.add(key) None Add a string to the filter
.contains(key) bool True if probably present, False if definitely absent
.item_count() int Number of items inserted
.bit_count() int Size of the internal bit array (m)
.hash_count() int Number of hash functions in use (k)

How it works

Internally the filter allocates a bit array of size m (computed from your capacity and error_rate). When you call .add(key), two hash functions (FNV-1a and DJB2) produce k positions in the array and set those bits to 1. .contains(key) checks all k positions -- if any bit is 0 the item was definitely never added.

The tradeoff: once enough bits are set, unrelated keys can accidentally match all k positions, producing a false positive. The math guarantees this stays below your configured error_rate as long as you stay within capacity.

Use cases

  • Deduplicating URLs in a web crawler
  • Skipping expensive database lookups
  • Checking passwords against breach lists
  • Filtering seen events in a streaming pipeline

License

MIT

Metadata

Release files for cbloom 0.1.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 cbloom 0.1.0
File Size Uploaded Provenance Actions
cbloom-0.1.0.tar.gz 7.9 kB Without provenance Details for cbloom-0.1.0.tar.gz

Release files / cbloom-0.1.0.tar.gz

Download URL cbloom-0.1.0.tar.gz
Size 7.9 kB
Tags Source
SHA-256 checksum
How to use checksums
5aff5842221365884078b629788e776a494d94fee8af46c0b6d8bdef1ff07e02
BLAKE2b-256 checksum
How to use checksums
e9fc8750a2ce2ea46e8bce3bd0ca1f597030be72dac9e9453ebf5d914b52cc37
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.16 {"installer":{"name":"uv","version":"0.11.16","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Arch Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for cbloom 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

1 release file No provenance

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