Install & Compatibility
Where this runs
tested against v0.3.1.post4 · 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
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
multihash
✓ from multiformats import multihash
✗ import multihash
Multihash is a submodule, not a top-level package.
multiaddr
✓ from multiformats import multiaddr
✗ import multiaddr
Multiaddr is a submodule, not a top-level package.
multibase
✓ from multiformats import multibase
✗ import multibase
Multibase is a submodule, not a top-level package.
multicodec
✓ from multiformats import multicodec
✗ import multicodec
Multicodec is a submodule, not a top-level package.
CID
✓ from multiformats import CID
✗ from multiformats.cid import CID
CID is re-exported at the package level; no need to go into submodule.
Demonstrates basic multihash, multibase, and CID creation/decoding.
from multiformats import multihash, multibase, CID
# Create a multihash (SHA2-256, 32 bytes)
digest = b'\x12' + b'\x20' + (b'x' * 32)
mh = multihash.decode(digest)
print(f"Hash function: {mh.code}, digest size: {mh.size}")
# Encode to multibase (base58btc)
encoded = multibase.encode('base58btc', digest)
print(f"Encoded: {encoded}")
# Create a CIDv1
cid = CID('base32', 'sha2-256', b'x' * 32)
print(f"CID: {cid}")
# Validate
assert cid.version == 1
Errors
Common errors & fixes
KeyError: 'sha2-256'
The hash function is not registered because optional dependencies are missing.
fixInstall the required hash extra, e.g., pip install multiformats[sha2].
ModuleNotFoundError: No module named 'multihash'
Attempted to import multihash as a standalone package, but it is a submodule of multiformats.
fixUse 'from multiformats import multihash' instead.
TypeError: CID() got an unexpected keyword argument 'codec'
Older code used 'codec' parameter; in v0.2.0+ the parameter is 'multicodec'.
fixUse CID('base32', 'sha2-256', content) – the second positional argument is the multicodec name, not a keyword 'codec'. Upgrade
Version history
0.3.1.post4latest on PyPI · released Dec 20, 2023
Audit
Dependencies
No dependency data recorded yet.