Skip to main content

A Python implementation of the Recordinality sketch

Project description

A Python implementation of the Recordinality sketch for cardinality estimation and stream sampling. Inspired by C. Scott Andreas’s implementation, but powered by SipHash-2-4 rather than MurmurHash3. In particular, this project uses two other libraries of mine: csiphash and cskipdict.

Installation

pip install recordinality

Usage

You can use the command-line application, which will read lines of text incrementally from stdin, printing the stream’s cardinality (or a random sample) once the pipe is closed:

$ recordinality -k <sketch-size> [-h|--hash-key <hash-key>] [-s|--sample] < input-lines.txt
3574
$ cat input-lines.txt | sort -u | wc -l
3556

SipHash allows the specification of a ‘secret key’ (used here as more of a hash seed); if provided it should be either a 16-char ASCII string or 32-char hexadecimal string.

You can also import the Recordinality class in Python:

>>> from recordinality import Recordinality
>>> sketch = Recordinality(size=512)
>>> for observation in input_observations:
...     sketch.add(observation)
>>> print(sketch.cardinality())
3574
>>> print(sketch.k_sample)
['strife', 'bragging', 'knight?', ...]

Unlicense

This is free and unencumbered software released into the public domain.

Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a compiled binary, for any purpose, commercial or non-commercial, and by any means.

In jurisdictions that recognize copyright laws, the author or authors of this software dedicate any and all copyright interest in the software to the public domain. We make this dedication for the benefit of the public at large and to the detriment of our heirs and successors. We intend this dedication to be an overt act of relinquishment in perpetuity of all present and future rights to this software under copyright law.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

For more information, please refer to http://unlicense.org/

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

recordinality-0.0.3.tar.gz (41.5 kB view details)

Uploaded Source

Built Distribution

recordinality-0.0.3-py2.py3-none-any.whl (6.6 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file recordinality-0.0.3.tar.gz.

File metadata

File hashes

Hashes for recordinality-0.0.3.tar.gz
Algorithm Hash digest
SHA256 0b5b13b38da0d66592a31d244be986383d2e62807067c695458117d5925bde8d
MD5 277b4af3ad63e67b4c664772dc5c9b5f
BLAKE2b-256 12d23f2c7d5fd391137e7c25144454a56f7ab43bf5acbb1ebbfe243b5cb37001

See more details on using hashes here.

File details

Details for the file recordinality-0.0.3-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for recordinality-0.0.3-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 37875ff628f694a29e4380b79edecbbb53a9936b297c2ec6742aafa24c09d9e4
MD5 8b3faae9ed22523ca42685fd2ca107b4
BLAKE2b-256 3e785ab441918c92d6454bdf82446de5dec42ebc7f1f421d2836ebc3c135fd11

See more details on using hashes here.

Supported by

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