Registry / serialization / py-multihash

py-multihash

JSON →
library3.0.0pypypi✓ verified 89d ago

py-multihash is a Python implementation of the Multihash specification, providing functions to encode and decode self-describing cryptographic hashes. The current version is 3.0.0. Releases are infrequent, tied to updates in the Multiformats specification.

pip install py-multihash
INSTALL
IMPORT
SIG · PY-MULTIHASH
P
py-multihash
serializationpythonv3.0.0
Install
2.8s avg
Import
35ms
Disk
19MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v3.0.0 · 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.910 runs
installs and imports cleanly · install 0.0s · import 0.036s · 21.7MB
glibc
py 3.10–3.910 runs
installs and imports cleanly · install 2.8s · import 0.033s · 22MB
19MB installed
● package 19MB
Code
Verified usage

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

encode
✓ from multihash import encode
decode
✓ from multihash import decode
Digest
✓ from multihash import Digest
Multihash
✓ from multihash import encode, decode, Digest
✗ from multihash import Multihash
The `Multihash` class was removed in v3.0.0. `encode` and `decode` are now top-level module functions, and `Digest` is directly importable.

This example demonstrates how to encode a byte string into a multihash and then decode it back to retrieve its properties like the algorithm name, code, length, and the raw digest.

import multihash import multicodec # Encode a byte string with a specific hash algorithm data = b'Hello multihash world!' mh = multihash.encode(data, 'sha2-256') print(f"Encoded multihash: {mh.hex()}") # Decode a multihash digest decoded_digest = multihash.decode(mh) print(f"Decoded digest name: {decoded_digest.name}") print(f"Decoded digest code: {hex(decoded_digest.code)}") print(f"Decoded digest length: {decoded_digest.length}") print(f"Original digest: {decoded_digest.digest.hex()}") # Verify the algorithm code using multicodec constants assert decoded_digest.code == multicodec.SHA2_256 print("Verification successful!")
Debug
Known issues
breakingThe `Multihash` class has been removed in version 3.0.0. `encode` and `decode` are now top-level functions in the `multihash` module, and `Digest` is a directly exposed class.
fix
Replace `Multihash().encode(data, code)` with `multihash.encode(data, code)`. Replace `Multihash().decode(mh)` with `multihash.decode(mh)`. Import `Digest` directly: `from multihash import Digest`.
affects: >=3.0.0
breakingThe `multihash.constants` module was removed in version 3.0.0. All algorithm constants (e.g., `SHA2_256`) are now provided by the `py-multicodec` library.
fix
Instead of `from multihash.constants import SHA2_256`, use `import multicodec` and refer to constants as `multicodec.SHA2_256`.
affects: >=3.0.0
breakingPython 3.10 or newer is now required for `py-multihash` version 3.0.0 and above.
fix
Upgrade your Python environment to 3.10 or higher. If unable, pin `py-multihash<3.0.0`.
affects: >=3.0.0
gotchaThe `multihash.encode` function expects the hash algorithm to be specified by its string name (e.g., 'sha2-256') or its integer code, not a `py-multicodec` constant directly for the algorithm parameter.
fix
Use `multihash.encode(data, 'sha2-256')` or `multihash.encode(data, 0x12)` instead of `multihash.encode(data, multicodec.SHA2_256)` directly for the algorithm name/code parameter. The `multicodec` library is still essential for looking up constants and verifying codes.
affects: all
Errors
Common errors & fixes
AttributeError: module 'multihash' has no attribute 'Multihash'
Attempting to use the `Multihash` class which was removed in v3.0.0.
fix
The `encode` and `decode` functions are now top-level. Use `multihash.encode(...)` and `multihash.decode(...)` directly.
ImportError: cannot import name 'constants' from 'multihash'
Attempting to import the `constants` module which was removed in v3.0.0.
fix
Algorithm constants are now part of the `py-multicodec` library. Use `import multicodec` and access constants like `multicodec.SHA2_256`.
TypeError: encode() missing 1 required positional argument: 'data' (if called as `Multihash.encode(alg)`) or AttributeError: type object 'Multihash' has no attribute 'encode'
Attempting to call `encode` or `decode` as a method of the removed `Multihash` class, or statically without providing `self`.
fix
These are now top-level functions. Call them as `multihash.encode(data, alg)` or `multihash.decode(mh)`.
Upgrade
Version history
3.0.0latest on PyPI · released Dec 17, 2025
Audit
Dependencies
py-multicodecrequiredProvides multicodec constants and decoding, essential for working with multihash algorithm codes.
py-multibaserequiredRequired for multibase encoding/decoding of multihash digests.
Agent activity
17 hits · last 30 days
node
14
Amazon
1
OpenAI (training)
1
Resources
py-multihash — pip install py-multihash · libregistry