Skip to main content

hashcodecs

CI PyPI Python License Downloads

hashcodecs provides runtime-dispatched SIMD Base64 codecs and fast, reference-compatible MurmurHash3 functions for Rust and Python.

Design

  • Base64 is implemented in this crate with runtime AVX2 and SSSE3 dispatch. One portable wheel supports Intel and AMD CPUs, selecting SIMD where the OS and CPU allow it and a scalar fallback otherwise.
  • Rust callers can reuse their own output buffers through the *_into APIs. Every backend writes exactly the documented prefix; it never depends on spare capacity after the destination slice.
  • Rust-owned results use the mimalloc global allocator.
  • MurmurHash3 uses direct little-endian block loads and tight scalar loops. Its state transitions are loop-carried, so the scalar implementation is faster than forcing wide-vector instructions for these hashes.
  • The Python Base64 surface follows the familiar base64 names. Use import hashcodecs.base64 as base64 when replacing standard Base64 calls.
  • Large Python calls release the GIL. Strict decoding and valid default-mode decoding write directly into the returned bytes; malformed default-mode input uses a CPython-compatible lenient fallback.

Usage

Rust

let encoded = hashcodecs::b64encode(b"hello");
assert_eq!(encoded, "aGVsbG8=");

let mut output = [0_u8; 8];
let written = hashcodecs::b64encode_into(b"hello", &mut output).unwrap();
assert_eq!(&output[..written], b"aGVsbG8=");
assert_eq!(hashcodecs::murmur3_x86_32(b"hello", 0), 0x248b_fa47);

Python

import hashcodecs.base64 as base64
from hashcodecs import murmur3_32

assert base64.b64encode(b"hello") == b"aGVsbG8="
assert base64.b64decode(b"aGVsbG8=") == b"hello"
assert murmur3_32(b"hello") == 0x248BFA47

Build an installable wheel and source distribution with:

uv build

Benchmark

Environment: Windows 10 x64 and Intel Core Ultra 7 265K.

Conditions: clean builds, one pinned logical CPU, single-threaded execution, and output allocation included. Higher is better.

Run Locally

Comparison crates are development-only dependencies and are not included in consumer builds.

cargo bench --bench base64
cargo bench --bench murmur3
uv run --no-project python benchmarks/python_base64.py

To time only this implementation:

cargo bench --bench base64 -- hashcodecs
cargo bench --bench murmur3 -- hashcodecs
uv run --no-project python benchmarks/python_base64.py --hashcodecs-only

Base64: Rust

Alphabet Input Operation hashcodecs base64 base64-turbo
Standard 4 KiB encode 18.11 GiB/s 5.40 GiB/s 17.01 GiB/s
4 KiB decode 16.18 GiB/s 4.05 GiB/s 15.83 GiB/s
1 MiB encode 19.25 GiB/s 4.83 GiB/s 18.28 GiB/s
1 MiB decode 18.28 GiB/s 3.81 GiB/s 16.78 GiB/s
512 MiB encode 8.90 GiB/s 3.10 GiB/s 8.88 GiB/s
512 MiB decode 9.32 GiB/s 3.03 GiB/s 9.12 GiB/s
URL-safe 4 KiB encode 17.77 GiB/s 5.42 GiB/s 17.02 GiB/s
4 KiB decode 14.39 GiB/s 4.04 GiB/s 15.72 GiB/s
1 MiB encode 19.27 GiB/s 4.83 GiB/s 18.30 GiB/s
1 MiB decode 16.15 GiB/s 3.81 GiB/s 16.97 GiB/s
512 MiB encode 8.97 GiB/s 3.09 GiB/s 8.92 GiB/s
512 MiB decode 9.32 GiB/s 3.00 GiB/s 9.20 GiB/s

MurmurHash3: Rust

Variant Input hashcodecs murmur3 murmurs fastmurmur3 mm3h
x86 32-bit 4 KiB 3.75 GiB/s 2.42 GiB/s 3.81 GiB/s n/a 4.02 GiB/s
1 MiB 3.81 GiB/s 2.44 GiB/s 3.79 GiB/s n/a 3.98 GiB/s
512 MiB 3.58 GiB/s 2.42 GiB/s 3.58 GiB/s n/a 3.73 GiB/s
x86 128-bit 4 KiB 8.18 GiB/s 4.66 GiB/s 8.08 GiB/s n/a n/a
1 MiB 8.26 GiB/s 4.71 GiB/s 8.19 GiB/s n/a n/a
512 MiB 5.61 GiB/s 4.44 GiB/s 5.33 GiB/s n/a n/a
x64 128-bit 4 KiB 8.96 GiB/s 6.38 GiB/s 8.85 GiB/s 9.40 GiB/s 8.87 GiB/s
1 MiB 8.95 GiB/s 6.44 GiB/s 8.87 GiB/s 9.39 GiB/s 8.89 GiB/s
512 MiB 5.98 GiB/s 5.56 GiB/s 5.66 GiB/s 6.56 GiB/s 5.73 GiB/s

