Skip to main content

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 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.

Metadata

Release files for pfutil 1.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pfutil 1.0.4
File Size Uploaded
pfutil-1.0.4.tar.gz 35.5 kB Details

Release files / pfutil-1.0.4.tar.gz

Download URL pfutil-1.0.4.tar.gz
Size 35.5 kB
Tags Source
SHA-256 checksum
How to use checksums
a08176dad56f632e879848180f3caa060dd4bdeb0062cf58411c52c5cf1b480a
BLAKE2b-256 checksum
How to use checksums
6e0cf0262f2361627021914da42f06f0491ca8c6dcf061d46c0e1b7ad2757042
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.0 CPython/3.10.0

Release history Release notifications | RSS feed

This release

1.0.4 This release

1 release file

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page