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.
#!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.3.tar.gz
(34.3 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pfutil-1.0.3.tar.gz.
File metadata
- Download URL: pfutil-1.0.3.tar.gz
- Upload date:
- Size: 34.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.0 CPython/3.10.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4b8d0362dcf8a272c755380051d370c9cd19aabb527ff3db4c97aa74287e473f
|
|
| MD5 |
f0642031fdefaf245818e87774fe6323
|
|
| BLAKE2b-256 |
898f4a983bfbf1cfbece2a9a97c0e85e6bdad0a0884e9404ee0ddb80a81258a1
|
File details
Details for the file pfutil-1.0.3-cp310-cp310-macosx_10_9_universal2.whl.
File metadata
- Download URL: pfutil-1.0.3-cp310-cp310-macosx_10_9_universal2.whl
- Upload date:
- Size: 42.5 kB
- Tags: CPython 3.10, macOS 10.9+ universal2 (ARM64, x86-64)
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.0 CPython/3.10.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
40b213807354785fb00363d2baccf693d30fb526cf6edcb6a3dcf7be858a9349
|
|
| MD5 |
ff4448faabf21658ca5d6f728581c5f6
|
|
| BLAKE2b-256 |
ab76986bd155a1d67970aef8cbf47f66b8a2932c612ff06642b82d962c9be15b
|