Fast and Redis-compatible HyperLogLog extension for Python 3
Project description
pfutil
Fast HyperLogLog extension for Python 3. The underlying binary representation is compatible with Redis.
This package supports both Python 2.7 and Python 3.3+ (tested with Python 3.13).
#!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:
pip install pfutil
Install from source:
pip install setuptools
python setup.py install
Usage
HyperLogLog()creates an empty HyperLogLog objectHyperLogLog.from_bytes(b'...')creates a HyperLogLog object from Redis-compatible bytes representationHyperLogLog.from_elements('a', 'b')create a HyperLogLog object from one or more stringsh.pfadd('x')adds one or more strings into this HyperLogLog objecth.pfmerge(other)merges another HyperLogLog objectotherinto thishh.pfcount()returns the cardinality of this HyperLogLog objecth.to_bytes()serializes the HyperLogLog object into Redis-compatible bytes representation
Refer to test.py for some examples.
License
- This
pfutilsoftware is released under the 3-Clause BSD License - The files in
src/redis/are extracted and modified from Redis 6.2.12, which is released under the 3-Clause BSD License as well.
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
pfutil-1.0.4.tar.gz
(35.5 kB
view details)
File details
Details for the file pfutil-1.0.4.tar.gz.
File metadata
- Download URL: pfutil-1.0.4.tar.gz
- Upload date:
- Size: 35.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.0 CPython/3.10.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a08176dad56f632e879848180f3caa060dd4bdeb0062cf58411c52c5cf1b480a
|
|
| MD5 |
ff0e584d4d5a42c738596206ee825a32
|
|
| BLAKE2b-256 |
6e0cf0262f2361627021914da42f06f0491ca8c6dcf061d46c0e1b7ad2757042
|