Skip to main content

Python bindings for C implementation of xorfilter

Project description

pyxorfilter

Python bindings for C implementation of Xor Filters: Faster and Smaller Than Bloom and Cuckoo Filters and of Binary Fuse Filters: Fast and Smaller Than Xor Filters.

Installation

pip install pyxorfilter

From Source

git clone --recurse-submodules https://github.com/glitzflitz/pyxorfilter
cd pyxorfilter
python setup.py build_ext
python setup.py install

Usage

>>> from pyxorfilter import Xor8, Xor16, Fuse8, Fuse16
>>> filter = Xor8(5)	#or Xor16(size)
>>> #Supports unicode strings and heterogeneous types
>>> test_str = ["あ","अ", 51, 0.0, 12.3]
>>> filter.populate(test_str)
True
>>> filter.contains("अ")
True
>>> filter[51]  #You can use __getitem__ instead of contains
True
>>> filter["か"]
False
>>> filter.contains(150)
False
>>> filter.size_in_bytes()
60

You can serialize a filter with the serialize() method which returns a buffer, and you can recover the filter with the deserialize(buffer) method, which returns a filter:

> f = open('/tmp/output', 'wb')
> f.write(filter.serialize())
> f.close()
> recoverfilter = Xor8.deserialize(open('/tmp/output', 'rb').read())

Caveats

Accuracy

For more accuracy(less false positives) use larger but more accurate Xor16 for Fuse16.

For large sets (contain millions of keys), Fuse8/Fuse16 filters are faster and smaller than Xor8/Xor16.

>>> filter = Xor8(1000000)
>>> filter.size_in_bytes()
1230054
>>> filter = Fuse8(1000000)
>>> filter.size_in_bytes()
1130536

TODO

  • Add unit tests
  • Add CI support for distributing pyxorfilter with PyPI.

Links

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

pyxorfilter-1.1.2.tar.gz (9.6 kB view hashes)

Uploaded Source

Built Distributions

pyxorfilter-1.1.2-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (29.3 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

pyxorfilter-1.1.2-pp310-pypy310_pp73-macosx_10_9_x86_64.whl (28.1 kB view hashes)

Uploaded PyPy macOS 10.9+ x86-64

pyxorfilter-1.1.2-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (29.3 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

pyxorfilter-1.1.2-pp39-pypy39_pp73-macosx_10_9_x86_64.whl (28.1 kB view hashes)

Uploaded PyPy macOS 10.9+ x86-64

pyxorfilter-1.1.2-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (29.3 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

pyxorfilter-1.1.2-pp38-pypy38_pp73-macosx_10_9_x86_64.whl (28.1 kB view hashes)

Uploaded PyPy macOS 10.9+ x86-64

pyxorfilter-1.1.2-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (29.3 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

pyxorfilter-1.1.2-pp37-pypy37_pp73-macosx_10_9_x86_64.whl (28.1 kB view hashes)

Uploaded PyPy macOS 10.9+ x86-64

pyxorfilter-1.1.2-cp312-cp312-musllinux_1_1_x86_64.whl (163.6 kB view hashes)

Uploaded CPython 3.12 musllinux: musl 1.1+ x86-64

pyxorfilter-1.1.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (161.9 kB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

pyxorfilter-1.1.2-cp312-cp312-macosx_10_9_x86_64.whl (43.7 kB view hashes)

Uploaded CPython 3.12 macOS 10.9+ x86-64

pyxorfilter-1.1.2-cp311-cp311-musllinux_1_1_x86_64.whl (162.7 kB view hashes)

Uploaded CPython 3.11 musllinux: musl 1.1+ x86-64

pyxorfilter-1.1.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (161.0 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

pyxorfilter-1.1.2-cp311-cp311-macosx_10_9_x86_64.whl (43.6 kB view hashes)

Uploaded CPython 3.11 macOS 10.9+ x86-64

pyxorfilter-1.1.2-cp310-cp310-musllinux_1_1_x86_64.whl (162.7 kB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.1+ x86-64

pyxorfilter-1.1.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (161.0 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

pyxorfilter-1.1.2-cp310-cp310-macosx_10_9_x86_64.whl (43.6 kB view hashes)

Uploaded CPython 3.10 macOS 10.9+ x86-64

pyxorfilter-1.1.2-cp39-cp39-musllinux_1_1_x86_64.whl (162.7 kB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.1+ x86-64

pyxorfilter-1.1.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (161.0 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

pyxorfilter-1.1.2-cp39-cp39-macosx_10_9_x86_64.whl (43.6 kB view hashes)

Uploaded CPython 3.9 macOS 10.9+ x86-64

pyxorfilter-1.1.2-cp38-cp38-musllinux_1_1_x86_64.whl (163.1 kB view hashes)

Uploaded CPython 3.8 musllinux: musl 1.1+ x86-64

pyxorfilter-1.1.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (161.2 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

pyxorfilter-1.1.2-cp38-cp38-macosx_10_9_x86_64.whl (43.6 kB view hashes)

Uploaded CPython 3.8 macOS 10.9+ x86-64

pyxorfilter-1.1.2-cp37-cp37m-musllinux_1_1_x86_64.whl (162.2 kB view hashes)

Uploaded CPython 3.7m musllinux: musl 1.1+ x86-64

pyxorfilter-1.1.2-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (160.4 kB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ x86-64

pyxorfilter-1.1.2-cp37-cp37m-macosx_10_9_x86_64.whl (43.5 kB view hashes)

Uploaded CPython 3.7m macOS 10.9+ x86-64

pyxorfilter-1.1.2-cp36-cp36m-musllinux_1_1_x86_64.whl (162.2 kB view hashes)

Uploaded CPython 3.6m musllinux: musl 1.1+ x86-64

pyxorfilter-1.1.2-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (160.4 kB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.17+ x86-64

pyxorfilter-1.1.2-cp36-cp36m-macosx_10_9_x86_64.whl (43.5 kB view hashes)

Uploaded CPython 3.6m macOS 10.9+ x86-64

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