Base64: Python

Python decoding uses validate=True, and hashcodecs passes bytes directly into Rust without an input copy.

Alphabet Input Operation hashcodecs CPython base64 pybase64
Standard 4 KiB encode 13.73 GiB/s 0.49 GiB/s 14.09 GiB/s
4 KiB decode 12.04 GiB/s 1.14 GiB/s 8.50 GiB/s
1 MiB encode 3.66 GiB/s 0.47 GiB/s 3.32 GiB/s
1 MiB decode 4.09 GiB/s 0.89 GiB/s 4.13 GiB/s
512 MiB encode 2.86 GiB/s 0.44 GiB/s 3.04 GiB/s
512 MiB decode 3.41 GiB/s 0.94 GiB/s 3.74 GiB/s
URL-safe 4 KiB encode 13.60 GiB/s 0.41 GiB/s 1.19 GiB/s
4 KiB decode 9.00 GiB/s 0.76 GiB/s 1.56 GiB/s
1 MiB encode 3.61 GiB/s 0.36 GiB/s 0.96 GiB/s
1 MiB decode 3.91 GiB/s 0.57 GiB/s 1.55 GiB/s
512 MiB encode 2.93 GiB/s 0.36 GiB/s 0.91 GiB/s
512 MiB decode 3.33 GiB/s 0.63 GiB/s 1.53 GiB/s

SIMD References

The AVX2 block structure uses the 24-byte encode and 32-byte decode arrangement described in Faster Base64 Encoding and Decoding using AVX2 Instructions. Base64 Turbo is included as a Rust comparator and is a useful direction for a future AVX-512 backend. This crate currently retains its Rust 1.85 MSRV, so its production runtime dispatch remains AVX2, SSSE3, and scalar.

Download files

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

Source Distribution

hashcodecs-0.1.0.tar.gz (35.0 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

hashcodecs-0.1.0-cp310-abi3-win_amd64.whl (178.7 kB view details)

Uploaded CPython 3.10+Windows x86-64

hashcodecs-0.1.0-cp310-abi3-manylinux_2_28_x86_64.whl (319.0 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.28+ x86-64

hashcodecs-0.1.0-cp310-abi3-macosx_11_0_arm64.whl (267.4 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

File details

Details for the file hashcodecs-0.1.0.tar.gz.

File metadata

  • Download URL: hashcodecs-0.1.0.tar.gz
  • Upload date:
  • Size: 35.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.3 {"installer":{"name":"uv","version":"0.12.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for hashcodecs-0.1.0.tar.gz
Algorithm Hash digest
SHA256 333786223fa29e65ff8b8a9442cbc8030c289a2ba72a85fa4c00df523147a3ec
MD5 99569650a50c9116caa888b8b7ef3dad
BLAKE2b-256 e25a90aa9526fbec7736d7eb79bf8de8221edaaf30d01b2ca353c30dae4ff978

See more details on using hashes here.

File details

Details for the file hashcodecs-0.1.0-cp310-abi3-win_amd64.whl.

File metadata

  • Download URL: hashcodecs-0.1.0-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 178.7 kB
  • Tags: CPython 3.10+, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.3 {"installer":{"name":"uv","version":"0.12.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for hashcodecs-0.1.0-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 71ac18fe61d0b8044f875b6b9131a224f8d96410c3a058ec1612145151b60ce8
MD5 fe6196540185202a31ef481046d0facd
BLAKE2b-256 e0542c6db3c97d559fd8335a3b378ee185545a91e174e69cb2f9bd539ba734d3

See more details on using hashes here.

File details

Details for the file hashcodecs-0.1.0-cp310-abi3-manylinux_2_28_x86_64.whl.

File metadata

  • Download URL: hashcodecs-0.1.0-cp310-abi3-manylinux_2_28_x86_64.whl
  • Upload date:
  • Size: 319.0 kB
  • Tags: CPython 3.10+, manylinux: glibc 2.28+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.3 {"installer":{"name":"uv","version":"0.12.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for hashcodecs-0.1.0-cp310-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 db60334261558b93717a7b1e3e569821505ee291551cecea2a3e9433eea9bdbb
MD5 574fc978fa7803f03fa19665a234d95c
BLAKE2b-256 e0096964ab6ee115b1f584350512496643c9e3bea342899104a8acc40e98ca60

See more details on using hashes here.

File details

Details for the file hashcodecs-0.1.0-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

  • Download URL: hashcodecs-0.1.0-cp310-abi3-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 267.4 kB
  • Tags: CPython 3.10+, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.3 {"installer":{"name":"uv","version":"0.12.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for hashcodecs-0.1.0-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 204009f30c6ba9f64d7317decb48a0c332b5a0698760597249bd931d16515aef
MD5 180eb1cb379af3695ce11371bf0888fe
BLAKE2b-256 1f27963d85337390728c1461c52f57f79c5f3f5957c3862264565c2f2b1550c2

See more details on using hashes here.

Supported by

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