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.5.0'
>>> xxhash.XXHASH_VERSION
'0.5.0'

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

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.5.0.zip (23.7 kB view details)

Uploaded Source

xxhash-0.5.0.tar.gz (18.6 kB view details)

Uploaded Source

xxhash-0.5.0.tar.bz2 (16.5 kB view details)

Uploaded Source

File details

Details for the file xxhash-0.5.0.zip.

File metadata

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

File hashes

Hashes for xxhash-0.5.0.zip
Algorithm Hash digest
SHA256 3d4ae92ae5137834a4b440fc37e89c4d0da1846738bc1b70d910a1995c99c6ea
MD5 68c6e798b289fae31f1c59cbd185f261
BLAKE2b-256 42be139d65cf585f560b7a4a1af67d57a1e4c0c8dae1d0af669e4e6ac5778a95

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for xxhash-0.5.0.tar.gz
Algorithm Hash digest
SHA256 3b3e7faf06a0f7e8093420e09ccbea3ed782153d4c6e374b79dff84b900bbdde
MD5 a12d5502c3a216c690f290f9d38eca4a
BLAKE2b-256 76a372a1fbbd25c1687c670f129ee474c1c29caf6f0bd1761f048f9e4df06e8c

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for xxhash-0.5.0.tar.bz2
Algorithm Hash digest
SHA256 0034354517dd24038b8bbc2046b2677caafda958b63be6e65526fbb1662465d5
MD5 9dd22f5d8551370cbb3c36a01f628c92
BLAKE2b-256 ddbbc338cf498229413c88ae9e486b398176d929f4ee1c735074de30d7e196c2

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