Skip to main content

Python binding for xxHash

Project description

Build Status Latest Version Downloads Supported Python versions License

xxhash is a Python binding for the xxHash library by Yann Collet.

Installation

$ pip install xxhash

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
'0.3.0'
>>> xxhash.XXHASH_VERSION
'r37'

This module is hashlib-compliant, which means you can use it in the same way as hashlib.md5.

update() – updates 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

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

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

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

xxhash-0.4.1.zip (21.7 kB view details)

Uploaded Source

xxhash-0.4.1.tar.gz (17.0 kB view details)

Uploaded Source

xxhash-0.4.1.tar.bz2 (15.0 kB view details)

Uploaded Source

Built Distributions

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

xxhash-0.4.1-cp34-cp34m-macosx_10_10_x86_64.whl (12.7 kB view details)

Uploaded CPython 3.4mmacOS 10.10+ x86-64

xxhash-0.4.1-cp27-none-macosx_10_10_x86_64.whl (12.4 kB view details)

Uploaded CPython 2.7macOS 10.10+ x86-64

File details

Details for the file xxhash-0.4.1.zip.

File metadata

  • Download URL: xxhash-0.4.1.zip
  • Upload date:
  • Size: 21.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for xxhash-0.4.1.zip
Algorithm Hash digest
SHA256 8f561edc5677b72feeb6f71141146df96aa999e9077618cde4695833785ea1d5
MD5 011a0457e80019091b920d275cebcc82
BLAKE2b-256 fff20420b16b54267c9e73025bc10e1c1a4b1e6390e90200de52999090623eec

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for xxhash-0.4.1.tar.gz
Algorithm Hash digest
SHA256 7e6a56a28fa4da708800a1e64bbc13209f5f1fd2e898c8a8dbb5f2e7803e6a73
MD5 9d2cd58884f90c263beb60af41771a8a
BLAKE2b-256 a1ba30ad51fa659f350b00940cb45fab084e5d067165151866e76c4a674ede5b

See more details on using hashes here.

File details

Details for the file xxhash-0.4.1.tar.bz2.

File metadata

  • Download URL: xxhash-0.4.1.tar.bz2
  • Upload date:
  • Size: 15.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for xxhash-0.4.1.tar.bz2
Algorithm Hash digest
SHA256 fe3bcdaa0d968998802423d31822a1e11aa323bb0eb9dfc1a58c13feb4c0d506
MD5 f05022680e9bc9a504318b2418c24644
BLAKE2b-256 b53f36416c8ef2108aca5fe0882e567d778fd74a966eec67f1abcc65e93be5ad

See more details on using hashes here.

File details

Details for the file xxhash-0.4.1-cp34-cp34m-macosx_10_10_x86_64.whl.

File metadata

File hashes

Hashes for xxhash-0.4.1-cp34-cp34m-macosx_10_10_x86_64.whl
Algorithm Hash digest
SHA256 25b5042fc681db6c2babb73605cfa43861517897ddd82da50f4188694512b0d2
MD5 67b9f171c8ec4ab8706abf59d60a8ad9
BLAKE2b-256 be2eb818a6e65bd8e2c9ad6ff89e928a7e0b3e7a3a9747c4b544cccedd22bc7d

See more details on using hashes here.

File details

Details for the file xxhash-0.4.1-cp27-none-macosx_10_10_x86_64.whl.

File metadata

File hashes

Hashes for xxhash-0.4.1-cp27-none-macosx_10_10_x86_64.whl
Algorithm Hash digest
SHA256 b00c158480a30e515acf6ae8b8f85c4c636c4c5d52908e07bac91b744860a409
MD5 648b624a91241dd076eea61043d3213d
BLAKE2b-256 7f3168d39bd9ccfaf9abe7818585eb3c5e5a16edfa14ea3f1338327c58a0ae34

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