Skip to main content

Python binding for xxHash

Project description

Travis CI Build Status Appveyor Build Status Latest Version Supported Python versions License

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 string
digest() – return the current digest value
hexdigest() – return the current digest as a string of hexadecimal digits
intdigest() – return the current digest as an integer
copy() – return a copy of the current xxhash object
reset() – 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.

CHANGELOG

v1.1.0 2018-07-05

  • Allow input larger than 2GB

  • Release the GIL on sufficiently large input

  • Drop support for Python 3.2

v1.0.1 2017-03-02

  • Free state actively, instead of delegating it to ffi.gc

v1.0.0 2017-02-10

  • Fixed copy() segfault

  • Added CFFI variant

v0.6.3 2017-02-10

  • Fixed copy() segfault

v0.6.2 2017-02-10

  • Upgrade xxHash to v0.6.2

v0.6.1 2016-06-26

  • Upgrade xxHash to v0.6.1

v0.5.0 2016-03-02

  • Upgrade xxHash to v0.5.0

v0.4.3 2015-08-21

  • Upgrade xxHash to r42

v0.4.1 2015-08-16

  • Upgrade xxHash to r41

v0.4.0 2015-08-05

  • Added method reset

  • Upgrade xxHash to r40

v0.3.2 2015-01-27

  • Fixed some typos in docstrings

v0.3.1 2015-01-24

  • Upgrade xxHash to r39

v0.3.0 2014-11-11

  • Change digest() from little-endian representation to big-endian representation of the integer digest. This change breaks compatibility (digest() results are different).

v0.2.0 2014-10-25

  • Make this package hashlib-compliant

v0.1.3 2014-10-23

  • Update xxHash to r37

v0.1.2 2014-10-19

  • Improve: Check XXHnn_init() return value.

  • Update xxHash to r36

v0.1.1 2014-08-07

  • Improve: Can now be built with Visual C++ Compiler.

v0.1.0 2014-08-05

  • New: XXH32 and XXH64 type, which support partially update.

  • Fix: build under Python 3.4

v0.0.2 2014-08-03

  • NEW: Support Python 3

v0.0.1 2014-07-30

  • NEW: xxh32 and xxh64

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

xxhash-1.1.0.tar.gz (32.7 kB view details)

Uploaded Source

Built Distributions

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

xxhash-1.1.0-cp37-cp37m-manylinux1_x86_64.whl (44.0 kB view details)

Uploaded CPython 3.7m

xxhash-1.1.0-cp37-cp37m-manylinux1_i686.whl (46.7 kB view details)

Uploaded CPython 3.7m

xxhash-1.1.0-cp36-cp36m-win_amd64.whl (16.5 kB view details)

Uploaded CPython 3.6mWindows x86-64

xxhash-1.1.0-cp36-cp36m-win32.whl (16.3 kB view details)

Uploaded CPython 3.6mWindows x86

xxhash-1.1.0-cp36-cp36m-manylinux1_x86_64.whl (43.0 kB view details)

Uploaded CPython 3.6m

xxhash-1.1.0-cp36-cp36m-manylinux1_i686.whl (45.6 kB view details)

Uploaded CPython 3.6m

xxhash-1.1.0-cp35-cp35m-win_amd64.whl (16.5 kB view details)

Uploaded CPython 3.5mWindows x86-64

xxhash-1.1.0-cp35-cp35m-win32.whl (16.3 kB view details)

Uploaded CPython 3.5mWindows x86

xxhash-1.1.0-cp35-cp35m-manylinux1_x86_64.whl (42.8 kB view details)

Uploaded CPython 3.5m

xxhash-1.1.0-cp35-cp35m-manylinux1_i686.whl (45.5 kB view details)

Uploaded CPython 3.5m

xxhash-1.1.0-cp34-cp34m-win32.whl (15.2 kB view details)

Uploaded CPython 3.4mWindows x86

xxhash-1.1.0-cp34-cp34m-manylinux1_x86_64.whl (42.6 kB view details)

Uploaded CPython 3.4m

xxhash-1.1.0-cp34-cp34m-manylinux1_i686.whl (45.3 kB view details)

Uploaded CPython 3.4m

xxhash-1.1.0-cp33-cp33m-win32.whl (18.8 kB view details)

Uploaded CPython 3.3mWindows x86

xxhash-1.1.0-cp33-cp33m-manylinux1_x86_64.whl (46.1 kB view details)

