Skip to main content

bloompy

An implementation of 4 kinds of Bloom Filter in Python3.Chinese Edition

bloompy includes the standard BloomFilter,CountingBloomFilter,ScalableBloomFilter,ScalableCountingBloomFilter. It's Update from pybloom.

Installation

pip install bloompy

Usage

There's 4 kinds of BloomFilter you can use by bloompy.

  • standard bloom filter

the standard one can only query or add elements in it.

>>> import bloompy
>>> bf = bloompy.BloomFilter(error_rate=0.001,element_num=10**3)

# query the status of the element inside the bf immediately 
# and add it into the bf.False returned indicates the element
# does not inside the filter.
>>> bf.add(1) 
False
>>> bf.add(1)
True
>>> 1 in bf
True
>>> bf.exists(1)
True
>>> bf.add([1,2,3])
False
>>> bf.add([1,2,3])
True
>>> [1,2,3] in bf
True
>>> bf.exists([1,2,3])
True

# store the bf into a file.
>>> bf.tofile('filename.suffix')

# recover a bf from a file.Auto recognize which kind of filters it is.
>>> recovered_bf = bloompy.get_filter_fromfile('filename.suffix')

# or you can use a classmethod 'fromfile' of the BloomFilter Class to get
# a BloomFilter instance from a file.Same as other kind of filter Classes .
>>> recovered_bf = bloompy.BloomFilter.fromfile('filename.suffix')

# return the total number of the elements inside the bf.
>>> bf.count
2

# the capacity of the current filter.
>>> bf.capacity
1000

# the bits array of the current filter. 
>>> bf.bit_array
bitarray('00....')

# the total length of the bitarray.
>>> bf.bit_num
14400

# the hash seeds inside the filter.
# they are prime numbers by default.It's modifiable.
>>> bf.seeds
[2, 3, 5, 7, 11,...]

# the amount of hash functions 
>>> bf.hash_num
10
  • counting bloom filter

The counting bloom filter is a subclass of the standard bloom filter.But it supports the delete operation. It is set inside that 4bits represent a bit of the standard bf. So it costs more momery than the standard bf, it's 4 times the standard one.

>>> import  bloompy
>>> cbf  = bloompy.CountingBloomFilter(error_rate=0.001,element_num=10**3)

# same as the standard bf at add operation.
>>> cbf.add(12)
False
>>> cbf.add(12)
True
>>> 12 in cbf
True
>>> cbf.count
1

# query the status of the element inside the cbf immediately 
# if the element inside the cbf,delete it.
>>> cbf.delete(12)
True
>>> cbf.delete(12)
False
>>> 12 in cbf
False
>>> cbf.count
0

# recover a cbf from a file.Same as the bf.
>>> recovered_cbf = bloompy.CountingBloomFilter.fromfile('filename.suffix')

You can do any operations of the BloomFilter on it as well.

  • scalable bloom filter

Auto increase the capacity of the filter if the current amount of inserted elements is up to the limits. It's set 2times the pre capacity inside by default.

>>> import bloompy
>>> sbf = bloompy.ScalableBloomFilter(error_rate=0.001,initial_capacity=10**3)

# at first, the sbf is at 1000 capacity limits.
>>> len(sbf)
0
>>> 12 in sbf
False
>>> sbf.add(12)
False
>>> 12 in sbf 
True
>>> len(sbf)
1
>>> sbf.filters
[<bloompy.BloomFilter object at 0x000000000B6F5860>]
>>> sbf.capacity
1000

# when the amount of inserting elements surpass the limits 1000.
# the sbf appends a new filter inside it which capacity 2times 1000.
>>> for i in range(1000):
        sbf.add(i)
>>> 600 in sbf
True
>>> len(sbf)
2
>>> sbf.filters
[<bloompy.BloomFilter object at 0x000000000B6F5860>, <bloompy.BloomFilter object at 0x000000000B32F748>]
>>> sbf.capacity
3000

# recover a sbf from a file.Same as bf.
>>> recovered_sbf = bloompy.ScalableBloomFilter.fromfile('filename.suffix')

You can do any operations of the BloomFilter on it as well.

  • scalable counting bloom filter

It's a subclass of the ScalableBloomFilter.But it supports the delete operation. You can do any operations of the ScalableBloomFilter on it as well.

>>> import bloompy
>>> scbf = bloompy.SCBloomFilter(error_rate=0.001,initial_capacity=10**3)

>>> scbf.add(1)
False
>>> 1 in scbf
True
>>> scbf.delete(1)
True
>>> 1 in scbf
False
>>> len(scbf)
1
>>> scbf.filters
[<bloompy.CountingBloomFilter object at 0x000000000B6F5828>]

# add elements in sbf to make it at a capacity limits
>>> for i in range(1100):
        scbf.add(i)
>>> len(scbf)
2
>>> scbf.filters
[<bloompy.CountingBloomFilter object at 0x000000000B6F5828>, <bloompy.CountingBloomFilter object at 0x000000000B6F5898>]

# recover a scbf from a file.Same as bf.
>>> recovered_scbf = bloompy.SCBloomFilter.fromfile('filename.suffix')

Store and recover

As shown in the standard bloom filter.You can store a filter in 2 ways:

  • classmethod 'fromfile'
  • get_filter_fromfile()

if you do clearly know that there is a BloomFilter stored in a file. you can recover it with:

bloompy.BloomeFilter.fromfile('filename.suffix')

or it's a CountingBloomFilter inside it:

bloompy.CountingBloomFilter.fromfile('filename.suffix')

Same as others.

But if you don't know what kind of filter it is stored in the file.Use:

bloompy.get_filter_fromfile('filename.suffix')

It will auto recognize the filter stored inside a file.Then you can do something with it.

Metadata

Release files for bloompy 0.1.1

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

Source distribution (sdist)

Source distribution for bloompy 0.1.1
File Size Uploaded Provenance Actions
bloompy-0.1.1.tar.gz 6.8 kB Without provenance Details for bloompy-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for bloompy 0.1.1
File Interpreter ABI Platform Actions
bloompy-0.1.1-py3-none-any.whl Python 3 none any Details for bloompy-0.1.1-py3-none-any.whl

Total release size: 14.4 kB

Release files / bloompy-0.1.1.tar.gz

Download URL bloompy-0.1.1.tar.gz
Size 6.8 kB
Tags Source
SHA-256 checksum
How to use checksums
36a2941981bf5bee998834b2ad5796130c008a210426ae6e7b99e43e7a04a312
BLAKE2b-256 checksum
How to use checksums
c57a5511d84309b2799d9d61434a00093b6786453549f2ee6e0f8ec9445c7c61
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.0

Release files / bloompy-0.1.1-py3-none-any.whl

Download URL bloompy-0.1.1-py3-none-any.whl
Size 7.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d8fa5eb94a7ce40adcc2b123aa046cde852af639527facd70645ed133462b761
BLAKE2b-256 checksum
How to use checksums
1e4eb911d74d2f6e60efe846792e37fd2e8a2b893c901dd368735cf064cd3ae3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.0

Security for bloompy 0.1.1

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.1 This release

2 release files 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