Skip to main content

hashcodecs

CI Codecov PyPI Python License Downloads

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

Design

  • Runtime-dispatched SIMD Base64 with portable scalar fallbacks.
  • Reference-compatible MurmurHash3 with SIMD acceleration.
  • Rust and Python *_into APIs for caller-managed output buffers.
  • A familiar Python Base64 API, including native batch encode and decode operations.

Install

pip3 install hashcodecs

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

assert base64.b64encode(b'hello') == b'aGVsbG8='
assert base64.b64decode(b'aGVsbG8=') == b'hello'
assert base64.b64encode_batch([b'hello', b'world']) == [b'aGVsbG8=', b'd29ybGQ=']
assert base64.b64decode_batch([b'aGVsbG8=', 'd29ybGQ=']) == [b'hello', b'world']
assert base64.b64encode(b'hello', padded=False) == b'aGVsbG8'
assert base64.b64decode(b'aGVsbG8', padded=False, canonical=True) == b'hello'
assert murmur3_32(b'hello') == 0x248BFA47

payload = b'hello'
encoded = bytearray(4 * ((len(payload) + 2) // 3))
encoded_len = base64.b64encode_into(payload, encoded)
decoded = bytearray(len(encoded))
decoded_len = base64.b64decode_into(encoded, decoded, validate=True)
assert encoded[:encoded_len] == b'aGVsbG8='
assert decoded[:decoded_len] == payload

hasher = murmur3_x64_128(seed=42)
hasher.update(b'hello')
assert hasher.hexdigest() == hasher.digest().hex()

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, 50 Rust samples, and 15 Python samples. Returned-output allocation is included except in the reusable-buffer table. 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 sync --group benchmark --no-install-project
uv run --no-project --with . python benchmarks/python_base64.py
uv run --no-project --with . python benchmarks/python_base64.py --into
uv run --no-project --with . python benchmarks/python_base64.py --bytearray-input
uv run --no-project --with . python benchmarks/python_base64.py --memoryview-input
uv run --no-project --with . python benchmarks/python_base64_batch.py
uv run --no-project --with . python benchmarks/python_base64_batch.py --large
uv run --no-project --with . python benchmarks/python_murmur3.py
uv run --no-project --with . python benchmarks/python_murmur3.py --incremental

Base64: Rust

Alphabet Input Operation hashcodecs base64 base64-turbo
Standard 4 KiB encode 20.41 GiB/s 5.81 GiB/s 18.29 GiB/s
4 KiB decode 27.11 GiB/s 4.33 GiB/s 16.95 GiB/s
1 MiB encode 42.38 GiB/s 5.16 GiB/s 19.60 GiB/s
1 MiB decode 31.07 GiB/s 4.10 GiB/s 18.17 GiB/s
32 MiB encode 11.97 GiB/s 3.28 GiB/s 10.94 GiB/s
32 MiB decode 11.51 GiB/s 3.35 GiB/s 10.45 GiB/s
URL-safe 4 KiB encode 20.46 GiB/s 5.81 GiB/s 18.31 GiB/s
4 KiB decode 25.65 GiB/s 4.35 GiB/s 16.96 GiB/s
1 MiB encode 42.56 GiB/s 5.18 GiB/s 19.66 GiB/s
1 MiB decode 29.42 GiB/s 4.08 GiB/s 18.16 GiB/s
32 MiB encode 11.86 GiB/s 3.29 GiB/s 11.09 GiB/s
32 MiB decode 11.67 GiB/s 3.36 GiB/s 10.62 GiB/s

MurmurHash3: Rust

Variant Input hashcodecs murmur3 murmurs fastmurmur3 mm3h
x86 32-bit 4 KiB 4.30 GiB/s 2.60 GiB/s 4.09 GiB/s n/a 4.30 GiB/s
1 MiB 4.26 GiB/s 2.59 GiB/s 4.04 GiB/s n/a 4.25 GiB/s
32 MiB 4.21 GiB/s 2.54 GiB/s 3.87 GiB/s n/a 4.03 GiB/s
x86 128-bit 4 KiB 9.54 GiB/s 4.97 GiB/s 8.64 GiB/s n/a n/a
1 MiB 9.84 GiB/s 5.06 GiB/s 8.77 GiB/s n/a n/a
32 MiB 9.63 GiB/s 4.84 GiB/s 6.05 GiB/s n/a n/a
x64 128-bit 4 KiB 10.76 GiB/s 6.83 GiB/s 9.45 GiB/s 10.06 GiB/s 9.54 GiB/s
1 MiB 10.84 GiB/s 6.89 GiB/s 9.51 GiB/s 10.04 GiB/s 9.51 GiB/s
32 MiB 10.12 GiB/s 6.11 GiB/s 6.64 GiB/s 7.25 GiB/s 6.70 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 14.42 GiB/s 0.49 GiB/s 14.36 GiB/s
4 KiB decode 16.72 GiB/s 1.12 GiB/s 8.35 GiB/s
1 MiB encode 3.69 GiB/s 0.43 GiB/s 3.51 GiB/s
1 MiB decode 4.90 GiB/s 0.97 GiB/s 4.60 GiB/s
32 MiB encode 2.81 GiB/s 0.44 GiB/s 2.60 GiB/s
32 MiB decode 3.15 GiB/s 0.93 GiB/s 3.49 GiB/s
URL-safe 4 KiB encode 14.48 GiB/s 0.40 GiB/s 1.19 GiB/s
4 KiB decode 13.45 GiB/s 0.75 GiB/s 1.56 GiB/s
1 MiB encode 3.96 GiB/s 0.36 GiB/s 0.92 GiB/s
1 MiB decode 4.53 GiB/s 0.61 GiB/s 1.58 GiB/s
32 MiB encode 2.64 GiB/s 0.34 GiB/s 0.83 GiB/s
32 MiB decode 3.15 GiB/s 0.60 GiB/s 1.49 GiB/s

MurmurHash3: Python

Variant API Input hashcodecs mmh3
x86 32-bit one-shot 4 KiB 3.79 GiB/s 3.71 GiB/s
1 MiB 3.98 GiB/s 3.83 GiB/s
32 MiB 3.97 GiB/s 3.66 GiB/s
incremental 4 KiB 3.58 GiB/s 3.58 GiB/s
1 MiB 3.96 GiB/s 3.81 GiB/s
32 MiB 3.92 GiB/s 3.74 GiB/s
x86 128-bit one-shot 4 KiB 8.09 GiB/s 8.21 GiB/s
1 MiB 9.22 GiB/s 8.87 GiB/s
32 MiB 9.12 GiB/s 6.15 GiB/s
incremental 4 KiB 7.02 GiB/s 0.77 GiB/s
1 MiB 9.17 GiB/s 0.80 GiB/s
32 MiB 9.01 GiB/s 0.79 GiB/s
x64 128-bit one-shot 4 KiB 8.68 GiB/s 9.46 GiB/s
1 MiB 10.10 GiB/s 10.24 GiB/s
32 MiB 9.54 GiB/s 6.61 GiB/s
incremental 4 KiB 7.70 GiB/s 7.99 GiB/s
1 MiB 10.01 GiB/s 9.28 GiB/s
32 MiB 9.41 GiB/s 7.34 GiB/s

Reusable-buffer and mutable-input results are available in BENCHMARK.md.

SIMD References

The SIMD implementation follows the approach described in Faster Base64 Encoding and Decoding using AVX2 Instructions, with AVX-512 VBMI and AArch64 NEON backends selected automatically when available.

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.5.0.tar.gz (57.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.5.0-cp310-abi3-win_amd64.whl (258.5 kB view details)

Uploaded CPython 3.10+Windows x86-64

hashcodecs-0.5.0-cp310-abi3-manylinux_2_28_x86_64.whl (403.4 kB view details)

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

hashcodecs-0.5.0-cp310-abi3-macosx_11_0_arm64.whl (336.4 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: hashcodecs-0.5.0.tar.gz
  • Upload date:
  • Size: 57.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.5.0.tar.gz
Algorithm Hash digest
SHA256 3a451277cbba2707b7f5d400828532afe337423109ccea525b63c0fe1186f96e
MD5 d45bbbac549d42f69fe161a72c398926
BLAKE2b-256 83f150670c65cd2c73a90bc1058a9256d53514902f0790c7e874a72d715b8eef

See more details on using hashes here.

File details

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

File metadata

  • Download URL: hashcodecs-0.5.0-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 258.5 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.5.0-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 b60b1a778a766e4ce06c0d9a2112805e4098704a5c5620e0821a57b1b3755f40
MD5 a66b42f72b25e11bb0fa64f2c6372155
BLAKE2b-256 071eac78e815b412bb92d51db023b4f435aec80af87de311ea89c7b37e947da7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: hashcodecs-0.5.0-cp310-abi3-manylinux_2_28_x86_64.whl
  • Upload date:
  • Size: 403.4 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.5.0-cp310-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 6628740069b55f44224a5b07243e7f0b33baed88c52000bff85f2d810c0f72b9
MD5 6360d7b3c2dc5043d4103d3be1b59e22
BLAKE2b-256 f366247bcdabf4e2ff0b988d84c6eb711c15d6ac48be7061212e4b3f0250730b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: hashcodecs-0.5.0-cp310-abi3-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 336.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.5.0-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3a413cfe4c6bbb3508908d831668e2ffc05aeef153e721c513d993b33b95797e
MD5 8b7efea450f227766a216b146c7e5ff5
BLAKE2b-256 2739c487cb30ff8e2475ff7e947c0709f0381cb43c35bde43165f64915287a13

See more details on using hashes here.

Release history Release notifications | RSS feed

1.4.1

25 files

1.4.0

25 files

1.3.0

25 files

1.2.1

25 files

1.2.0

25 files

1.1.0

25 files

1.0.0

25 files

0.6.1

19 files

0.6.0

19 files

This release

0.5.0 This release

4 files

0.4.0

4 files

0.3.0

4 files

0.2.0

4 files

0.1.0

4 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page