BLAKE3 Hash Function
blake3-py provides high-performance Python bindings for the BLAKE3 cryptographic hash function, implemented in Rust. It offers a fast, secure, and modern hashing algorithm. The current version is 1.0.8, with releases typically driven by updates to the underlying Rust `blake3` crate, PyO3, or support for new Python versions.
Warnings
- gotcha Installation may require a Rust toolchain. While pre-built wheels are available for most common platforms and Python versions, if a suitable wheel is not found for your specific environment (OS, architecture, Python version), pip will attempt to build the library from source. This requires the Rust programming language and Cargo package manager to be installed on your system.
- gotcha Minimum Supported Rust Version (MSRV) increases over time. For versions 1.0.7 and later, the MSRV is Rust 1.80. If you are building from source, an older Rust toolchain might lead to compilation failures.
- gotcha For optimal performance and memory usage with large datasets, use `blake3.Hasher()` for incremental hashing. The `blake3.blake3()` function is designed for one-shot hashing of data that fits comfortably in memory. Repeated calls to `blake3.blake3()` on chunks of a large file will be inefficient compared to using the `Hasher` object.
Install
-
pip install blake3
Imports
- blake3
import blake3
Quickstart
import blake3
# One-shot hashing
data = b"Hello, BLAKE3!"
hash_result = blake3.blake3(data).hexdigest()
print(f"One-shot hash: {hash_result}")
# Incremental hashing
hasher = blake3.Hasher()
hasher.update(b"First part. ")
hasher.update(b"Second part.")
incremental_hash = hasher.finalize().hexdigest()
print(f"Incremental hash: {incremental_hash}")