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


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.5.tar.gz (31.1 kB view details)

Uploaded Source

Built Distributions

blake3-0.1.5-cp38-none-win_amd64.whl (161.1 kB view details)

Uploaded CPython 3.8 Windows x86-64

blake3-0.1.5-cp38-none-win32.whl (173.4 kB view details)

Uploaded CPython 3.8 Windows x86

blake3-0.1.5-cp38-cp38-manylinux1_x86_64.whl (774.6 kB view details)

Uploaded CPython 3.8

blake3-0.1.5-cp38-cp38-macosx_10_7_x86_64.whl (216.6 kB view details)

Uploaded CPython 3.8 macOS 10.7+ x86-64

blake3-0.1.5-cp37-none-win_amd64.whl (161.1 kB view details)

Uploaded CPython 3.7 Windows x86-64

blake3-0.1.5-cp37-none-win32.whl (173.3 kB view details)

Uploaded CPython 3.7 Windows x86

blake3-0.1.5-cp37-cp37m-manylinux1_x86_64.whl (774.6 kB view details)

Uploaded CPython 3.7m

blake3-0.1.5-cp37-cp37m-macosx_10_7_x86_64.whl (216.6 kB view details)

Uploaded CPython 3.7m macOS 10.7+ x86-64

blake3-0.1.5-cp36-none-win_amd64.whl (161.4 kB view details)

Uploaded CPython 3.6 Windows x86-64

blake3-0.1.5-cp36-none-win32.whl (173.6 kB view details)

Uploaded CPython 3.6 Windows x86

blake3-0.1.5-cp36-cp36m-manylinux1_x86_64.whl (774.7 kB view details)

Uploaded CPython 3.6m

blake3-0.1.5-cp36-cp36m-macosx_10_7_x86_64.whl (216.8 kB view details)

Uploaded CPython 3.6m macOS 10.7+ x86-64

blake3-0.1.5-cp35-none-win_amd64.whl (161.4 kB view details)

Uploaded CPython 3.5 Windows x86-64

blake3-0.1.5-cp35-none-win32.whl (173.6 kB view details)

Uploaded CPython 3.5 Windows x86

blake3-0.1.5-cp35-cp35m-manylinux1_x86_64.whl (774.7 kB view details)

Uploaded CPython 3.5m

blake3-0.1.5-cp35-cp35m-macosx_10_7_x86_64.whl (216.8 kB view details)

Uploaded CPython 3.5m macOS 10.7+ x86-64

File details

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

File metadata

  • Download URL: blake3-0.1.5.tar.gz
  • Upload date:
  • Size: 31.1 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.45.0 CPython/3.8.2

File hashes

Hashes for blake3-0.1.5.tar.gz
Algorithm Hash digest
SHA256 44ad76f52025ab2206715c5f968d13323cbc803c06dfe9bfc82546d6ecf63f51
MD5 aa11375f60cf189a47e491c5e23d5b37
BLAKE2b-256 3fe2c55e8369aae371f7ce0d0e278f74b0ea2ed99e79e609dd7b512fc330a033

See more details on using hashes here.

File details

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

File metadata

  • Download URL: blake3-0.1.5-cp38-none-win_amd64.whl
  • Upload date:
  • Size: 161.1 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.45.0 CPython/3.8.2

File hashes

Hashes for blake3-0.1.5-cp38-none-win_amd64.whl
Algorithm Hash digest
SHA256 4dce593182c1e15dd3752bb1d27e5acb2a7e7311f096fe159c726538d659076f
MD5 9c9ea99cf22ec782d579fc25258d753a
BLAKE2b-256 5cafcf0879cdec308211c9dc277bf8d9b9a9b49c99e5e21b7e04a215ae24e8d1

See more details on using hashes here.

File details

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

File metadata

  • Download URL: blake3-0.1.5-cp38-none-win32.whl
  • Upload date:
  • Size: 173.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.45.0 CPython/3.8.2

File hashes

Hashes for blake3-0.1.5-cp38-none-win32.whl
Algorithm Hash digest
SHA256 512a2e33226f148c586860b6dfa7cb9a0977c913b5e7c5e210265faec4ad1c2b
MD5 c80b9783400f782a0783e143b61f1d93
BLAKE2b-256 a53024a95b10398ef0f6c79909c93a2f3bae0fa747c3e1dfa0afd85088f7f379

