bloomfilter-py


Namebloomfilter-py JSON
Version 1.0.0 PyPI version JSON
download
home_page
SummaryYet another bloomfilter implementation in Python
upload_time2023-09-18 04:24:48
maintainer
docs_urlNone
author
requires_python>=3.8
licenseMIT License Copyright (c) 2020 OldPanda Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords bloomfilter
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # bloomfilter-py
![](https://img.shields.io/pypi/v/bloomfilter-py.svg)
![](https://img.shields.io/pypi/pyversions/bloomfilter-py.svg)
[![codecov](https://codecov.io/gh/OldPanda/bloomfilter-py/branch/master/graph/badge.svg?token=RBX1JK7P7O)](https://codecov.io/gh/OldPanda/bloomfilter-py)
[![Downloads](https://pepy.tech/badge/bloomfilter-py)](https://pepy.tech/project/bloomfilter-py)

## 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](https://www.baeldung.com/guava-bloom-filter).

Here's a brief [introduction](https://en.wikipedia.org/wiki/Bloom_filter) to Bloomfilter.

## Requirements
* Python 3.7+

This library is not tested under Python 3.6 and lower versions.

## Install
```
pip install bloomfilter-py
```

## Usage Examples

### Basic Usage
```Python
>>> 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
```Python
>>> dumps = bloom_filter.dumps()
>>> with open("dumps.out", "wb") as f:
...     f.write(dumps)
...
>>>
```

or to a hex string
```Python
>>> hex_str = bloom_filter.dumps_to_hex()
```

or to a base64 encoded bytes
```Python
base64_bytes = bloom_filter.dumps_to_base64()
```

### Deserialize Bloomfilter
And you can easily initialize a `BloomFilter` instance from a byte array
```Python
>>> 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
```Python
>>> bf = BloomFilter.loads_from_hex(hex_str)
>>> 1 in bf
True
>>> 100 in bf
False
```

or from a base64 encoded bytes
```Python
>>> bf = BloomFilter.loads_from_base64(base64_bytes)
>>> 100 in bf
False
>>> 200 in bf
False
>>> 1 in bf
True
>>> 99 in bf
True
```

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "bloomfilter-py",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "bloomfilter",
    "author": "",
    "author_email": "OldPanda <me@old-panda.com>",
    "download_url": "https://files.pythonhosted.org/packages/c8/98/3ccddd660e21b958bf350f0f4e5295987a1e90063f74025914e0db12aa8b/bloomfilter-py-1.0.0.tar.gz",
    "platform": null,
    "description": "# bloomfilter-py\n![](https://img.shields.io/pypi/v/bloomfilter-py.svg)\n![](https://img.shields.io/pypi/pyversions/bloomfilter-py.svg)\n[![codecov](https://codecov.io/gh/OldPanda/bloomfilter-py/branch/master/graph/badge.svg?token=RBX1JK7P7O)](https://codecov.io/gh/OldPanda/bloomfilter-py)\n[![Downloads](https://pepy.tech/badge/bloomfilter-py)](https://pepy.tech/project/bloomfilter-py)\n\n## Overview\nYet another Bloomfilter implementation in Python, compatible with Java's Guava library.\n\nI 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.\n\nAs for Bloomfilter usage in Java world, please refer to [this post](https://www.baeldung.com/guava-bloom-filter).\n\nHere's a brief [introduction](https://en.wikipedia.org/wiki/Bloom_filter) to Bloomfilter.\n\n## Requirements\n* Python 3.7+\n\nThis library is not tested under Python 3.6 and lower versions.\n\n## Install\n```\npip install bloomfilter-py\n```\n\n## Usage Examples\n\n### Basic Usage\n```Python\n>>> from bloomfilter import BloomFilter\n>>> bloom_filter = BloomFilter(expected_insertions=500, err_rate=0.01)\n>>> for i in range(100):\n...     bloom_filter.put(i)\n...\n>>> 1 in bloom_filter\nTrue\n>>> 100 in bloom_filter\nFalse\n>>>\n```\n\n### Serialize Bloomfilter\nYou can easily serialize `BloomFilter` instance to a byte array\n```Python\n>>> dumps = bloom_filter.dumps()\n>>> with open(\"dumps.out\", \"wb\") as f:\n...     f.write(dumps)\n...\n>>>\n```\n\nor to a hex string\n```Python\n>>> hex_str = bloom_filter.dumps_to_hex()\n```\n\nor to a base64 encoded bytes\n```Python\nbase64_bytes = bloom_filter.dumps_to_base64()\n```\n\n### Deserialize Bloomfilter\nAnd you can easily initialize a `BloomFilter` instance from a byte array\n```Python\n>>> with open(\"dumps.out\", \"rb\") as f:\n...     bf = BloomFilter.loads(f.read())\n...\n>>> 1 in bf\nTrue\n>>> 100 in bf\nFalse\n>>>\n```\n\nor from a hex string\n```Python\n>>> bf = BloomFilter.loads_from_hex(hex_str)\n>>> 1 in bf\nTrue\n>>> 100 in bf\nFalse\n```\n\nor from a base64 encoded bytes\n```Python\n>>> bf = BloomFilter.loads_from_base64(base64_bytes)\n>>> 100 in bf\nFalse\n>>> 200 in bf\nFalse\n>>> 1 in bf\nTrue\n>>> 99 in bf\nTrue\n```\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) 2020 OldPanda  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
    "summary": "Yet another bloomfilter implementation in Python",
    "version": "1.0.0",
    "project_urls": {
        "Documentation": "https://github.com/OldPanda/bloomfilter-py/blob/master/README.md",
        "Homepage": "https://github.com/OldPanda/bloomfilter-py",
        "Repository": "https://github.com/OldPanda/bloomfilter-py.git"
    },
    "split_keywords": [
        "bloomfilter"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "783a91c3b6d22374b7de6705e7a87a3ea009752062086865174c5326b74954e3",
                "md5": "4e557316f5d36e03d21605e574300285",
                "sha256": "814db68557a63692bb0e642ff82dcb3e07341134ae9eed961f9cda0c41aec25e"
            },
            "downloads": -1,
            "filename": "bloomfilter_py-1.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "4e557316f5d36e03d21605e574300285",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 6684,
            "upload_time": "2023-09-18T04:24:46",
            "upload_time_iso_8601": "2023-09-18T04:24:46.690132Z",
            "url": "https://files.pythonhosted.org/packages/78/3a/91c3b6d22374b7de6705e7a87a3ea009752062086865174c5326b74954e3/bloomfilter_py-1.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c8983ccddd660e21b958bf350f0f4e5295987a1e90063f74025914e0db12aa8b",
                "md5": "6079d6fff41f031749aae8475c7e75ef",
                "sha256": "0be904ee15ef5fa73f26f030b1f573785cb9fd7c1979ffcf5502d78236ac2f6b"
            },
            "downloads": -1,
            "filename": "bloomfilter-py-1.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "6079d6fff41f031749aae8475c7e75ef",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 6306,
            "upload_time": "2023-09-18T04:24:48",
            "upload_time_iso_8601": "2023-09-18T04:24:48.188002Z",
            "url": "https://files.pythonhosted.org/packages/c8/98/3ccddd660e21b958bf350f0f4e5295987a1e90063f74025914e0db12aa8b/bloomfilter-py-1.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-09-18 04:24:48",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "OldPanda",
    "github_project": "bloomfilter-py",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "bloomfilter-py"
}
        
Elapsed time: 0.12160s