Skip to main content

Python bindings for the Rust blake3 crate

Project description

blake3-py Actions Status PyPI version

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. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

blake3-0.1.6.tar.gz (31.2 kB view details)

Uploaded Source

Built Distributions

blake3-0.1.6-cp38-none-win_amd64.whl (168.8 kB view details)

Uploaded CPython 3.8 Windows x86-64

blake3-0.1.6-cp38-none-win32.whl (178.7 kB view details)

Uploaded CPython 3.8 Windows x86

blake3-0.1.6-cp38-cp38-manylinux1_x86_64.whl (860.9 kB view details)

Uploaded CPython 3.8

blake3-0.1.6-cp38-cp38-macosx_10_7_x86_64.whl (226.1 kB view details)

Uploaded CPython 3.8 macOS 10.7+ x86-64

blake3-0.1.6-cp37-none-win_amd64.whl (168.8 kB view details)

Uploaded CPython 3.7 Windows x86-64

blake3-0.1.6-cp37-none-win32.whl (178.7 kB view details)

Uploaded CPython 3.7 Windows x86

blake3-0.1.6-cp37-cp37m-manylinux1_x86_64.whl (860.9 kB view details)

Uploaded CPython 3.7m

blake3-0.1.6-cp37-cp37m-macosx_10_7_x86_64.whl (226.1 kB view details)

Uploaded CPython 3.7m macOS 10.7+ x86-64

blake3-0.1.6-cp36-none-win_amd64.whl (169.1 kB view details)

Uploaded CPython 3.6 Windows x86-64

blake3-0.1.6-cp36-none-win32.whl (179.0 kB view details)

Uploaded CPython 3.6 Windows x86

blake3-0.1.6-cp36-cp36m-manylinux1_x86_64.whl (860.9 kB view details)

Uploaded CPython 3.6m

blake3-0.1.6-cp36-cp36m-macosx_10_7_x86_64.whl (226.2 kB view details)

Uploaded CPython 3.6m macOS 10.7+ x86-64

blake3-0.1.6-cp35-none-win_amd64.whl (168.8 kB view details)

Uploaded CPython 3.5 Windows x86-64

blake3-0.1.6-cp35-none-win32.whl (178.6 kB view details)

Uploaded CPython 3.5 Windows x86

blake3-0.1.6-cp35-cp35m-manylinux1_x86_64.whl (860.1 kB view details)

Uploaded CPython 3.5m

blake3-0.1.6-cp35-cp35m-macosx_10_7_x86_64.whl (225.6 kB view details)

Uploaded CPython 3.5m macOS 10.7+ x86-64

File details

Details for the file blake3-0.1.6.tar.gz.

File metadata

  • Download URL: blake3-0.1.6.tar.gz
  • Upload date:
  • Size: 31.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/41.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.3

File hashes

Hashes for blake3-0.1.6.tar.gz
Algorithm Hash digest
SHA256 5049f8e8286672dc6bb384b7b5c81a5ca21743b198e3c5874147e1acefa56b91
MD5 78e9e0f99880c4eed906fe68a19e0ccc
BLAKE2b-256 9b4d765249a90f5db66e2bbefa41d413304c3a187c6e777c522fea29f96bc836

See more details on using hashes here.

File details

Details for the file blake3-0.1.6-cp38-none-win_amd64.whl.

File metadata

  • Download URL: blake3-0.1.6-cp38-none-win_amd64.whl
  • Upload date:
  • Size: 168.8 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/41.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.3

File hashes

Hashes for blake3-0.1.6-cp38-none-win_amd64.whl
Algorithm Hash digest
SHA256 c8b1e458afea16b8c0da53b181236688ea1fa68e35e96264de7fac8d8489d490
MD5 99a7f8d122552d54991052a0f1053d5d
BLAKE2b-256 81ed082fca412eea9a3a2aa55735e7078e012c39b9ccb760fb2ab50cd9076045

See more details on using hashes here.

File details

Details for the file blake3-0.1.6-cp38-none-win32.whl.

File metadata

  • Download URL: blake3-0.1.6-cp38-none-win32.whl
  • Upload date:
  • Size: 178.7 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/41.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.3

File hashes

Hashes for blake3-0.1.6-cp38-none-win32.whl
Algorithm Hash digest
SHA256 749ea797bb4b99c1f84d63c027295f70b41f6c1766dd822092d10fa9712fed44
MD5 d9bc9971842ee3e2b1b60b57c4f59505
BLAKE2b-256 c0cea7120584d6111b27fe1a1e238c41aaca2d9fb7b629f6ee3e7c44b6fbb476

See more details on using hashes here.

File details

Details for the file blake3-0.1.6-cp38-cp38-manylinux1_x86_64.whl.

