Skip to main content

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 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
  • 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.2.tar.gz (34.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pfutil-1.0.2-cp310-cp310-macosx_10_9_universal2.whl (42.1 kB view details)

Uploaded CPython 3.10macOS 10.9+ universal2 (ARM64, x86-64)

File details

Details for the file pfutil-1.0.2.tar.gz.

File metadata

  • Download URL: pfutil-1.0.2.tar.gz
  • Upload date:
  • Size: 34.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.0 CPython/3.10.0

File hashes

Hashes for pfutil-1.0.2.tar.gz
Algorithm Hash digest
SHA256 110169ff96f0427ae3261261ad3a22d230ad47ce85ed4ef9a5d652b7c65a52da
MD5 fbf604e4ca966bfb86965bed2803c562
BLAKE2b-256 4b318864d7b66fdc952bb05d73fb4b1a529387797f776d964e5c89f74f7d4966

See more details on using hashes here.

File details

Details for the file pfutil-1.0.2-cp310-cp310-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for pfutil-1.0.2-cp310-cp310-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 0c0ef9f73be72325f04460a629a649cda67647afb78fa36fc50001171f776895
MD5 d6b2496740c311187a5dd1dc2b14f587
BLAKE2b-256 8e20c9efb4e8c1a9f0f85b9e0cd5b3e71581d58f1327ce09d916553f698d45af

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page