Python bindings for the Rust blake3 crate
Project description
blake3-py
Python bindings for the official Rust implementation of
BLAKE3, based on
PyO3. These bindings expose all the features of
BLAKE3, including extendable output, keying, and multithreading. The basic API
matches that of Python's standard
hashlib
module.
Examples
from blake3 import blake3
# Hash some input all at once. The input can be bytes, a bytearray, or a memoryview.
hash1 = blake3(b"foobarbaz").digest()
# Hash the same input incrementally.
hasher = blake3()
hasher.update(b"foo")
hasher.update(b"bar")
hasher.update(b"baz")
hash2 = hasher.digest()
assert hash1 == hash2
# Hexadecimal output.
print("The hash of 'hello world' is", blake3(b"hello world").hexdigest())
# Use the keyed hashing mode, which takes a 32-byte key.
zero_key = b"\0" * 32
message = b"a message to authenticate"
mac = blake3(message, key=zero_key).digest()
# Use the key derivation mode, which takes a context string. Context strings
# should be hardcoded, globally unique, and application-specific.
context = "blake3-py 2020-03-04 11:13:10 example context"
key_material = b"some super secret key material"
derived_key = blake3(key_material, derive_key_context=context).digest()
# Extendable output. The default digest size is 32 bytes.
extended = blake3(b"foo").digest(length=100)
assert extended[:32] == blake3(b"foo").digest()
assert extended[75:100] == blake3(b"foo").digest(length=25, seek=75)
# Hash a large input with multithreading. Note that this can be slower
# for short inputs, and you should benchmark it for your use case on
# your platform. As a rule of thumb, don't use multithreading for inputs
# shorter than 1 MB.
large_input = bytearray(1_000_000)
hash3 = blake3(large_input, multithreading=True).digest()
# Copy a hasher that has already accepted some input.
hasher1 = blake3(b"foo")
hasher2 = hasher1.copy()
hasher1.update(b"bar")
hasher2.update(b"baz")
assert hasher1.digest() == blake3(b"foobar").digest()
assert hasher2.digest() == blake3(b"foobaz").digest()
Installation
pip install blake3
As usual with Pip, you might need to use sudo
or the --user
flag
with the command above, depending on how you installed Python on your
system.
There are binary wheels available on PyPI for most environments. But if you're building the source distribution, or if a binary wheel isn't available for your environment, you'll need to install the Rust toolchain.
Thread Safety and the GIL
Like the hashlib
functions in the Python standard library, we release
the GIL while hashing, to avoid blocking other threads for a potentially
long time. However, this allows race conditions: it's possible for other
threads to access a hasher or an input buffer while hashing is going on.
This is worse than an ordinary Python race condition. It's undefined
behavior in the C/C++/Rust sense. But this seems to be the standard way
to do hashing in Python. In any case, it should be rare for real world
programs to share a hasher between threads. For more details about this
issue, see the comments on usafe code in lib.rs
.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
File details
Details for the file blake3-0.2.0.tar.gz
.
File metadata
- Download URL: blake3-0.2.0.tar.gz
- Upload date:
- Size: 33.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.8.11
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 91794f3335062ff484aaef1ff028276c904b1eca0cccfea18e081c25b5f2c7d0 |
|
MD5 | 346e5c7250e54ed59e30401675935376 |
|
BLAKE2b-256 | c8dc40d740998936be074666acaf2d1f7c90959898272bf587377f1f65c86b7b |
File details
Details for the file blake3-0.2.0-cp39-none-win_amd64.whl
.
File metadata
- Download URL: blake3-0.2.0-cp39-none-win_amd64.whl
- Upload date:
- Size: 178.4 kB
- Tags: CPython 3.9, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.8.11
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7037a22ed87840b00f3745cdb7c7d850d8f8b85bd7b845f24a655f41908b4b4f |
|
MD5 | b54b696259a8fda0c5453566ef33f96e |
|
BLAKE2b-256 | 32216b99f603a19232dfc51a299518e0e7e4af30ffaa11010b45cb3648e9ce41 |
File details
Details for the file blake3-0.2.0-cp39-none-win32.whl
.
File metadata
- Download URL: blake3-0.2.0-cp39-none-win32.whl
- Upload date:
- Size: 194.3 kB
- Tags: CPython 3.9, Windows x86
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.8.11
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7c8ca9807a0e42cc3149b0dc40dbdf612a89674f6cafe6ea5b7eafe718bf2620 |
|
MD5 | 47fdc0c651e7f343f2ab7865563e3d82 |
|
BLAKE2b-256 | d8a038358e99f1fde98c3987400b8a44ddbe259c5cd83e67e4bda93344867a9c |
File details
Details for the file blake3-0.2.0-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.whl
.
File metadata
- Download URL: blake3-0.2.0-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.whl
- Upload date:
- Size: 952.3 kB
- Tags: CPython 3.9, manylinux: glibc 2.5+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.8.11
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9432148c58aa6f1d7ca08b87f5467c9708e6650b18af9733a6359ffa6cfac3de |
|
MD5 | a8f351673bab7b7fb742cb239f8a2b76 |
|
BLAKE2b-256 | 5b3a417cf4594dee08a039f662a619772a33b55440fd0bdc54bca09d3f9b484f |
File details
Details for the file blake3-0.2.0-cp39-cp39-macosx_10_7_x86_64.whl
.
File metadata
- Download URL: blake3-0.2.0-cp39-cp39-macosx_10_7_x86_64.whl
- Upload date:
- Size: 286.6 kB
- Tags: CPython 3.9, macOS 10.7+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.8.11
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 517d8a64b540075bb6625d1bc60db27b00b00dd935e382d09959686bde921d05 |
|
MD5 | ad4e33fa3bd11b422d17713af1f92095 |
|
BLAKE2b-256 | 3d02b01da3b8830c229b554464088c36d08ba11f5e261d839446beee412aa70b |
File details
Details for the file blake3-0.2.0-cp38-none-win_amd64.whl
.
File metadata
- Download URL: blake3-0.2.0-cp38-none-win_amd64.whl
- Upload date:
- Size: 178.3 kB
- Tags: CPython 3.8, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.8.11
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e006685c888f40ed2dc3051fd69d5fdd36bfc1ac0aa754ec7688b748b6f3cef1 |
|
MD5 | 2d4d22673f8cadf7b1a82d854768917e |
|
BLAKE2b-256 | 9fca68daf89d2707c7eb8c4822cddf3c85ea92a4abd8a4c8a180f3704d8bb62a |
File details
Details for the file blake3-0.2.0-cp38-none-win32.whl
.
File metadata
- Download URL: blake3-0.2.0-cp38-none-win32.whl
- Upload date:
- Size: 194.4 kB
- Tags: CPython 3.8, Windows x86
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.8.11
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 27e56e21c7b8b59f06c4c218fdcbca6291546ad4215833da93e263c4b02e85a0 |
|
MD5 | 4a20dd13f3b98af50bcffcb3eb0e70e4 |
|
BLAKE2b-256 | 24c6af2355b6a4fa0d28d1267bad999d56ac10fd1f1ba66354495a548f56b67c |
File details
Details for the file blake3-0.2.0-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.whl
.
File metadata
- Download URL: blake3-0.2.0-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.whl
- Upload date:
- Size: 952.3 kB
- Tags: CPython 3.8, manylinux: glibc 2.5+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.8.11
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 26a77e9251f159177854758546b5395d8c21186eee32894e41f9534843d56f3e |
|
MD5 | 7ae0721a1775bed14552a4b42e48836d |
|
BLAKE2b-256 | 57ad49be8a53bf4cd1abf1f7cfdbfb147f0bae0e782f528eef6fed4adad26d43 |
File details
Details for the file blake3-0.2.0-cp38-cp38-macosx_10_7_x86_64.whl
.
File metadata
- Download URL: blake3-0.2.0-cp38-cp38-macosx_10_7_x86_64.whl
- Upload date:
- Size: 286.5 kB
- Tags: CPython 3.8, macOS 10.7+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.8.11
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1545ff1b499109f8be73fcfc0c72b77d0f7035b4e656e209964c0de407f7301a |
|
MD5 | 0be0e69e5839e01fb2594b02b3ccef7d |
|
BLAKE2b-256 | 595182bbb9c0f5e71974c2ac1b59cdf6259009d4a39dbd440aaccb0d1d0ec098 |
File details
Details for the file blake3-0.2.0-cp37-none-win_amd64.whl
.
File metadata
- Download URL: blake3-0.2.0-cp37-none-win_amd64.whl
- Upload date:
- Size: 178.5 kB
- Tags: CPython 3.7, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.8.11
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 35b216ccc84607e0b683a1efaa221ddad8b0f8bb7d7c6017f1286ec0d59e4995 |
|
MD5 | 428ff66accaa9fb1b62f85373d30b113 |
|
BLAKE2b-256 | 0e7774c40ba9a819fd1389abc1272d606cdeee984811a9b244b41505a6548819 |
File details
Details for the file blake3-0.2.0-cp37-none-win32.whl
.
File metadata
- Download URL: blake3-0.2.0-cp37-none-win32.whl
- Upload date:
- Size: 194.4 kB
- Tags: CPython 3.7, Windows x86
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.8.11
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 66252d5e7b9320c51b1082e56cd127c971f74456214d1347259b7300e35d3e20 |
|
MD5 | 65e5a3f9af811264a3d3d64cc766cc91 |
|
BLAKE2b-256 | 87315f75aced8e0f2c63b4a76b530faf1f395fc69ee071966d87cc36bc987093 |
File details
Details for the file blake3-0.2.0-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.whl
.
File metadata
- Download URL: blake3-0.2.0-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.whl
- Upload date:
- Size: 952.6 kB
- Tags: CPython 3.7m, manylinux: glibc 2.5+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.8.11
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 01e74e01b8b7ff404d547db6398b61ccb03580afb6e92617161cbf239b298927 |
|
MD5 | d2cbfc7a91ce476cc4447e33a016e121 |
|
BLAKE2b-256 | 64c67d148f3d078e9735a226197c2a1f75f84729085e94edb0bff1b8234aae5d |
File details
Details for the file blake3-0.2.0-cp37-cp37m-macosx_10_7_x86_64.whl
.
File metadata
- Download URL: blake3-0.2.0-cp37-cp37m-macosx_10_7_x86_64.whl
- Upload date:
- Size: 287.0 kB
- Tags: CPython 3.7m, macOS 10.7+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.8.11
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0fbfbba6a38c38e2cd03f6070bf27f338ea9c529cf1e4c9f3cc885d04bb4d5ba |
|
MD5 | ab013ed2904ffe4a08545ed257610786 |
|
BLAKE2b-256 | 278606989fb04bc8f8d2bf6eae5c0b39d412a83e2cfb968be7a2de61aa0be1e6 |
File details
Details for the file blake3-0.2.0-cp36-none-win_amd64.whl
.
File metadata
- Download URL: blake3-0.2.0-cp36-none-win_amd64.whl
- Upload date:
- Size: 178.3 kB
- Tags: CPython 3.6, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.8.11
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b064ca79b8caa607ef6d1d51773956556df98105aaf835ad9ff5dbd7af3ae3cd |
|
MD5 | 0dba63436424fb88cf9afad549284d1f |
|
BLAKE2b-256 | c9cd97980cb72fdb14333aac9dd26f140400a1ae9f92843c4af936925a04ba4c |
File details
Details for the file blake3-0.2.0-cp36-none-win32.whl
.
File metadata
- Download URL: blake3-0.2.0-cp36-none-win32.whl
- Upload date:
- Size: 193.8 kB
- Tags: CPython 3.6, Windows x86
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.8.11
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 39688c5b3024a51549a5fa0a7d87edababbea60b28f8756d1d2ff5376ee6fd73 |
|
MD5 | bb226c501fc28129b997356e6aebdc7b |
|
BLAKE2b-256 | ff0d0447b980af4eac3b131ad8838acc989e89477f68cf8b6018ae05445d133a |
File details
Details for the file blake3-0.2.0-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.whl
.
File metadata
- Download URL: blake3-0.2.0-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.whl
- Upload date:
- Size: 952.1 kB
- Tags: CPython 3.6m, manylinux: glibc 2.5+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.8.11
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | da158297ed4735f7cf6b1b677854772ccee028726fd5c7c40cf6d2a1b2b898fa |
|
MD5 | 4b7eaf5f8316a7829bbebaa2094fb056 |
|
BLAKE2b-256 | 382f85e5c7117c9d3ba5a14c2c8f40f20b15df015678fc6789f3649d41f0137b |
File details
Details for the file blake3-0.2.0-cp36-cp36m-macosx_10_7_x86_64.whl
.
File metadata
- Download URL: blake3-0.2.0-cp36-cp36m-macosx_10_7_x86_64.whl
- Upload date:
- Size: 286.8 kB
- Tags: CPython 3.6m, macOS 10.7+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.8.11
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 221a9b80ab1178fe7675b1b44daa77724715768351603fe6dc3ddd671a4b2310 |
|
MD5 | b4e2bc655961b9d1d706d867f1836cf1 |
|
BLAKE2b-256 | d43a0fb7c2e1dd636d06715f0a9236e0d280b56db59b67ebaf26f648cd5c77fb |