Uploaded CPython 3.3m

xxhash-1.1.0-cp33-cp33m-manylinux1_i686.whl (48.7 kB view details)

Uploaded CPython 3.3m

xxhash-1.1.0-cp27-cp27mu-manylinux1_x86_64.whl (41.6 kB view details)

Uploaded CPython 2.7mu

xxhash-1.1.0-cp27-cp27mu-manylinux1_i686.whl (44.5 kB view details)

Uploaded CPython 2.7mu

xxhash-1.1.0-cp27-cp27m-win_amd64.whl (14.4 kB view details)

Uploaded CPython 2.7mWindows x86-64

xxhash-1.1.0-cp27-cp27m-win32.whl (15.1 kB view details)

Uploaded CPython 2.7mWindows x86

xxhash-1.1.0-cp27-cp27m-manylinux1_x86_64.whl (41.6 kB view details)

Uploaded CPython 2.7m

xxhash-1.1.0-cp27-cp27m-manylinux1_i686.whl (44.5 kB view details)

Uploaded CPython 2.7m

File details

Details for the file xxhash-1.1.0.tar.gz.

File metadata

  • Download URL: xxhash-1.1.0.tar.gz
  • Upload date:
  • Size: 32.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for xxhash-1.1.0.tar.gz
Algorithm Hash digest
SHA256 66c9cc9cdd1c9da8496325a41c0abe813c2adcb96f99c770add12d1661488ae6
MD5 bcf821bb23b27861717908f1265f061d
BLAKE2b-256 c024d355784a078eea633f49b8736a1df9972569634e0da9d5ae594836e0e674

See more details on using hashes here.

File details

Details for the file xxhash-1.1.0-cp37-cp37m-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for xxhash-1.1.0-cp37-cp37m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 16387e0a27b46001f9f420bef873dc65999d073ca550bd5fa26dbae703189030
MD5 098493ff6865397d0fafcd0c65619df6
BLAKE2b-256 f0b4627146a3bb1db646f26d5d61c88dfaa33874e6f1649c24d538f9b8fc2248

See more details on using hashes here.

File details

Details for the file xxhash-1.1.0-cp37-cp37m-manylinux1_i686.whl.

File metadata

File hashes

Hashes for xxhash-1.1.0-cp37-cp37m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 cbe1576712e560fdefcc1ec44b3a08fe65251a028d5a5f07515bbf4d19a9bc0e
MD5 9d441f516e90e20e31069471e12b6ff8
BLAKE2b-256 47812ff971a8f4392cdb3112af0ec8af9e385e41ff3cbd42c530a95adb042f05

See more details on using hashes here.

File details

Details for the file xxhash-1.1.0-cp36-cp36m-win_amd64.whl.

File metadata

File hashes

Hashes for xxhash-1.1.0-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 454125bdd6d1282cce3c4526a98c1e6343177df746747285575dca82cc3cddb3
MD5 71c4a4e0d4e69f73bc0f25d5be07b9b2
BLAKE2b-256 09d0ef51a3fb1d79a0e7958f8cbb36da725e78bc8ab15ff13a8469512f550fd7

See more details on using hashes here.

File details

Details for the file xxhash-1.1.0-cp36-cp36m-win32.whl.

File metadata

File hashes

Hashes for xxhash-1.1.0-cp36-cp36m-win32.whl
Algorithm Hash digest
SHA256 ba0f3e66dd304eaa83d06eefc27e6d3f27773bf02980ce93920bcda66331c65a
MD5 544fde98b686f1d4854a80a510fefa7e
BLAKE2b-256 c97eeb4c9d8695716a005a39f71d9a0eceeab2763310258d07244f70d35938e7

See more details on using hashes here.

File details

Details for the file xxhash-1.1.0-cp36-cp36m-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for xxhash-1.1.0-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 e16e1fdd188d809c895d9a71b098d076847ef00fd7e3e7a9c885fcd2209b2cb9
MD5 c0fafe9f464ba7832f2dd120cb8c2352
BLAKE2b-256 487e21e45a239af30bb7f064640923acf8c239f8006e78e5a3093437518c2d87

See more details on using hashes here.

File details

Details for the file xxhash-1.1.0-cp36-cp36m-manylinux1_i686.whl.

File metadata

File hashes

