Registry / serialization / multiformats

multiformats

JSON →
library0.3.1.post4pypypi✓ verified 84d ago

Python implementation of the multiformats protocols (multihash, multiaddr, multibase, multicodec, CID). Version 0.3.1.post4. Active development; releases every few months.

pip install multiformats
INSTALL
IMPORT
SIG · MULTIFORMATS
M
multiformats
serializationpythonv0.3.1.post4
Install
Import
Disk
Pass rate
0/ 10
Env Coverage0 / 10
glibc
3.93.13
musl
3.93.13
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
musl
glibc
py 3.10
1/2 runs
1/2 runs
py 3.11
1/2 runs
1/2 runs
py 3.12
1/2 runs
1/2 runs
py 3.13
1/2 runs
1/2 runs
py 3.9
1/2 runs
1/2 runs
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
Debug
Known issues
gotchaThe package installs without optional dependencies by default. Required hash functions (e.g., SHA2, SHA3) are not available unless you install multiformats[full] or the specific extra like sha2, sha3, blake2, etc.
fix
Run 'pip install multiformats[full]' to get all hash implementations, or install specific extras (e.g., multiformats[sha2]).
affects: >=0.1.4
breakingIn v0.2.0, the API for creating CIDs changed. CID() now expects the multibase code as a string (e.g., 'base32'), not a number. Old code using integer codes will fail.
fix
Use string multibase names: CID('base32', 'sha2-256', content). See quickstart.
affects: >=0.2.0
deprecatedThe multihash.decode() function returns a namedtuple; accessing fields by index is deprecated in future versions.
fix
Use named attributes: mh.code, mh.size, mh.digest instead of mh[0], mh[1], mh[2].
affects: >=0.3.0
Errors
Common errors & fixes
KeyError: 'sha2-256'
The hash function is not registered because optional dependencies are missing.
fix
Install 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.
fix
Use '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'.
fix
Use 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.

Agent activity
2 hits · last 30 days
node
2
Resources
multiformats — pip install multiformats · libregistry