See more details on using hashes here.

File details

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

File metadata

  • Download URL: blake3-0.1.5-cp38-cp38-manylinux1_x86_64.whl
  • Upload date:
  • Size: 774.6 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.45.0 CPython/3.8.2

File hashes

Hashes for blake3-0.1.5-cp38-cp38-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 beb254263af3f9139cbc149c7c141b2746110ba24e8ed9abf7ab1e0d9984711e
MD5 54f9bac6963f2ce2e944bca6b87f6a0f
BLAKE2b-256 71a805f68bc7c1cd4ccb32707925a0fd3e578f42cc201e93bbaf84da30c51917

See more details on using hashes here.

File details

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

File metadata

  • Download URL: blake3-0.1.5-cp38-cp38-macosx_10_7_x86_64.whl
  • Upload date:
  • Size: 216.6 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.45.0 CPython/3.8.2

File hashes

Hashes for blake3-0.1.5-cp38-cp38-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 f392e95f5697263aa2fb3754ae90ea8d25f1c6d01bb086633177864e2f30c830
MD5 edb800b835e104dc62da5f40b342c92a
BLAKE2b-256 f6da10cc513fa3d839bd82f39e8caac20ef43871a8eae2a87912fdc0f0c521f5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: blake3-0.1.5-cp37-none-win_amd64.whl
  • Upload date:
  • Size: 161.1 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.45.0 CPython/3.8.2

File hashes

Hashes for blake3-0.1.5-cp37-none-win_amd64.whl
Algorithm Hash digest
SHA256 9d5bfbe50882ee69540f562d447c53fc5afd182a78c18041388a699ed8a847ee
MD5 44f4bd759744d54f7e1a4498a6cbedaa
BLAKE2b-256 51da5bc4a68291734d2614986e450e8cf8f2d57ac1f4dc661db5db8f0930d05a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: blake3-0.1.5-cp37-none-win32.whl
  • Upload date:
  • Size: 173.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.45.0 CPython/3.8.2

File hashes

Hashes for blake3-0.1.5-cp37-none-win32.whl
Algorithm Hash digest
SHA256 9dbc37cd7f76392b58a93b9aac13e75c87b9098d6efa0185a0f8b99006919cb7
MD5 9163ae8abe0f2de0f97eba5f4af94007
BLAKE2b-256 903e5be128981851ce32d3df50aadbfdb3452aae77bd2a1f56c0608a938b29fb

See more details on using hashes here.

File details

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

File metadata

  • Download URL: blake3-0.1.5-cp37-cp37m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 774.6 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.45.0 CPython/3.8.2

File hashes

Hashes for blake3-0.1.5-cp37-cp37m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 59b8da7d40709fdadc786738e52dae17badfdcd0ad0a3a0d1492b175eb13a99d
MD5 35e4f82176a1a5f0744ed53c2789d6ed
BLAKE2b-256 c69d49c271a52730c392842e16bc2cca78156a43a605e74522ea5d715a65fed8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: blake3-0.1.5-cp37-cp37m-macosx_10_7_x86_64.whl
  • Upload date:
  • Size: 216.6 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.45.0 CPython/3.8.2

File hashes

Hashes for blake3-0.1.5-cp37-cp37m-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 ebf320aac1d0d24c0b23ecfdeac274c61439c4d08972cbb7a8d97c8656676373
MD5 24dd72576e0ee3a291f732b5bb16d020
BLAKE2b-256 f5543d2f94c83faac3ede6c43ddc38d18d84172e0a7404c9b23cca7675e0265f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: blake3-0.1.5-cp36-none-win_amd64.whl
  • Upload date:
  • Size: 161.4 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.45.0 CPython/3.8.2

File hashes

Hashes for blake3-0.1.5-cp36-none-win_amd64.whl
Algorithm Hash digest
SHA256 784c55104f11c9fae0c093b6bde604647335eeddad5e2c0a275d4532538d963f
MD5 8f81723e127a46f20b8a6e637c2b4cc4
BLAKE2b-256 27ceaa0a9cf32b77bc67259e116ede4be26034d0704e6716609a99aaed20f509

