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.
Caution: This is a brand new library. Please expect some build issues on platforms not covered by CI testing. If you're using this for anything important, please test your code against known-good outputs. See also the soundness concerns below.
Example
from blake3 import blake3, KEY_LEN, OUT_LEN
# Hash some input all at once.
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" * KEY_LEN
message = b"a message to authenticate"
mac = blake3(message, key=zero_key)
# Use the key derivation mode, which takes a context string. Context
# strings should be hardcoded, globally unique, and application-specific.
example_context = "blake3-py 2020-03-04 11:13:10 example context"
key_material = b"some super secret key material"
derived_key = blake3(key_material, context=example_context)
# Extendable output. The default OUT_LEN is 32 bytes.
extended = blake3(b"foo").digest(length=100)
assert extended[:OUT_LEN] == 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)
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, so
most users do not need a Rust toolchain. If you're building the source
distribution, or if a binary wheel isn't available for your environment,
you'll need nightly Rust installed. (If you use
rustup, it will read the rust-toolchain
file in
this project and use the nightly toolchain automatically.)
Thread Safety and Soundness
This wrapper is not currently thread-safe. Like the hash implementations
in the Python standard library, we release the GIL during update
, to
avoid blocking the entire process. However, that means that calling the
update
method on the same object from multiple threads at the same
time is undefined behavior. We could solve this by putting a Mutex
inside the wrapper type, but I'd like to get some expert advice about
the best practice here first.
A deeper problem is that another thread might mutate a bytearray
while
we're hashing it, and while our Rust code is treating it as a &[u8]
.
That violates Rust's aliasing guarantees and is also technically
undefined behavior. However, the only possible way to solve this while
still supporting bytearray
would be to retain the GIL. Again, I'm in
need of expert advice.
These concerns are more theoretical than practical, however. If you're racing to update a hasher, or racing to hash a buffer while it's being written to, the result is inherently nondeterministic. That's almost certainly a bug in your program, whether or not it's technically sound.
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.1.4.tar.gz
.
File metadata
- Download URL: blake3-0.1.4.tar.gz
- Upload date:
- Size: 30.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.44.1 CPython/3.8.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e03cabf07e23a0a2118ddfdeac066cfaa4ceed7a11b4bf581680831e454924f3 |
|
MD5 | c519d4ae464d4186bfc6157b2090db26 |
|
BLAKE2b-256 | c34006e065962fb7f37493492b4daaa2c4cd42c0ec9a60cebfb955af985b9872 |
File details
Details for the file blake3-0.1.4-cp38-none-win_amd64.whl
.
File metadata
- Download URL: blake3-0.1.4-cp38-none-win_amd64.whl
- Upload date:
- Size: 159.3 kB
- Tags: CPython 3.8, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.44.1 CPython/3.8.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ef3c9bed389a93da32deb2933aaca0eda9f5e14f24dc7eb3c65aaf20c9d35b70 |
|
MD5 | ac63d82e7d95ab8335187df5d3ade293 |
|
BLAKE2b-256 | db74298e2b923e0a79991eca736eba1544e0adf9f0a1681fa08a6aaaf8ae68b1 |
File details
Details for the file blake3-0.1.4-cp38-none-win32.whl
.
File metadata
- Download URL: blake3-0.1.4-cp38-none-win32.whl
- Upload date:
- Size: 172.4 kB
- Tags: CPython 3.8, Windows x86
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.44.1 CPython/3.8.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d30ae04e85156f978e5077cfcf9044ca705e018634c72534f6e8325a5ea8a597 |
|
MD5 | c173a0da028d3f52f06e5610af1e387d |
|
BLAKE2b-256 | 05dbcd8b1408bf8e50398b1ad5d9e82f57ee14c4b1b7c305966148e0f072d8e8 |
File details
Details for the file blake3-0.1.4-cp38-cp38-manylinux1_x86_64.whl
.
File metadata
- Download URL: blake3-0.1.4-cp38-cp38-manylinux1_x86_64.whl
- Upload date:
- Size: 766.4 kB
- Tags: CPython 3.8
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.44.1 CPython/3.8.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f2c24e889ddff8186f362fdf792e20006553db88708dec5b72706f3c8a7d5f27 |
|
MD5 | 599cb5d773f6140b078b11d4386c2455 |
|
BLAKE2b-256 | d7d94740acd52573498efa4beddb98b3e4ecfe6f4a8c425e8c618fb2092cd802 |
File details
Details for the file blake3-0.1.4-cp38-cp38-macosx_10_7_x86_64.whl
.
File metadata
- Download URL: blake3-0.1.4-cp38-cp38-macosx_10_7_x86_64.whl
- Upload date:
- Size: 216.3 kB
- Tags: CPython 3.8, macOS 10.7+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.44.1 CPython/3.8.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fd2f0653d02aace3e8219bf03dd26f7f23c7834d230b82aceceffab007237a48 |
|
MD5 | 972ef112069a09073e6bc36fa78a4b33 |
|
BLAKE2b-256 | a2f99b04720e1e2f0dfde7c28415a7172f6ef164f23768a009295e1e6fb2f104 |
File details
Details for the file blake3-0.1.4-cp37-none-win_amd64.whl
.
File metadata
- Download URL: blake3-0.1.4-cp37-none-win_amd64.whl
- Upload date:
- Size: 159.0 kB
- Tags: CPython 3.7, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.44.1 CPython/3.8.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b0c3d0bb8cd36c4e2e5dfd9ed15b24556409148758e7972e5051704d3c816b39 |
|
MD5 | fef59e880ab8df85598682dd062d7020 |
|
BLAKE2b-256 | 800c25e35d793a447cd2ed4e9d30c838ee3ab4bc8426d31ec808904d3dabb6fb |
File details
Details for the file blake3-0.1.4-cp37-none-win32.whl
.
File metadata
- Download URL: blake3-0.1.4-cp37-none-win32.whl
- Upload date:
- Size: 172.3 kB
- Tags: CPython 3.7, Windows x86
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.44.1 CPython/3.8.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c7e7cdc1057fc424dbbc6100110d94e427175774193e3986ea7dfc57df95ccbc |
|
MD5 | 93979c73c06f6843178b16a84c59eb89 |
|
BLAKE2b-256 | 347ca20be2767ab77aee83b8a5169cb45302a271594b09eb1ce03378f3d92b29 |
File details
Details for the file blake3-0.1.4-cp37-cp37m-manylinux1_x86_64.whl
.
File metadata
- Download URL: blake3-0.1.4-cp37-cp37m-manylinux1_x86_64.whl
- Upload date:
- Size: 766.5 kB
- Tags: CPython 3.7m
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.44.1 CPython/3.8.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 06a436b8254ef20c4f54dba61981be4378dde1a61c7e09e167c8e987ea38ac70 |
|
MD5 | afdf4abd7479865feba673aa312eb087 |
|
BLAKE2b-256 | e78400f0722129912e5df105e1ea79f218377b524d46a52075c22f7da042d71e |
File details
Details for the file blake3-0.1.4-cp37-cp37m-macosx_10_7_x86_64.whl
.
File metadata
- Download URL: blake3-0.1.4-cp37-cp37m-macosx_10_7_x86_64.whl
- Upload date:
- Size: 216.4 kB
- Tags: CPython 3.7m, macOS 10.7+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.44.1 CPython/3.8.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 17ec0955843b3005ca18b3b99dc8f289b7ccc9ed8a7ab4a4629b7c2ebfb605ca |
|
MD5 | 6c4a46befa15b7d7b14c2cbcffe2827a |
|
BLAKE2b-256 | 8420f6b3c5318a6ba97ca3ab306ad5d19aa128067f0f88c85bd91da74f93818f |
File details
Details for the file blake3-0.1.4-cp36-none-win_amd64.whl
.
File metadata
- Download URL: blake3-0.1.4-cp36-none-win_amd64.whl
- Upload date:
- Size: 159.2 kB
- Tags: CPython 3.6, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.44.1 CPython/3.8.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ab37a2fb0017d332fa8624c699918ea65f3f196db97f87b78d91fea1dffb2e17 |
|
MD5 | 6612ddfa20e7a1316659d503d8a6a49a |
|
BLAKE2b-256 | ae1416902042fefd3a8ebe695c8cb8d3ce793dd8b5e05f2f19b30198eff65c4c |
File details
Details for the file blake3-0.1.4-cp36-none-win32.whl
.
File metadata
- Download URL: blake3-0.1.4-cp36-none-win32.whl
- Upload date:
- Size: 172.6 kB
- Tags: CPython 3.6, Windows x86
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.44.1 CPython/3.8.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fa96d87155648b36b0bcfb72fd9fe533f98a38e7a8b62b9c5674173177a53384 |
|
MD5 | 4e2fbba36c2d03492e32b722f3023489 |
|
BLAKE2b-256 | 09ea095e9795761ee5eb8a4259a8767673b502efcb55450e62def96b614ef911 |
File details
Details for the file blake3-0.1.4-cp36-cp36m-manylinux1_x86_64.whl
.
File metadata
- Download URL: blake3-0.1.4-cp36-cp36m-manylinux1_x86_64.whl
- Upload date:
- Size: 766.7 kB
- Tags: CPython 3.6m
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.44.1 CPython/3.8.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7d2e7f99b9dc40828fdbc8f2ea4dc12b1bd93faceecea3a68a87be1b56683122 |
|
MD5 | 2aacabd56cf2d4624bb8b92b5266afa5 |
|
BLAKE2b-256 | f69d82673b3a039c190b7cc20591ad1f1691be134787ce240f4ee427334f4cca |
File details
Details for the file blake3-0.1.4-cp36-cp36m-macosx_10_7_x86_64.whl
.
File metadata
- Download URL: blake3-0.1.4-cp36-cp36m-macosx_10_7_x86_64.whl
- Upload date:
- Size: 216.6 kB
- Tags: CPython 3.6m, macOS 10.7+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.44.1 CPython/3.8.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | edcdf51681118b3298fc6b28c464a4b188cb9bc4f2bfccf642b2d48090dc6376 |
|
MD5 | 2728d490c17d94268c44d0679d1b8930 |
|
BLAKE2b-256 | 80a7227b4f8b3108951d32fbd3e8cb7eee59da1c7abf26a412a46e23db12867b |
File details
Details for the file blake3-0.1.4-cp35-none-win_amd64.whl
.
File metadata
- Download URL: blake3-0.1.4-cp35-none-win_amd64.whl
- Upload date:
- Size: 159.6 kB
- Tags: CPython 3.5, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.44.1 CPython/3.8.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c146909a9ab411783e4954870cc4d1e6702881f7bbd8a303c983cdc3e2449aa5 |
|
MD5 | fd10757aaef0a5e4ed17e8814f6e89fd |
|
BLAKE2b-256 | 829823a6169fe377271dc177b307ff53b89f9a36bb4e15d80c3b60d8b1792c85 |
File details
Details for the file blake3-0.1.4-cp35-none-win32.whl
.
File metadata
- Download URL: blake3-0.1.4-cp35-none-win32.whl
- Upload date:
- Size: 172.7 kB
- Tags: CPython 3.5, Windows x86
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.44.1 CPython/3.8.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6040ffd38847f8c37ba9653b369e29bc3e2e9fb26d18deda944e1ff46c060aa8 |
|
MD5 | 847aeac1eebba7e959818a52678869d2 |
|
BLAKE2b-256 | 27c2e45d9c37a2e6a4bdb58a31a8f77370eefe022cb67e03ae409a60980c257b |
File details
Details for the file blake3-0.1.4-cp35-cp35m-manylinux1_x86_64.whl
.
File metadata
- Download URL: blake3-0.1.4-cp35-cp35m-manylinux1_x86_64.whl
- Upload date:
- Size: 766.4 kB
- Tags: CPython 3.5m
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.44.1 CPython/3.8.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6adf481f0b70db744a28ca334b823ccc0ad2ef0982f5a17a916efbcb1d73f0bc |
|
MD5 | 64daad47ad5de7704634b79d50492c89 |
|
BLAKE2b-256 | 8d75a4c572fe059d5a1ca9e7e4304a5a3919a48cbeedadc94edebc7aba50938d |
File details
Details for the file blake3-0.1.4-cp35-cp35m-macosx_10_7_x86_64.whl
.
File metadata
- Download URL: blake3-0.1.4-cp35-cp35m-macosx_10_7_x86_64.whl
- Upload date:
- Size: 216.4 kB
- Tags: CPython 3.5m, macOS 10.7+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.44.1 CPython/3.8.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 37abcb7addc0965f8b720f0956055aee9485d8d092585532b560a634831aa68f |
|
MD5 | 8b1a75be35450fd4c61a76ea95dd3268 |
|
BLAKE2b-256 | 1da094d6a249e222f3e7484b40eec8f06c3ca853840f127cfe27134098265ed4 |