Hashes for xxhash-1.1.0-cp36-cp36m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 8bbbb03326a1fc929680b38880b3d5115704983d2fe3a8d586e9ff4e09c4f1bf
MD5 8dcf8fc1afc30b36edea85d12486b5ad
BLAKE2b-256 6e8018e37cbfeb3a2526030fa2753589f301c0b4bc209ecbe0bf72480deae5ce

See more details on using hashes here.

File details

Details for the file xxhash-1.1.0-cp35-cp35m-win_amd64.whl.

File metadata

File hashes

Hashes for xxhash-1.1.0-cp35-cp35m-win_amd64.whl
Algorithm Hash digest
SHA256 633d371c257f3d2f5110ae61882f00304c9d04492357bbbe4f83f7129502e07d
MD5 46da316e6ce6ce31d7113df01bb00419
BLAKE2b-256 b691bcccb423af2ec1563f1d57c32a2fff5f478b09ee17e5c80a2cb79d0bc65a

See more details on using hashes here.

File details

Details for the file xxhash-1.1.0-cp35-cp35m-win32.whl.

File metadata

File hashes

Hashes for xxhash-1.1.0-cp35-cp35m-win32.whl
Algorithm Hash digest
SHA256 d1876df7ebb3600e878e4a22d925bf63b9bc093b8f5e6f330e039e17d80f9971
MD5 499aa2098087864a6ee4fe685ef0a188
BLAKE2b-256 092782234ee18b2fb268989603cddf9e91dd86b7a39f061026ad99a923d59abe

See more details on using hashes here.

File details

Details for the file xxhash-1.1.0-cp35-cp35m-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for xxhash-1.1.0-cp35-cp35m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 b749b2befe7e114f51f1398e45f857d1ede6f2fc0ed69759a0d2e3b22d366cde
MD5 049ce4d8c7c937c6d786c736fe515a4f
BLAKE2b-256 bd9d4bdbc124d770727de13debdf5095e2278aee40b833a754c0fdfc758bf204

See more details on using hashes here.

File details

Details for the file xxhash-1.1.0-cp35-cp35m-manylinux1_i686.whl.

File metadata

File hashes

Hashes for xxhash-1.1.0-cp35-cp35m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 90506fa90a6d1c6b13b74f23c6c18a7720fc4c08acd3a1568b2e85d7c73de9c8
MD5 81510775a26c4bc27d4298045e0d07eb
BLAKE2b-256 bb46b099cf17ef1bf34f8e8a98b9887c035462642b393bd25c84f6835952fd28

See more details on using hashes here.

File details

Details for the file xxhash-1.1.0-cp34-cp34m-win32.whl.

File metadata

File hashes

Hashes for xxhash-1.1.0-cp34-cp34m-win32.whl
Algorithm Hash digest
SHA256 75520bdd455310c533c2d6e5c7acf532cb42a29754f79efe55d3b911b7f25d27
MD5 f757cde6c7ab6b0f015031b4b68f0a33
BLAKE2b-256 d48fb2da485e6af8af80a787ffc76e4f8f37fac8307cdae84e1372882ab0963d

See more details on using hashes here.

File details

Details for the file xxhash-1.1.0-cp34-cp34m-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for xxhash-1.1.0-cp34-cp34m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 76ede89c0b9aa36eb3ea22f1d07472bc830c6a5d8fc73c2da24137cd9e5a7cd7
MD5 ac493c55ea25d44c9c9507cae63f71bc
BLAKE2b-256 012cf3790ed53e47a4fec7d497c8dcc54d291c28e6631f844c159b937ee5df7d

See more details on using hashes here.

File details

Details for the file xxhash-1.1.0-cp34-cp34m-manylinux1_i686.whl.

File metadata

File hashes

Hashes for xxhash-1.1.0-cp34-cp34m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 90cbbd6e8eb167f1b9ad5119e38523070bde8cb2803777bcfb81f6ebc3dcba3a
MD5 8ad7a10110955ef6ef96e67c30016356
BLAKE2b-256 f03531135eb696ae1df8e17584037fa204a6ac185328a8d35f270187391eac0c

See more details on using hashes here.

File details

Details for the file xxhash-1.1.0-cp33-cp33m-win32.whl.

File metadata

File hashes

Hashes for xxhash-1.1.0-cp33-cp33m-win32.whl
Algorithm Hash digest
SHA256 00c2c4c2f2de80a2e26db813c444dfd97e5fe0e14d3548bd99629bf4cd926238
MD5 65d57fd2eecc05ae4e216a90b0d3a1d1
BLAKE2b-256 5c37cad5d328f4e436382e063e989456e1cd058afdab3c612bd9fd48c0a88ed2