See more details on using hashes here.

File details

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

File metadata

  • Download URL: blake3-0.1.5-cp36-none-win32.whl
  • Upload date:
  • Size: 173.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.45.0 CPython/3.8.2

File hashes

Hashes for blake3-0.1.5-cp36-none-win32.whl
Algorithm Hash digest
SHA256 093951d45c7d51e62b823b97ea146519bec358ec98b6ded64ecfeb319b4cf19d
MD5 94a18457f717c06bc5685d52907d9787
BLAKE2b-256 8196a029eb49d32d19d9ca85e4828d6a73554c76f744c60a39ae56f2681e5214

See more details on using hashes here.

File details

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

File metadata

  • Download URL: blake3-0.1.5-cp36-cp36m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 774.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.45.0 CPython/3.8.2

File hashes

Hashes for blake3-0.1.5-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 b3d167f755cf9846ffc9ba538ebd7306726e2298a5200eb9358262a87f1eb6ce
MD5 7389efe5040ffbefbf46e6275394b1a1
BLAKE2b-256 7b90be6795d056fec87aafb84fd3f0bbe4eb78ec2430561616ba00f7b93944f2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: blake3-0.1.5-cp36-cp36m-macosx_10_7_x86_64.whl
  • Upload date:
  • Size: 216.8 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.45.0 CPython/3.8.2

File hashes

Hashes for blake3-0.1.5-cp36-cp36m-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 8ab795d7c4281ba5fdc8f25cbb74abdece063a00bda6b9cf7f8040d45311a8eb
MD5 bd56264fd83541737ef1f5178fe1d83f
BLAKE2b-256 78aa362909d6620f4fbf784080e1e3708c2d4c10947a23659d37d686b36793af

See more details on using hashes here.

File details

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

File metadata

  • Download URL: blake3-0.1.5-cp35-none-win_amd64.whl
  • Upload date:
  • Size: 161.4 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.45.0 CPython/3.8.2

File hashes

Hashes for blake3-0.1.5-cp35-none-win_amd64.whl
Algorithm Hash digest
SHA256 eb9fbc11c8b378cb63060688fe1f22e23242f7ef66ccae6295314f76b1dcbabe
MD5 f3684149395ea52f92a8961fd56832f3
BLAKE2b-256 53f8bee8b2e139e79023b3c3b7bf4fe4593db9a4e61b0162f717979fac4a9996

See more details on using hashes here.

File details

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

File metadata

  • Download URL: blake3-0.1.5-cp35-none-win32.whl
  • Upload date:
  • Size: 173.6 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.45.0 CPython/3.8.2

File hashes

Hashes for blake3-0.1.5-cp35-none-win32.whl
Algorithm Hash digest
SHA256 781cadf11ec7872be0939f5821955d1f70f3fb7856bf9bf2d8df2994ca089442
MD5 e8a8bfdba14a211a9700582949288000
BLAKE2b-256 510172763af4f48bcfcf9d06bdd3cc36d2b00c26f676096274d6b7e39d37d9e2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: blake3-0.1.5-cp35-cp35m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 774.7 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.45.0 CPython/3.8.2

File hashes

Hashes for blake3-0.1.5-cp35-cp35m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 2f3858542c45e6e81e526337cdd31931833e245cd7769f9309489f32b6d5e7ad
MD5 a609e6356ef8ac0a3f6af441419288ba
BLAKE2b-256 e140e092da67fe0d6f94c254826f073cf490830a77523e26cf51a8f0d569b8f7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: blake3-0.1.5-cp35-cp35m-macosx_10_7_x86_64.whl
  • Upload date:
  • Size: 216.8 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.45.0 CPython/3.8.2

File hashes

Hashes for blake3-0.1.5-cp35-cp35m-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 b061e9b33a36cab40daf10b8642bec9b4a152c7cff70b15a4493d69a43a6797a
MD5 0da12742bf290e17446e410020dcf7fd
BLAKE2b-256 23d274c45bd30d8c2697b5a0b6c64bba398f9a8dd4983ae307b6b7d3d49d19e7

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