Python bindings for the Rust blake3 crate
Project description
blake3-py
Python bindings for the Rust blake3
crate, based on PyO3. This a proof of
concept, not yet fully-featured or production-ready. See also the
Soundness concerns below.
Example
How to try out this repo on the command line:
# You have to build the shared library first.
$ ./build.py
# Try out example.py.
$ echo hello world | ./example.py
dc5a4edb8240b018124052c330270696f96771a63b45250a5c17d3000e823355
# Run a few tests.
$ ./test.py
What it looks like to use blake3
in Python code:
import blake3
hash1 = blake3.blake3(b"foobarbaz").digest()
hasher = blake3.blake3()
hasher.update(b"foo")
hasher.update(b"bar")
hasher.update(b"baz")
hash2 = hasher.digest()
assert hash1 == hash2
print("The hash of 'hello world' is:",
blake3.blake3(b"hello world").hexdigest())
Building
The build.py
script runs cargo build --release
and then copies the
resulting shared library to a platform-appropriate name (blake3.so
on
Linux/macOS, and blake3.pyd
on Windows) in the repo root directory.
Python scripts in that directory will then load the shared library when
they import blake3
.
This project is not yet packaged in a way that's convenient to pip install
. I need to learn more about Python packaging to understand the
right way to do this. (Binary wheels?) Any help on this front from folks
with more experience would be greatly appreciated.
Soundness
There are some fundamental questions about whether these bindings can be
sound. Like the Python standard library's hash implementations, in order
to avoid blocking other threads during a potentially expensive call to
update()
, we release the GIL. But that opens up the possibility that
another thread might mutate, say, the bytearray
we're hashing, while
the Rust code is treating it as a &[u8]
. That violates Rust's aliasing
guarantees and is technically unsound. However, no Python hashing
implementation that I'm aware of holds the GIL while it calls into
native code. I need to get some expert opinions on this.
Features
Currently only basic hashing is supported, with the default 32-byte output size. Missing BLAKE3 features should be easy to add, though I'm not sure exactly what the API should look like. Missing features include:
- variable-length output
- an incremental output reader
- the keyed hashing mode
- the key derivation mode
- optional multi-threading
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.0.tar.gz
.
File metadata
- Download URL: blake3-0.1.0.tar.gz
- Upload date:
- Size: 5.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/0.7.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 120723773bd4e2122badecd1aa28f1a60ee0c715042cb8e4e79561ccad9fe8d4 |
|
MD5 | 8c4d4756d78c2a9a1fa0fd9101182ea3 |
|
BLAKE2b-256 | 897450ab1a32c5acf77ef732599779af5f1898b2bd374e9fab1531a39ea6dff7 |
File details
Details for the file blake3-0.1.0-cp38-none-win_amd64.whl
.
File metadata
- Download URL: blake3-0.1.0-cp38-none-win_amd64.whl
- Upload date:
- Size: 119.8 kB
- Tags: CPython 3.8, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/0.7.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f1cde8a7ad147a46c4096d5878abca10822da56ff5bf68ee8b5f2232465b8a10 |
|
MD5 | c04bf678dd44d83a68dd193159f94d7e |
|
BLAKE2b-256 | b0a796a293991dd296d4eec1a8783bf0f6333361515a6d46ad523146a83a90dd |
File details
Details for the file blake3-0.1.0-cp38-cp38-manylinux1_x86_64.whl
.
File metadata
- Download URL: blake3-0.1.0-cp38-cp38-manylinux1_x86_64.whl
- Upload date:
- Size: 148.6 kB
- Tags: CPython 3.8
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/0.7.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 376f39ec7f2565adfdc20e46f9768ab729417786a2e2dc22180799bdf05f79f5 |
|
MD5 | 9508ad3ae14d7415527fe27085af467b |
|
BLAKE2b-256 | 53ed4faec95b9b40f9be267cf22ea43fe5caeb70f59b8ec6a05bdc8f385e06f0 |
File details
Details for the file blake3-0.1.0-cp37-cp37m-manylinux1_x86_64.whl
.
File metadata
- Download URL: blake3-0.1.0-cp37-cp37m-manylinux1_x86_64.whl
- Upload date:
- Size: 148.6 kB
- Tags: CPython 3.7m
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/0.7.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 37967e50c681ded4fa3f7924b143673ba16fb4639553dc12404641e2f8d7a011 |
|
MD5 | be9760add8fd8d1e71b40f7674b0a43b |
|
BLAKE2b-256 | 2cbdc32d862acf56f27ec6bebeb3045a5d19db63945d232a798e4bdb6d89de37 |
File details
Details for the file blake3-0.1.0-cp36-cp36m-manylinux1_x86_64.whl
.
File metadata
- Download URL: blake3-0.1.0-cp36-cp36m-manylinux1_x86_64.whl
- Upload date:
- Size: 149.3 kB
- Tags: CPython 3.6m
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/0.7.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3332fb6c5a619ee2b7b1d29e3cfeaabaf0515c01c11a80e1b5379832f9e0aa4b |
|
MD5 | 0d760ea8d920ee8dc58593d60745a412 |
|
BLAKE2b-256 | 5f34dc58e4a9ed5a44becd7d749410b6e21c20272cfdebd71b4dd38aa6987165 |
File details
Details for the file blake3-0.1.0-cp35-cp35m-manylinux1_x86_64.whl
.
File metadata
- Download URL: blake3-0.1.0-cp35-cp35m-manylinux1_x86_64.whl
- Upload date:
- Size: 149.4 kB
- Tags: CPython 3.5m
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/0.7.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2322221c2b34c893327a0a0b36111ec9ffda618b98cd93d382b29fa7024039e8 |
|
MD5 | e8fdae644f7714cb1b345a9c39aa4679 |
|
BLAKE2b-256 | c0371ddad507578d22d9c5a012a4b86ff20efcf8c5125145c7fd24d0f4f5733f |