File metadata

  • Download URL: blake3-0.1.6-cp38-cp38-manylinux1_x86_64.whl
  • Upload date:
  • Size: 860.9 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/41.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.3

File hashes

Hashes for blake3-0.1.6-cp38-cp38-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 c2a44219a480251d7b2cc49af25cb69f377e988a897a070d5513a9c1d5aa0d80
MD5 14d4a190552a3c8afe77fe7c580c097c
BLAKE2b-256 58e488603a82928869103f330703efc7b118df11d3c91fc887c85b209c548a73

See more details on using hashes here.

File details

Details for the file blake3-0.1.6-cp38-cp38-macosx_10_7_x86_64.whl.

File metadata

  • Download URL: blake3-0.1.6-cp38-cp38-macosx_10_7_x86_64.whl
  • Upload date:
  • Size: 226.1 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/41.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.3

File hashes

Hashes for blake3-0.1.6-cp38-cp38-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 08459e4572a83fc5eebc38f6cfd0e0991089b381417ee605d675ce7a13c41e5f
MD5 4f456057ea33300fddd962709d30dcd6
BLAKE2b-256 3058b0cada764963c888db0cbf419046fb67f4455212fbdb096025ec6a9206bc

See more details on using hashes here.

File details

Details for the file blake3-0.1.6-cp37-none-win_amd64.whl.

File metadata

  • Download URL: blake3-0.1.6-cp37-none-win_amd64.whl
  • Upload date:
  • Size: 168.8 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/41.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.3

File hashes

Hashes for blake3-0.1.6-cp37-none-win_amd64.whl
Algorithm Hash digest
SHA256 b85d3c87379cb75a143f9cdbb8fbca6bd369afc357c3fc938fcfd877a1785bca
MD5 768971e3223923cbdaa3442c0c2b690e
BLAKE2b-256 5a1dda3e46a3824616c65df2b15b7037af5eb39c23f51558f023d3d51dce9b3e

See more details on using hashes here.

File details

Details for the file blake3-0.1.6-cp37-none-win32.whl.

File metadata

  • Download URL: blake3-0.1.6-cp37-none-win32.whl
  • Upload date:
  • Size: 178.7 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/41.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.3

File hashes

Hashes for blake3-0.1.6-cp37-none-win32.whl
Algorithm Hash digest
SHA256 21f229f62bd716b89228ef006623e1d23fc6be4fcd870a017f6256424e5eb945
MD5 9084dc06c005dd8189ea216c6362ddec
BLAKE2b-256 ac6bec85f6c944dc60ae60aa726a24fa445fd4d8f8775ee76236d3f3df4ac450

See more details on using hashes here.

File details

Details for the file blake3-0.1.6-cp37-cp37m-manylinux1_x86_64.whl.

File metadata

  • Download URL: blake3-0.1.6-cp37-cp37m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 860.9 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/41.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.3

File hashes

Hashes for blake3-0.1.6-cp37-cp37m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 793e84fb9336b1196cf63efdc62145a1ad5be1f60083caca9394afffb5eea2cf
MD5 76bc99e3672edce2e81e8c5b52d4baae
BLAKE2b-256 09fd0ad1105eb42ef178c494d9199b64e031d75ae6b685e0b804490837e017df

See more details on using hashes here.

File details

Details for the file blake3-0.1.6-cp37-cp37m-macosx_10_7_x86_64.whl.

File metadata

  • Download URL: blake3-0.1.6-cp37-cp37m-macosx_10_7_x86_64.whl
  • Upload date:
  • Size: 226.1 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/41.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.3

File hashes

Hashes for blake3-0.1.6-cp37-cp37m-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 1db4db50ae8b7d50925c432cda0d98315708fd2f233df133dc8b76b11c0ff7e1
MD5 fd0aca2a1b3657bb62b3cd5e01adb7e5
BLAKE2b-256 ef6c26b89c8868d4e28e14cd6a1e3ccd1eb309cfd2a934075cf2ae3b3fdcaf99

See more details on using hashes here.

File details

Details for the file blake3-0.1.6-cp36-none-win_amd64.whl.

File metadata

  • Download URL: blake3-0.1.6-cp36-none-win_amd64.whl
  • Upload date:
  • Size: 169.1 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/41.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.3

File hashes

Hashes for blake3-0.1.6-cp36-none-win_amd64.whl
Algorithm Hash digest
SHA256 6864a1fddb5d2bf216fa616cf5fd4289e78ea27415a7e77a007bf518101e6330
MD5 ac6af79cdf2775c7265811e8dd8020ef
BLAKE2b-256 27ad05024f33f31b0cefdf839ff4bea3298f93114ceb19e6d2f4dfefe3a7f511

See more details on using hashes here.

