Python binding for xxHash
Project description
xxhash is a Python binding for the xxHash library by Yann Collet.
Installation
$ pip install xxhash
As of version 1.0.0, xxhash provides two variants: the original CPython variant, and the new CFFI variant. By default the installation is the CPython variant, setting env variable XXHASH_FORCE_CFFI=1 to install the CFFI variant:
$ export XXHASH_FORCE_CFFI=1
$ pip install xxhash
Installation Prerequisites
CPython Variant
On Debian/Ubuntu:
$ apt-get install python-dev gcc
On CentOS/Fedora:
$ yum install python-devel gcc redhat-rpm-config
CFFI Variant
On Debian/Ubuntu:
$ apt-get install libcffi-dev python-dev gcc
On CentOS/Fedora:
$ yum install libcffi-devel python-devel gcc redhat-rpm-config
Usage
Module version and its backend xxHash library version can be retrieved using the module properties VERSION AND XXHASH_VERSION respectively.
>>> import xxhash
>>> xxhash.VERSION
'1.0.1'
>>> xxhash.XXHASH_VERSION
'0.6.2'
This module is hashlib-compliant, which means you can use it in the same way as hashlib.md5.
update() – update the current digest with an additional stringdigest() – return the current digest valuehexdigest() – return the current digest as a string of hexadecimal digitsintdigest() – return the current digest as an integercopy() – return a copy of the current xxhash objectreset() – reset state
md5 digest returns bytes, but the original xxh32 and xxh64 C APIs return integers. While this module is made hashlib-compliant, intdigest() is also provided to get the integer digest.
Constructors for hash algorithms provided by this module are xxh32() and xxh64().
For example, to obtain the digest of the byte string b'Nobody inspects the spammish repetition'.
>>> import xxhash
>>> x = xxhash.xxh32()
>>> x.update(b'Nobody inspects')
>>> x.update(b' the spammish repetition')
>>> x.digest()
b'\xe2);/'
>>> x.digest_size
4
>>> x.block_size
16
More condensed.
>>> xxhash.xxh32(b'Nobody inspects the spammish repetition').hexdigest()
'e2293b2f'
>>> xxhash.xxh32(b'Nobody inspects the spammish repetition').digest() == x.digest()
True
An optional seed (default is 0) can be used to alter the result predictably.
>>> import xxhash
>>> xxhash.xxh64('xxhash').hexdigest()
'32dd38952c4bc720'
>>> xxhash.xxh64('xxhash', seed=20141025).hexdigest()
'b559b98d844e0635'
>>> x = xxhash.xxh64(seed=20141025)
>>> x.update('xxhash')
>>> x.hexdigest()
'b559b98d844e0635'
>>> x.intdigest()
13067679811253438005
Be careful that xxh32 takes an unsigned 32-bit integer as seed, while xxh64 takes an unsigned 64-bit integer. Although unsigned integer overflow is defined behavior, it’s better to not to let it happen.
>>> xxhash.xxh32('I want an unsigned 32-bit seed!', seed=0).hexdigest()
'f7a35af8'
>>> xxhash.xxh32('I want an unsigned 32-bit seed!', seed=2**32).hexdigest()
'f7a35af8'
>>> xxhash.xxh32('I want an unsigned 32-bit seed!', seed=1).hexdigest()
'd8d4b4ba'
>>> xxhash.xxh32('I want an unsigned 32-bit seed!', seed=2**32+1).hexdigest()
'd8d4b4ba'
>>>
>>> xxhash.xxh64('I want an unsigned 64-bit seed!', seed=0).hexdigest()
'd4cb0a70a2b8c7c1'
>>> xxhash.xxh64('I want an unsigned 64-bit seed!', seed=2**64).hexdigest()
'd4cb0a70a2b8c7c1'
>>> xxhash.xxh64('I want an unsigned 64-bit seed!', seed=1).hexdigest()
'ce5087f12470d961'
>>> xxhash.xxh64('I want an unsigned 64-bit seed!', seed=2**64+1).hexdigest()
'ce5087f12470d961'
digest() returns bytes of the big-endian representation of the integer digest.
>>> import xxhash
>>> h = xxhash.xxh64()
>>> h.digest()
b'\xefF\xdb7Q\xd8\xe9\x99'
>>> h.intdigest().to_bytes(8, 'big')
b'\xefF\xdb7Q\xd8\xe9\x99'
>>> h.hexdigest()
'ef46db3751d8e999'
>>> format(h.intdigest(), '016x')
'ef46db3751d8e999'
>>> h.intdigest()
17241709254077376921
>>> int(h.hexdigest(), 16)
17241709254077376921
Caveats
SEED OVERFLOW
xxh32 takes an unsigned 32-bit integer as seed, and xxh64 takes an unsigned 64-bit integer as seed. Make sure that the seed is greater than or equal to 0.
ENDIANNESS
As of python-xxhash 0.3.0, digest() returns bytes of the big-endian representation of the integer digest. It used to be little-endian.
DONT USE XXHASH IN HMAC
Though you can use xxhash as an HMAC hash function, but it’s highly recommended not to.
xxhash is NOT a cryptographic hash function, it is a non-cryptographic hash algorithm aimed at speed and quality. Do not put xxhash in any position where cryptographic hash functions are required.
Copyright and License
Copyright (c) 2014-2017 Yue Du - https://github.com/ifduyue
Licensed under BSD 2-Clause License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for xxhash-1.0.1-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ad55574603cff6b1cb316d994f66379b0a6a9bd2017c669c77f1eda5ce4e6ddf |
|
MD5 | 2613c3b0638f6e6ebd4f6e4ff7718f7a |
|
BLAKE2b-256 | ee6b8e9c61b5d54a05e3fba93487fbe61a3f144ebb489d2efa1ce6650fce3295 |
Hashes for xxhash-1.0.1-cp37-cp37m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2013682962151de2d31fd9744e2d16ad5ec1d9c8071cd43798d4645f030ddfe4 |
|
MD5 | 60f68201c99a11301118d13e04b65ab3 |
|
BLAKE2b-256 | 959aad9de6974727710d32cba0c5deeb870b03c5f9fba9fd6545f27a7e86fbe9 |
Hashes for xxhash-1.0.1-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 22226a080fc7ddda42c2d53e2737119973898febef3df8d57ddbbc8f7e172a87 |
|
MD5 | fa212e045e384ee85b7ecebfc8f65922 |
|
BLAKE2b-256 | 6ebc943994998d5ba0a36835202760ab8677883534554e28abd5c7d19a8592f5 |
Hashes for xxhash-1.0.1-cp36-cp36m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c26a239c36db00c69661f0651e297571c844f2a0dac20127f9f5c61bea1300b4 |
|
MD5 | 59afa0cf0bec2ef468667efbfeb05856 |
|
BLAKE2b-256 | a0051bda357384b15a02b61448b36e567897e9aa5fa6c618191585b443e0b007 |
Hashes for xxhash-1.0.1-cp36-cp36m-macosx_10_10_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e4a7f6fa64f6eba0245d89ce4ab4e5dff789060f18328722ba71e3f477d763c1 |
|
MD5 | 9ae70bcf9a88cf9184bd606e7a6148b0 |
|
BLAKE2b-256 | f9aa9615b5153d1ec4a0b9e4cac3b017f0478693d6968cc8790a3936366cbca0 |
Hashes for xxhash-1.0.1-cp35-cp35m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 068815d889733d565fe5f2f409907ded830220c9a9e64cc899fec5bf5addf1c3 |
|
MD5 | cd3268a993fee6cce24d4fab42e6e31a |
|
BLAKE2b-256 | 6f2c5d78ed9ec086794448178ff79f3707579b1e3ed8b63784f4b96265c22650 |
Hashes for xxhash-1.0.1-cp35-cp35m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7aee439490645a2111ce5152d5c13c981e9b53fad258f877642c300dc8f04f7d |
|
MD5 | 379350a5affb72d8c8c7664cc46d9a69 |
|
BLAKE2b-256 | 76164a49fe233d54a4b176d3f0543b480e94ef6a42ac0e22d166990179266e9b |
Hashes for xxhash-1.0.1-cp34-cp34m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 623b7c097998256e96f1cf72071a2287d48dbe79a26f9631e0e426b3f392896f |
|
MD5 | 5569da20477f6bd35671fc4c21d84964 |
|
BLAKE2b-256 | b48d6193d7a35596aca106252c3e00a9af95a2ac3232f8b1b3f8e85bccd98e67 |
Hashes for xxhash-1.0.1-cp34-cp34m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5a2a1194052127a69fa142bf0c56863636bf9d5a295197dd694cbf2a1b35ecb7 |
|
MD5 | 1de76ae3c2056aa2445ac101e1dc5223 |
|
BLAKE2b-256 | f4a4e772db12a3cd1c0c3c304346cb5087c931fa26608e2c6591d23cd2d2b559 |
Hashes for xxhash-1.0.1-cp33-cp33m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 91737d7694cdeb69002467296c60586c9b7ed8ec7f51c2cab4e8f0a163e9b8e1 |
|
MD5 | 7132ca48447ca080b094a1ff14ffb70f |
|
BLAKE2b-256 | 57d71a4d922cb9c23b54b85b2449b9472ac648d2043b6f69aa3c79f0387302e9 |
Hashes for xxhash-1.0.1-cp33-cp33m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9a7f6e8b3987c1e32bf9d8d44832b991440a006c9d8e899173480b72fc5b63a5 |
|
MD5 | f7746bb33297af1d28b079bdb41cd259 |
|
BLAKE2b-256 | 1e633b18c75edf621e53dbb1c79a74ba29c69d46d62b1edf88270a4b31878b6f |
Hashes for xxhash-1.0.1-cp27-cp27mu-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1c4bf2c2259b882bdcf3429a69419a0a70acb6f8c18f4b64851c363dae2617b8 |
|
MD5 | bc624accf19822e3d9b368867a0ad568 |
|
BLAKE2b-256 | 5672c758d9cd9ff7c8107e2483f9e739a9e1fb8a4c04f16225403f0fa2fe5ed0 |
Hashes for xxhash-1.0.1-cp27-cp27mu-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 19cba39a52e2944626c2b3a65433724698d95919632f752dac2a20e9c77ccd43 |
|
MD5 | f9438831caae3c9f8098f3a843bf9d65 |
|
BLAKE2b-256 | 1fc9af439dbed3ca49243f500022b3d57f081fed616de8cf3bd6ec33efe1fc9f |
Hashes for xxhash-1.0.1-cp27-cp27m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d84696958077bdd7630f7f85f91d2b71b4b6eb41600b28ad6be6842eb9055fca |
|
MD5 | ffcaf4b17ab5d096975395b29f960483 |
|
BLAKE2b-256 | b3ed640d72ad573f62892fa49c5e23c15903fbd02341b82c97aabd55eb28e648 |
Hashes for xxhash-1.0.1-cp27-cp27m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6876bdc764489a95d9f71e9fae7e74f5ac4032ead3053f3b2f0a6a12177b14ae |
|
MD5 | 3ff3be2eef7784e9646384e57e81ae5f |
|
BLAKE2b-256 | 47d1cedf2435c1ab9c626d98c1102dc7e07946d99a1ca2dc49793dbe80ca938c |
Hashes for xxhash-1.0.1-cp27-cp27m-macosx_10_10_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4dadd94a448d8902df2fd4450fd8bc635009466eaf9c083b4c9530eafd8c9c1f |
|
MD5 | d0bcdbd985461809ba8c4fc2f69ab83f |
|
BLAKE2b-256 | 953506e37c9326856ede6653bc0c70a3d1ac68978a105d5448dbba828337db42 |