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 rustup installed. The toolchain version is currently pinned in the rust-toolchain file (tracking issue), and rustup will automatically download it.

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

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

Uploaded Source

Built Distributions

blake3-0.1.3-cp38-none-win_amd64.whl (162.1 kB view details)

Uploaded CPython 3.8 Windows x86-64

blake3-0.1.3-cp38-none-win32.whl (176.7 kB view details)

Uploaded CPython 3.8 Windows x86

blake3-0.1.3-cp38-cp38-manylinux1_x86_64.whl (811.6 kB view details)

Uploaded CPython 3.8

blake3-0.1.3-cp38-cp38-macosx_10_7_x86_64.whl (211.5 kB view details)

Uploaded CPython 3.8 macOS 10.7+ x86-64

blake3-0.1.3-cp37-none-win_amd64.whl (161.7 kB view details)

Uploaded CPython 3.7 Windows x86-64

blake3-0.1.3-cp37-none-win32.whl (176.7 kB view details)

Uploaded CPython 3.7 Windows x86

blake3-0.1.3-cp37-cp37m-manylinux1_x86_64.whl (811.2 kB view details)

Uploaded CPython 3.7m

blake3-0.1.3-cp37-cp37m-macosx_10_7_x86_64.whl (211.3 kB view details)

Uploaded CPython 3.7m macOS 10.7+ x86-64

blake3-0.1.3-cp36-none-win_amd64.whl (162.3 kB view details)

Uploaded CPython 3.6 Windows x86-64

blake3-0.1.3-cp36-none-win32.whl (177.3 kB view details)

Uploaded CPython 3.6 Windows x86

blake3-0.1.3-cp36-cp36m-manylinux1_x86_64.whl (811.9 kB view details)

Uploaded CPython 3.6m

blake3-0.1.3-cp36-cp36m-macosx_10_7_x86_64.whl (211.9 kB view details)

Uploaded CPython 3.6m macOS 10.7+ x86-64

blake3-0.1.3-cp35-none-win_amd64.whl (162.7 kB view details)

Uploaded CPython 3.5 Windows x86-64

blake3-0.1.3-cp35-none-win32.whl (177.3 kB view details)

Uploaded CPython 3.5 Windows x86

blake3-0.1.3-cp35-cp35m-manylinux1_x86_64.whl (812.3 kB view details)

Uploaded CPython 3.5m

blake3-0.1.3-cp35-cp35m-macosx_10_7_x86_64.whl (212.2 kB view details)

Uploaded CPython 3.5m macOS 10.7+ x86-64

File details

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

File metadata

  • Download URL: blake3-0.1.3.tar.gz
  • Upload date:
  • Size: 30.0 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.43.0 CPython/3.8.2

File hashes

Hashes for blake3-0.1.3.tar.gz
Algorithm Hash digest
SHA256 87a11f0eb20a293d2b4975ee21ea1047d1d923fbc81cdabc53cf1ccaf0798855
MD5 088f752e19adf64f9acfc6cf7a6b6e21
BLAKE2b-256 89937d91b13d7f0e434699e660f1906c59df6fec03200610ccba5e118647894d

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for blake3-0.1.3-cp38-none-win_amd64.whl
Algorithm Hash digest
SHA256 baecf733beab83e2a7199699f1b99a81a495b4e549913d729fcd14be7e3c05b8
MD5 19dbe7c00d5e6b8a48ad90bd75b5260d
BLAKE2b-256 6ac03934bfc5bed638bc8097eb81d43bbc0c84e8876615c7bef425b3afda74a6

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for blake3-0.1.3-cp38-none-win32.whl
Algorithm Hash digest
SHA256 6bb7bcefe4cd30d935d461876cb2e22970af67acab0f06b629cd7c13c88b5368
MD5 091aefc635e73b150847a3e6c931256d
BLAKE2b-256 20f83c8a0ad80354765da537113b0a981a99e1ef3340b38143411f0e7bf854e3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: blake3-0.1.3-cp38-cp38-manylinux1_x86_64.whl
  • Upload date:
  • Size: 811.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.43.0 CPython/3.8.2

File hashes

Hashes for blake3-0.1.3-cp38-cp38-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 8f053c2c3ab071ac87e985944c880ec9a16d4db38925d55f95f159c132ad3b50
MD5 914be2928a1c255a0c47400faef1e166
BLAKE2b-256 87cf8bd19e4e9653334cf1454c2d69e76a10a6b8b5c82dc8f066c267755a1aac

See more details on using hashes here.

File details

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

File metadata

  • Download URL: blake3-0.1.3-cp38-cp38-macosx_10_7_x86_64.whl
  • Upload date:
  • Size: 211.5 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.43.0 CPython/3.8.2

File hashes

