pfutil
======
Fast [HyperLogLog](https://en.wikipedia.org/wiki/HyperLogLog) extension for Python 3. The underlying binary representation is compatible with [Redis](https://redis.io).
This package supports both Python 2.7 and Python 3.3+ (tested with Python 3.13).
```python
#!python3
import redis
from pfutil import HyperLogLog
r = redis.Redis()
r.pfadd('foo', 'a', 'b', 'c')
r.pfadd('bar', 'x', 'y', 'z')
r.pfmerge('bar', 'foo')
assert r.pfcount('foo') == 3
assert r.pfcount('bar') == 6
foo = HyperLogLog.from_bytes(r.get('foo'))
bar = HyperLogLog.from_elements('x', 'y')
bar.pfadd('z')
bar.pfmerge(foo)
assert foo.pfcount() == 3
assert bar.pfcount() == 6
assert r.get('bar') == bar.to_bytes()
```
Install
-------
Install from [PyPI](https://pypi.org/project/pfutil/):
```
pip install pfutil
```
Install from source:
```
pip install setuptools
python setup.py install
```
Usage
-----
* `HyperLogLog()` creates an empty HyperLogLog object
* `HyperLogLog.from_bytes(b'...')` creates a HyperLogLog object from Redis-compatible bytes representation
* `HyperLogLog.from_elements('a', 'b')` create a HyperLogLog object from one or more strings
* `h.pfadd('x')` adds one or more strings into this HyperLogLog object
* `h.pfmerge(other)` merges another HyperLogLog object `other` into this `h`
* `h.pfcount()` returns the cardinality of this HyperLogLog object
* `h.to_bytes()` serializes the HyperLogLog object into Redis-compatible bytes representation
Refer to `test.py` for some examples.
License
-------
* This `pfutil` software is released under the [3-Clause BSD License](https://opensource.org/license/bsd-3-clause)
* The files in `src/redis/` are extracted and modified from [Redis 6.2.12](https://github.com/redis/redis/tree/6.2.12), which is released under the 3-Clause BSD License as well.
Raw data
{
"_id": null,
"home_page": "https://github.com/danchen6/pfutil",
"name": "pfutil",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": null,
"author": "Dan Chen",
"author_email": "danchen666666@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/6e/0c/f0262f2361627021914da42f06f0491ca8c6dcf061d46c0e1b7ad2757042/pfutil-1.0.4.tar.gz",
"platform": null,
"description": "pfutil\n======\n\nFast [HyperLogLog](https://en.wikipedia.org/wiki/HyperLogLog) extension for Python 3. The underlying binary representation is compatible with [Redis](https://redis.io).\n\nThis package supports both Python 2.7 and Python 3.3+ (tested with Python 3.13).\n\n```python\n#!python3\nimport redis\nfrom pfutil import HyperLogLog\n\nr = redis.Redis()\nr.pfadd('foo', 'a', 'b', 'c')\nr.pfadd('bar', 'x', 'y', 'z')\nr.pfmerge('bar', 'foo')\nassert r.pfcount('foo') == 3\nassert r.pfcount('bar') == 6\n\nfoo = HyperLogLog.from_bytes(r.get('foo'))\nbar = HyperLogLog.from_elements('x', 'y')\nbar.pfadd('z')\nbar.pfmerge(foo)\nassert foo.pfcount() == 3\nassert bar.pfcount() == 6\nassert r.get('bar') == bar.to_bytes()\n```\n\n\nInstall\n-------\n\nInstall from [PyPI](https://pypi.org/project/pfutil/):\n```\npip install pfutil\n```\n\nInstall from source:\n```\npip install setuptools\npython setup.py install\n```\n\n\nUsage\n-----\n\n* `HyperLogLog()` creates an empty HyperLogLog object\n* `HyperLogLog.from_bytes(b'...')` creates a HyperLogLog object from Redis-compatible bytes representation\n* `HyperLogLog.from_elements('a', 'b')` create a HyperLogLog object from one or more strings\n* `h.pfadd('x')` adds one or more strings into this HyperLogLog object\n* `h.pfmerge(other)` merges another HyperLogLog object `other` into this `h`\n* `h.pfcount()` returns the cardinality of this HyperLogLog object\n* `h.to_bytes()` serializes the HyperLogLog object into Redis-compatible bytes representation\n\nRefer to `test.py` for some examples.\n\n\nLicense\n-------\n\n* This `pfutil` software is released under the [3-Clause BSD License](https://opensource.org/license/bsd-3-clause)\n* The files in `src/redis/` are extracted and modified from [Redis 6.2.12](https://github.com/redis/redis/tree/6.2.12), which is released under the 3-Clause BSD License as well.\n",
"bugtrack_url": null,
"license": "3-Clause BSD License",
"summary": "Fast and Redis-compatible HyperLogLog extension for Python 3",
"version": "1.0.4",
"project_urls": {
"Homepage": "https://github.com/danchen6/pfutil"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "6e0cf0262f2361627021914da42f06f0491ca8c6dcf061d46c0e1b7ad2757042",
"md5": "ff0e584d4d5a42c738596206ee825a32",
"sha256": "a08176dad56f632e879848180f3caa060dd4bdeb0062cf58411c52c5cf1b480a"
},
"downloads": -1,
"filename": "pfutil-1.0.4.tar.gz",
"has_sig": false,
"md5_digest": "ff0e584d4d5a42c738596206ee825a32",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 35487,
"upload_time": "2024-12-08T05:01:18",
"upload_time_iso_8601": "2024-12-08T05:01:18.436107Z",
"url": "https://files.pythonhosted.org/packages/6e/0c/f0262f2361627021914da42f06f0491ca8c6dcf061d46c0e1b7ad2757042/pfutil-1.0.4.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-12-08 05:01:18",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "danchen6",
"github_project": "pfutil",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "pfutil"
}