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.4.1'
>>> xxhash.XXHASH_VERSION
'r41'

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.4.3.zip (22.3 kB view details)

Uploaded Source

xxhash-0.4.3.tar.gz (16.5 kB view details)

Uploaded Source

xxhash-0.4.3.tar.bz2 (15.5 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.3-cp34-cp34m-macosx_10_10_x86_64.whl (12.7 kB view details)

Uploaded CPython 3.4mmacOS 10.10+ x86-64

xxhash-0.4.3-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.3.zip.

File metadata

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

File hashes

Hashes for xxhash-0.4.3.zip
Algorithm Hash digest
SHA256 0f087c43d9c83582672b246d57c14c09014a344fdfdaad5af6eb1b84926d954d
MD5 b2e88c37a3c0f283ec3edfc143075c7f
BLAKE2b-256 520525560b170c7ea2cf06a38afefd078cce3b152b0e99e801769c257fe5e8f9

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for xxhash-0.4.3.tar.gz
Algorithm Hash digest
SHA256 ddf4e05839c2b7954369e55ed9ce1a96885c272460be7b83bd7b91f67a3c2275
MD5 0cd1f046513eec86ccd4332fafaacaf2
BLAKE2b-256 1dfb34eb664ad4282abdd1685608587af3285a613cc84a63e0800db9e903d316

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for xxhash-0.4.3.tar.bz2
Algorithm Hash digest
SHA256 733edbbc8f55a9e61bc55d5c2569c14a455ec2eb750b55f7dc1ddf889262329e
MD5 11ab31044a7c4dd88d3262eaf27506b2
BLAKE2b-256 5c19b642798083e9d5543797b4571981acc5256e908e9ee19eebad8b565369c2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xxhash-0.4.3-cp34-cp34m-macosx_10_10_x86_64.whl
Algorithm Hash digest
SHA256 d8c3fbd51011ae6c5bce35897d49a214247046a6ea4e0e6a22dfd31d2ff4017b
MD5 f968ca9068de1913b5a72dd7376d394b
BLAKE2b-256 776dd6a4bd9dba71938ef3d2d9d92fdcb7752c73b9658f31211bf5068c4e221b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xxhash-0.4.3-cp27-none-macosx_10_10_x86_64.whl
Algorithm Hash digest
SHA256 2dfdd41c1126bd13f16d025cec9e2bf9b2065f66cc5b1d130cd59135a7fccf13
MD5 7c07d61b506fc7f365a878b950d39b45
BLAKE2b-256 5e66c9f8289e8d2a12c8ca5413da218a9f56d77b8517cc15fd1811df52621a64

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