Hashes for blake3-0.1.3-cp38-cp38-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 3e30aa8a95defa87fbcbfbaab2021d7f11781c1b32e181d3a1eec2525950e6ae
MD5 8da257cd6947567b70ba77ef801a0ab6
BLAKE2b-256 30fb0e14c3819d3d1b2c445d13f7dbbe2251c32d906a6a6c738a6b49c64f46d4

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for blake3-0.1.3-cp37-none-win_amd64.whl
Algorithm Hash digest
SHA256 696b6ad186d1cb285c12d67b22f2952c9e23440c24bb2302b8d923b5db2ca6f9
MD5 21cc5224566243ba4f8dabbf683240f6
BLAKE2b-256 797628e8ed59a30b52c0417e3bda88c8b5b2fac01458bd3d9e1d127b3f3203e4

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for blake3-0.1.3-cp37-none-win32.whl
Algorithm Hash digest
SHA256 f571db31d4444e0b98d01f5e7b3c77bcdc436e5a92698dffda7faa92db877721
MD5 83226c7b1deb9ac44524046629b3a22f
BLAKE2b-256 3f48492a87ca7226064c3a0db227d717cf0a231edda2cb12f4612a38a22f082f

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for blake3-0.1.3-cp37-cp37m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 1855236be918a1c16036eb0b51330116647fe207d2f4e5ae4eddc79801dd6ddd
MD5 a22e0c992557aa527e143a938071573a
BLAKE2b-256 89ce0341c9c54f6ce2f67a7720809c48d652b6d78c3d2226eff2246302aa480a

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for blake3-0.1.3-cp37-cp37m-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 a94a3dad783149eb4dd1a5bcc87ac18522dea9fbbab97a16ffa2a2988346e47e
MD5 9593e8d928e9b97d2f95b90f4b7418c6
BLAKE2b-256 963ca3cb4597ccb29bde2890cda9fe76759080e2e748b1a8837b6d9623cad0b7

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for blake3-0.1.3-cp36-none-win_amd64.whl
Algorithm Hash digest
SHA256 fe966050a7b9dbb787c6bb65c448dba137475235eb4bc5b908d4bd4849283072
MD5 35cf155cdb39385caf5f680cd91f98db
BLAKE2b-256 47c92ff35c17ec2a562254169f5bd623e079c18a3a5ab404eaa255f530b859a3

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for blake3-0.1.3-cp36-none-win32.whl
Algorithm Hash digest
SHA256 c39034f346ac67b0554ef16f1c3c6a0ad7a52f54977d0be6928def03023b42e3
MD5 713c77ec504e7330a75d89c3960a501b
BLAKE2b-256 47cad815021c948916fc273b74a99a508ba2075fc4d32aef8048976abc27aca7

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for blake3-0.1.3-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 ad78000385b350f02b4c06972f7a46ae3d6efd0cc6f251b447413fbded8c7c78
MD5 d0ee7183b0ba551ff763198897de0349
BLAKE2b-256 dd2845f57f79e8228d87ee5fdefacc50a1753630b39ecfdfb5fff6beddc3d7f5

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for blake3-0.1.3-cp36-cp36m-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 375889cd7932c3883f2206d21bd440c22433ffa4adf7342b4b70281e32429476
MD5 598a8909f8291cbae39f3fafe0483335
BLAKE2b-256 eee082b697b1d92d971318660f82b3b52333494a3d9188aa860fe0b8983bba74

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for blake3-0.1.3-cp35-none-win_amd64.whl
Algorithm Hash digest
SHA256 1a1e3600d7a5fc2ad17a5fc38801681d0e9308f0392bc56c43a9183991152383
MD5 a1d401cd5b9a216d65abad0bd3c1af59
BLAKE2b-256 c6eada335cd7b6d72bfc41a45900aeb0ea10f2ad00b9c3be989b4e537bd4e112

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for blake3-0.1.3-cp35-none-win32.whl
Algorithm Hash digest
SHA256 283a9a2951b8f90e6fcda56b220f2c4dc22e60f2556d53aea2df68a7b474e2be
MD5 6b443fa12e7d112b2b99e30f7133d04f
BLAKE2b-256 b588507315a4ec6807c5c48a69bcea087fa0c29243389976a62e5a8759da7262

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for blake3-0.1.3-cp35-cp35m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 3e3de6b8f112c75d11d9d01211ef0a4c53457ed1e08dfab1f22a8eb092283519
MD5 40eb38d1e7f5749b3a1438808be4a32d
BLAKE2b-256 5168bf0ccae7a5464269af30b95da17d58c2c344a200386be87090b7f3ea66ae

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for blake3-0.1.3-cp35-cp35m-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 c8d17abe737a72bd3dc63a35314b3161dcbbefa00525452c3c1a91491c7cf3ae
MD5 9a658392840b35ece8b1949ec5990118
BLAKE2b-256 c26de834fbc152bba3ae5c032eae4287e9531082526f507d9929721c7f33f6ae

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