File details

Details for the file blake3-0.1.6-cp36-none-win32.whl.

File metadata

  • Download URL: blake3-0.1.6-cp36-none-win32.whl
  • Upload date:
  • Size: 179.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/41.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.3

File hashes

Hashes for blake3-0.1.6-cp36-none-win32.whl
Algorithm Hash digest
SHA256 9d49c6963a2301e6f746326b0fc3c8465004c3f1e43236ecba9cb08b345cc00c
MD5 978a7b24a6d4c8a43469de9871d6ebd0
BLAKE2b-256 20048e73c1b2efb97f0ad7e57eace81b62b4d2481a57399dd1484441b6113101

See more details on using hashes here.

File details

Details for the file blake3-0.1.6-cp36-cp36m-manylinux1_x86_64.whl.

File metadata

  • Download URL: blake3-0.1.6-cp36-cp36m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 860.9 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/41.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.3

File hashes

Hashes for blake3-0.1.6-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 e6b3d2916b06946577e13757aff6b08d384462487f2e8e31f77034b6883e070e
MD5 224a4f9b5ed62f8afb8e4c580d48fe4c
BLAKE2b-256 fc60d9c079215117bc2793c11b2e2317a3908ace2847cb049d9a8e260356cccc

See more details on using hashes here.

File details

Details for the file blake3-0.1.6-cp36-cp36m-macosx_10_7_x86_64.whl.

File metadata

  • Download URL: blake3-0.1.6-cp36-cp36m-macosx_10_7_x86_64.whl
  • Upload date:
  • Size: 226.2 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/41.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.3

File hashes

Hashes for blake3-0.1.6-cp36-cp36m-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 fc2ed24dda25c9b3a8c34845ee155728c5e6c6fe77ccdff7e23b4eedc1398426
MD5 ba7606aae68841f3247d6b2508755dc5
BLAKE2b-256 2754830dc8f0c03c9b977511c9b5f4e105584db84bce98432abd2d61e5346984

See more details on using hashes here.

File details

Details for the file blake3-0.1.6-cp35-none-win_amd64.whl.

File metadata

  • Download URL: blake3-0.1.6-cp35-none-win_amd64.whl
  • Upload date:
  • Size: 168.8 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/41.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.3

File hashes

Hashes for blake3-0.1.6-cp35-none-win_amd64.whl
Algorithm Hash digest
SHA256 2092984a3c6562c032c37b2c1a48a923467a471de23504f21f7d6e2529aa878a
MD5 cd05d47bb6f788e150174f292dbddb49
BLAKE2b-256 7a6465b6b57b7c696a8e04f537ef3626d3de080017019a974ff86207c255aa65

See more details on using hashes here.

File details

Details for the file blake3-0.1.6-cp35-none-win32.whl.

File metadata

  • Download URL: blake3-0.1.6-cp35-none-win32.whl
  • Upload date:
  • Size: 178.6 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/41.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.3

File hashes

Hashes for blake3-0.1.6-cp35-none-win32.whl
Algorithm Hash digest
SHA256 7f64988e8e3a7dfa34886d02d3b4f5dd9c271d44ff93c38adcc499d164bfe5e1
MD5 4cb8a48453e48bc4073513d7d9050a4c
BLAKE2b-256 fa85e2aafe58578b5fe61bbec3f1e5d7bfe30ecadf7dbb1b4b8b4e1628f3ae00

See more details on using hashes here.

File details

Details for the file blake3-0.1.6-cp35-cp35m-manylinux1_x86_64.whl.

File metadata

  • Download URL: blake3-0.1.6-cp35-cp35m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 860.1 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/41.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.3

File hashes

Hashes for blake3-0.1.6-cp35-cp35m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 602e7c859e168e6b7ee771201aa23efd8c0ba633b6c961577c17f6eea30b442a
MD5 d07352039cd7cef86f520efbde4459af
BLAKE2b-256 dde3e1645abbd5727707e5e21a75982a44c35dd95b8e23f75440f774f340860d

See more details on using hashes here.

File details

Details for the file blake3-0.1.6-cp35-cp35m-macosx_10_7_x86_64.whl.

File metadata

  • Download URL: blake3-0.1.6-cp35-cp35m-macosx_10_7_x86_64.whl
  • Upload date:
  • Size: 225.6 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/41.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.3

File hashes

Hashes for blake3-0.1.6-cp35-cp35m-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 29ac0ae479f7ec1d27f6c80f21ae3ca59e597908b32b8c19acf3a5c8cb471376
MD5 50f8c55a6bef98abbb3e4457c3972dde
BLAKE2b-256 f4ca054b29069cea5951e35dffae05af45c7f87fc5d04890a32d7ca83ea7b15f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page