Registry / serialization / pymultihash

pymultihash

JSON →
library0.8.2pypypi✓ verified 87d ago

Python implementation of the multihash specification (current version 0.8.2). Multihash is a self-describing hash format that includes a hash function identifier and digest length. This library provides encoding, decoding, and hashing utilities. Release cadence is low; last release was in 2020.

pip install pymultihash
INSTALL
IMPORT
SIG · PYMULTIHASH
P
pymultihash
serializationpythonv0.8.2
Install
1.6s avg
Import
10ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v0.8.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.010s · 17.9MB
glibc
py 3.10–3.95 runs
installs and imports cleanly · install 1.6s · import 0.010s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

multihash
✓ import multihash
✗ from pymultihash import multihash
The package provides a top-level module `multihash`, not a submodule under `pymultihash`.

Encode and decode multihashes using the standard functions.

import multihash # Hash data using SHA2-256 (code 0x12) digest = multihash.digest(b'hello world', 'sha2-256') print(digest.hex()) # multihash encoded # Decode a multihash decoded = multihash.decode(digest) print(decoded.code) # 0x12 print(decoded.digest.hex()) # raw digest # Hash with a specific length (truncated) digest_trunc = multihash.digest(b'hello world', 'sha2-256', 8) print(len(digest_trunc)) # 1 (varint code) + 1 (length) + 8 = 10 bytes
Debug
Known issues
gotchaThe `digest` function returns a multihash-encoded byte string (with code and length prefix), not a raw hash digest. This differs from other multihash libraries.
fix
Use `multihash.decode()` to extract the raw digest, or use `hashlib` for raw hashing and then `multihash.encode()` to wrap it.
affects: all
gotchaHash function names are lowercase with hyphens (e.g., 'sha2-256', 'sha3-512'). Using incorrect casing (e.g., 'SHA256') raises a ValueError.
fix
Use the exact names as defined in the multihash table: 'sha1', 'sha2-256', 'sha2-512', 'sha3-512', 'blake2b-256', etc.
affects: all
deprecatedThe `encode` and `decode` functions may be renamed or deprecated in future versions. Check the latest documentation.
fix
Monitor the repo for API changes; no breaking changes have occurred yet.
affects: 0.8.x
Errors
Common errors & fixes
ValueError: Unknown multihash code: 0x12
Passing a raw digest (without the multihash code+length prefix) to `decode()`.
fix
Ensure the input to `decode()` is a complete multihash-encoded byte string, not a raw hash. Use `digest()` to create a valid multihash.
NameError: name 'multihash' is not defined
Using incorrect import path (e.g., `from pymultihash import multihash`).
fix
Use `import multihash` (the package exposes a top-level module).
ValueError: Unsupported hash function: sha256
Using an incorrect hash function name (common mistake: using 'sha256' instead of 'sha2-256').
fix
Use the full multihash name: 'sha2-256', 'sha2-512', 'sha3-512', etc.
TypeError: digest() takes 2 positional arguments but 3 were given
The third argument `length` is optional but must be passed as a keyword argument if provided.
fix
Use `multihash.digest(data, 'sha2-256', length=16)` instead of positional third argument.
Upgrade
Version history
0.8.2latest on PyPI · released Jun 12, 2016
Audit
Dependencies

No dependency data recorded yet.

Agent activity
7 hits · last 30 days
node
6
Resources
pymultihash — pip install pymultihash · libregistry