See more details on using hashes here.

File details

Details for the file xxhash-1.1.0-cp33-cp33m-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for xxhash-1.1.0-cp33-cp33m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 884c8f0fb7e621fe8c547bcc08b5e620b5293266230ca22ee3eb5949db2918a5
MD5 ff71fe6b651959fc1a3a56715ef44f34
BLAKE2b-256 78d865ff87f077a307dd90579ea17d05c8db602d683efc0c70b6490d7b6dc534

See more details on using hashes here.

File details

Details for the file xxhash-1.1.0-cp33-cp33m-manylinux1_i686.whl.

File metadata

File hashes

Hashes for xxhash-1.1.0-cp33-cp33m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 0ed12f73b4f21d245cb49a7720db6f58ebbce245599726ffa43ce28817cf57af
MD5 5a20bfd380c5fe397a8540a444650769
BLAKE2b-256 f552385440d4dcfe3a22a00facdcc1ea6e77a39a41bd71d6c1c3c65011e50675

See more details on using hashes here.

File details

Details for the file xxhash-1.1.0-cp27-cp27mu-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for xxhash-1.1.0-cp27-cp27mu-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 90b64633913041ed78c3be90b03b20a2724aa995fb44cf222c4f432f96b7bed6
MD5 8588072b7eda4506d9a389f5b3344b68
BLAKE2b-256 395c39cd0cd16fd7ffaebe1d97c02eb827af2ec4df29de10db7c9edfd2b7be93

See more details on using hashes here.

File details

Details for the file xxhash-1.1.0-cp27-cp27mu-manylinux1_i686.whl.

File metadata

File hashes

Hashes for xxhash-1.1.0-cp27-cp27mu-manylinux1_i686.whl
Algorithm Hash digest
SHA256 b93a991a477928c746dab749304d1293d3039f232f19e5128661a8b468556be6
MD5 3b9ebd5733d8f11b88526a8e41fe73bd
BLAKE2b-256 ed5fb73749d12395bb9c8aa5bfb86fc84f941deb416437b79e464c2a12b978fa

See more details on using hashes here.

File details

Details for the file xxhash-1.1.0-cp27-cp27m-win_amd64.whl.

File metadata

File hashes

Hashes for xxhash-1.1.0-cp27-cp27m-win_amd64.whl
Algorithm Hash digest
SHA256 c1ad24139a126f4387dfffd6b477ca94bda89e2f794bfdd15956998dc536cac8
MD5 6d5302926857d76ea974574be17aa016
BLAKE2b-256 5a79627278ebff4c8ad0b15838a680e5055dc9888ce62282b9f8ea8ea5b3dab9

See more details on using hashes here.

File details

Details for the file xxhash-1.1.0-cp27-cp27m-win32.whl.

File metadata

File hashes

Hashes for xxhash-1.1.0-cp27-cp27m-win32.whl
Algorithm Hash digest
SHA256 ff247eda650a4740b7c37889137f188c52a83ab2b1879eecc94db923f87a358f
MD5 259721a918cc126ac5ab1685c9c8f8f0
BLAKE2b-256 02d3fe9c616eead929a2961b50975e76b8759f0408fb6dd0ebe524651777d656

See more details on using hashes here.

File details

Details for the file xxhash-1.1.0-cp27-cp27m-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for xxhash-1.1.0-cp27-cp27m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 6181f2924aedb01211fe6143a2649f7dace2ba6a8d22c3f311f8c8959ddb2017
MD5 f0c5bb67518e81f46a151464c7399dbf
BLAKE2b-256 08a317a9ebc8fc1d90b5eceba890dc0b9fbaa5d06743a78324d24f5c51f7b35b

See more details on using hashes here.

File details

Details for the file xxhash-1.1.0-cp27-cp27m-manylinux1_i686.whl.

File metadata

File hashes

Hashes for xxhash-1.1.0-cp27-cp27m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 d250dc05de0ac04be96cd67dcf02e55d9b0bf6d1a09cee6ab9f1578572e0c31a
MD5 ae65ddce8c166819d7ccb6091ccb8891
BLAKE2b-256 a5ae436d72a81b31cd1ee88f7726f2c3d25fff7258f2e3bbbf05a9bb3c8e0787

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