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. 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" * KEY_LEN
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.
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).digest()
# 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).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 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.7.tar.gz
.
File metadata
- Download URL: blake3-0.1.7.tar.gz
- Upload date:
- Size: 32.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 99d688bd1b673de332a2927665e0e82eefae79b18b7c03564c5907d716e473b8 |
|
MD5 | 1b9c37de1b08c898d75b4348e5a77655 |
|
BLAKE2b-256 | b13daf8bf3a3207a36e84ba25b96e79bdcdbc764f895a6f0e7680fcc70e1724a |
File details
Details for the file blake3-0.1.7-cp38-none-win_amd64.whl
.
File metadata
- Download URL: blake3-0.1.7-cp38-none-win_amd64.whl
- Upload date:
- Size: 179.3 kB
- Tags: CPython 3.8, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 93e8094c9fd4112d8c0c62e487d027f3c534fde903893788875c79e1c09b8c6d |
|
MD5 | a558fcc3c52b8ecde186dda3127755a4 |
|
BLAKE2b-256 | 0b5ec8aa322c00f94173c0024fa78003bac160bcd781ce1dbbee331c5dbf971e |
File details
Details for the file blake3-0.1.7-cp38-none-win32.whl
.
File metadata
- Download URL: blake3-0.1.7-cp38-none-win32.whl
- Upload date:
- Size: 185.8 kB
- Tags: CPython 3.8, Windows x86
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 38f9225c4b527d3f34a884e17a3fb59c6a4f322a3051344be7de2ab2e5ccc640 |
|
MD5 | 6400e7dfd0ecfd62aa7beb98faede52e |
|
BLAKE2b-256 | 7cb0826a67e73402d0cd0107f59db6888a1d399cccfabb5174eca9c2056f2ede |
File details
Details for the file blake3-0.1.7-cp38-cp38-manylinux1_x86_64.whl
.
File metadata
- Download URL: blake3-0.1.7-cp38-cp38-manylinux1_x86_64.whl
- Upload date:
- Size: 871.5 kB
- Tags: CPython 3.8
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cc459bde85fce01b1b58b815d0c1df87b692cc8a434e70debe2f1a3737cf2a07 |
|
MD5 | aabf2ad0b9eee6fda9dceec32c300eb6 |
|
BLAKE2b-256 | e278452ef34f6473932b4823bea1615fe2a24834868d59b2ab76fdb908a03c6c |
File details
Details for the file blake3-0.1.7-cp38-cp38-macosx_10_7_x86_64.whl
.
File metadata
- Download URL: blake3-0.1.7-cp38-cp38-macosx_10_7_x86_64.whl
- Upload date:
- Size: 233.8 kB
- Tags: CPython 3.8, macOS 10.7+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1f0a0b444f653e28298c1aea73d7604597366a29ffd2876972138bcb0ea8be33 |
|
MD5 | 765cc014a78f5f89287270a3c159dbf0 |
|
BLAKE2b-256 | 9209bc251678d576a2b680972b00ffc34d90dbee729667b23588c8f8dfa84c24 |
File details
Details for the file blake3-0.1.7-cp37-none-win_amd64.whl
.
File metadata
- Download URL: blake3-0.1.7-cp37-none-win_amd64.whl
- Upload date:
- Size: 179.3 kB
- Tags: CPython 3.7, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e78d92c3d1cec69ccec7d9c47222c4037459cc982725d5a553b598c83d34c325 |
|
MD5 | 5b82d8be333a2ee995a74f72c68b1e34 |
|
BLAKE2b-256 | 4c400cf2f23e03f245e360d933dc09e41532dc253feb2b4ee37869f9dee0e20c |
File details
Details for the file blake3-0.1.7-cp37-none-win32.whl
.
File metadata
- Download URL: blake3-0.1.7-cp37-none-win32.whl
- Upload date:
- Size: 185.8 kB
- Tags: CPython 3.7, Windows x86
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3ca1181c7427bc532c7989b96030f5684f4d946e08bd0ee72a989dd56bed83c3 |
|
MD5 | cf3823f8f2bd23d8da8d01573928cbb3 |
|
BLAKE2b-256 | 14507e9f2f8847ec12125055aa61b5a0107bffbb036fb3bfa100b9ad81b9de74 |
File details
Details for the file blake3-0.1.7-cp37-cp37m-manylinux1_x86_64.whl
.
File metadata
- Download URL: blake3-0.1.7-cp37-cp37m-manylinux1_x86_64.whl
- Upload date:
- Size: 871.5 kB
- Tags: CPython 3.7m
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f968142a5b5de1d97eaacfaaaa26e81e51ca97b1b8b7ce88710969a310f4570d |
|
MD5 | 5429e69bbacea40eb7857c25d1b793cf |
|
BLAKE2b-256 | ca77d779e162845abd7d30bd499b61b081423b6dad6c36b4a5763eccee561e25 |
File details
Details for the file blake3-0.1.7-cp37-cp37m-macosx_10_7_x86_64.whl
.
File metadata
- Download URL: blake3-0.1.7-cp37-cp37m-macosx_10_7_x86_64.whl
- Upload date:
- Size: 233.8 kB
- Tags: CPython 3.7m, macOS 10.7+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1c7289fedf0ac714812fa743ae2dd0fe522cc968b0adf5d1e7529ec639cf82c0 |
|
MD5 | 239f736723a9e2814e1788e66c5e24e2 |
|
BLAKE2b-256 | a69992bceb1599e1edc76e5dc67b668a143a3d1ceb436ffd9ea7b1e69465b7e9 |
File details
Details for the file blake3-0.1.7-cp36-none-win_amd64.whl
.
File metadata
- Download URL: blake3-0.1.7-cp36-none-win_amd64.whl
- Upload date:
- Size: 179.6 kB
- Tags: CPython 3.6, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c118ad0e3ea4af907e1eac8e90353640b7e4433446faefdd3c1b5b8a8481e21c |
|
MD5 | 129e7542f536883e3f4351dbfd9b8784 |
|
BLAKE2b-256 | 40d9e17f27827bb20eb2c7c41216d55c32dee9e841dd9d6fdff07e6675debe92 |
File details
Details for the file blake3-0.1.7-cp36-none-win32.whl
.
File metadata
- Download URL: blake3-0.1.7-cp36-none-win32.whl
- Upload date:
- Size: 186.0 kB
- Tags: CPython 3.6, Windows x86
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6eaa5d5df6f8562d2ecbb4e17c1e2945be369afdf9969676e50c2d721b5f9757 |
|
MD5 | 55d20a1d42b9fa7b8261c3f0af8a71c8 |
|
BLAKE2b-256 | e3a9b60c05953e5b070fd4cd6ec4a0384ad26dac446c51eaeb810bbb57dc747e |
File details
Details for the file blake3-0.1.7-cp36-cp36m-manylinux1_x86_64.whl
.
File metadata
- Download URL: blake3-0.1.7-cp36-cp36m-manylinux1_x86_64.whl
- Upload date:
- Size: 871.8 kB
- Tags: CPython 3.6m
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c54c8a5833cde8ec83aa2fda1510f53db24ffb605f17cc20170e4c34831ee997 |
|
MD5 | 66e447168cc39cf593deccf94999fc71 |
|
BLAKE2b-256 | f6400dffc993fc0dfd097a4755ea398d37fa17fec68456ab4788fa2853eb165b |
File details
Details for the file blake3-0.1.7-cp36-cp36m-macosx_10_7_x86_64.whl
.
File metadata
- Download URL: blake3-0.1.7-cp36-cp36m-macosx_10_7_x86_64.whl
- Upload date:
- Size: 234.0 kB
- Tags: CPython 3.6m, macOS 10.7+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 540ce72c2866d3d058fb70f97a4bd2552a6ad26cfbf3121336cfc98dbad9f52b |
|
MD5 | 8919ad023879d141b88e7f0984b09ffe |
|
BLAKE2b-256 | affc2927fb650f51708c734f738095a4b230178d36bdf19012fd1d15e5804437 |
File details
Details for the file blake3-0.1.7-cp35-none-win_amd64.whl
.
File metadata
- Download URL: blake3-0.1.7-cp35-none-win_amd64.whl
- Upload date:
- Size: 179.3 kB
- Tags: CPython 3.5, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d41c61b4c64f324ddcffe8c02d7f34235f60e50b6e7686212e97b7e5640dc5c4 |
|
MD5 | 0e866023e2e33d26ed01c37816a00932 |
|
BLAKE2b-256 | 9fc839bbc8861221313ec4c55999e8cb366ff3328e4e869619f18895e85368b9 |
File details
Details for the file blake3-0.1.7-cp35-none-win32.whl
.
File metadata
- Download URL: blake3-0.1.7-cp35-none-win32.whl
- Upload date:
- Size: 186.0 kB
- Tags: CPython 3.5, Windows x86
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fe9b36f875bb37bd6afa5cce81eef889758c494dd5bdff14879e49bc04a8cda9 |
|
MD5 | ab019a08e1d46b5c62b9b77c89e3107a |
|
BLAKE2b-256 | 72822e03f0e8b5439e0d8f1a3085d5e4a26ed2b667757d29be17d6806955e3c5 |
File details
Details for the file blake3-0.1.7-cp35-cp35m-manylinux1_x86_64.whl
.
File metadata
- Download URL: blake3-0.1.7-cp35-cp35m-manylinux1_x86_64.whl
- Upload date:
- Size: 870.8 kB
- Tags: CPython 3.5m
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ef7c13fa5b42af9864d6f5a5950469a0de4703a18549b2aa47a051fe156b8f59 |
|
MD5 | 4e1119fe7add26ad12c8fc4e225fe46e |
|
BLAKE2b-256 | a480ff04d8e80a8712eba2ae89802aa1a738cc5e9bcaa182842cb15310c958ca |
File details
Details for the file blake3-0.1.7-cp35-cp35m-macosx_10_7_x86_64.whl
.
File metadata
- Download URL: blake3-0.1.7-cp35-cp35m-macosx_10_7_x86_64.whl
- Upload date:
- Size: 233.1 kB
- Tags: CPython 3.5m, macOS 10.7+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d97572076d2a87a454f518b6a025fda75af2a098f1f73d6c7ce7a43704f02669 |
|
MD5 | 232fade69251b5ea03de11468c6561f2 |
|
BLAKE2b-256 | 7cec9006ef36657146d3f79ec3652be7cb9fc396dbd8c58008d339d0ebaf7255 |