ppxxh is a Pure Python implementation of the XXHASH family of hash algorithms.
This pure python implementation of Yann Collet’s XXHASH family of non-cryptographic hash algorithms with no dependencies outside of the python standard library is significantly slower than version 0.8.0 of the reference implementation of these hash algorithms, but they produce the same outputs given the same inputs. This equality of outputs is checked with tests that duplicate portions of xsum_sanity_check.c from the reference implementation.
ppxxh is compatible with Python 3.0 and newer.
The interface and use of ppxxh is similar to the Python standard library module hashlib, while providing XXHASH hash algorithms. Thus the various hash objects may be created using the ppxxh.new() function or directly instantiated from their classes.
Hash Methods
The hash objects have these common methods:
- update(data)
Update the state of the hash object. Data may be passed to the hash object at initialization and/or by an arbitrary number of calls to update().
- digest()
Return the hash digest as a bytes object.
- hexdigest()
Return the hash digest as a string of hexidecimal digits.
- intdigest()
Return the hash digest as an unsigned integer.
This method is not part of the hashlib interface but is the typical output format of the reference implementation (except for xxh3_128)
- copy()
Return a copy (clone) of the hash object.
The xxh3_128 hash objects also have a intdigest2() method that returns the hash digest as a pair of 64-bit unsigned integers matching the typical output format of the reference implementation for this hash algorithm
As listed in ppxxh.algorithms_guaranteed and ppxxh.algorithms_guaranteed, the hash algorithms provided are xxh32, xxh64, xxh3_64, and xxh3_128.
The ppxxh.generate_secret() function duplicates the XXH3_generateSecret() function provided by the reference implementation to use a low entropy bytes like object of arbitrary length to generate a high entropy secret well suited to use as the secret parameter of xxh3_64 and xxh3_128.
Example
Calculate the digest in various forms for the bytes object, b'This is a bytes object, not a string!'. Specify a seed value. If this optional value were not provided, the hash object would be initialized differently and the various resulting digest values would all be different.
>>> from ppxxh import xxh64 >>> m = xxh64(seed=14414669413082423462) # seed is optional >>> m.name 'xxh64' >>> m.digest_size 8 >>> m.block_size 32 >>> m.update(b'This is a bytes') >>> m.hexdigest() # a digest may be requested at any time '938907256708f46c' >>> m.update(b' object, not a string!') >>> m.digest() b'!^>f7\x84Ii' >>> m.hexdigest() '215e3e6637844969' >>> m.intdigest() 2404427859801426281
A more condensed way to get the same result.
>>> xxh64(b'This is a bytes object, not a string!', ... seed=14414669413082423462).hexdigest() '215e3e6637844969'
The reference implementation of the XXHASH family are available at https://github.com/Cyan4973/xxHash
(Python code formatted by black -l 79)
Licensed under MIT License
Metadata
Release files for ppxxh 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| ppxxh-1.0.0.tar.gz | 16.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| ppxxh-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 37.6 kB
Release files / ppxxh-1.0.0.tar.gz
| Download URL | ppxxh-1.0.0.tar.gz |
|---|---|
| Size | 16.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1c5b82b0ae1356f8fa32e3f1d45fd059eef6ecf491de2061f169d9998ce59f3e
|
|
BLAKE2b-256 checksum How to use checksums |
5c33e3bc3a3734ac304ffa055e11c3c73f7ce9464d97af66d842ff4ba8faac50
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.2 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.5
|
Release files / ppxxh-1.0.0-py3-none-any.whl
| Download URL | ppxxh-1.0.0-py3-none-any.whl |
|---|---|
| Size | 21.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e43a13456fadf5d80f7ff70c17a2087a846f924d4ee7be41478191a27252d3e4
|
|
BLAKE2b-256 checksum How to use checksums |
124af6996785e0bd70b8d47405170ee68c7294be34d9a81614bf353a3dd1bd8f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.2 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.5
|