xxHash Python Binding

3.6.0 · active · verified Sat Mar 28

xxhash is a Python binding for the high-performance, non-cryptographic xxHash library by Yann Collet. It is widely favored for its speed and efficiency in applications requiring fast hashing of large volumes of data, such as data integrity checks, file deduplication, and checksum generation. The library is actively maintained, with version 3.6.0 currently available, and new releases occurring a few times a year, often to support newer Python versions and xxHash upstream updates.

Warnings

Install

Imports

Quickstart

This example demonstrates both one-shot and incremental hashing using the `xxh64` and `xxh3_128` algorithms. Data must be provided as bytes. An optional seed can be used to generate distinct hash outputs for identical input data.

import xxhash

data_to_hash = b"Hello, xxHash! This is some data to be hashed."

# One-shot hashing
hash_value_64 = xxhash.xxh64(data_to_hash, seed=0).hexdigest()
hash_value_128 = xxhash.xxh3_128(data_to_hash).hexdigest()

print(f"XXH64 Hash: {hash_value_64}")
print(f"XXH3_128 Hash: {hash_value_128}")

# Incremental hashing
hasher = xxhash.xxh64(seed=42)
hasher.update(b"First chunk ")
hasher.update(b"of data.")
incremental_hash = hasher.hexdigest()
print(f"Incremental XXH64 Hash: {incremental_hash}")

view raw JSON →