{"id":24086,"library":"multiformats","title":"Multiformats","description":"Python implementation of the multiformats protocols (multihash, multiaddr, multibase, multicodec, CID). Version 0.3.1.post4. Active development; releases every few months.","status":"active","version":"0.3.1.post4","language":"python","source_language":"en","source_url":"https://github.com/hashberg-io/multiformats","tags":["multiformats","multihash","multiaddr","multibase","multicodec","CID","IPFS"],"install":[{"cmd":"pip install multiformats","lang":"bash","label":"Base install"},{"cmd":"pip install multiformats[full]","lang":"bash","label":"With all hash function dependencies"}],"dependencies":[],"imports":[{"note":"Multihash is a submodule, not a top-level package.","wrong":"import multihash","symbol":"multihash","correct":"from multiformats import multihash"},{"note":"Multiaddr is a submodule, not a top-level package.","wrong":"import multiaddr","symbol":"multiaddr","correct":"from multiformats import multiaddr"},{"note":"Multibase is a submodule, not a top-level package.","wrong":"import multibase","symbol":"multibase","correct":"from multiformats import multibase"},{"note":"Multicodec is a submodule, not a top-level package.","wrong":"import multicodec","symbol":"multicodec","correct":"from multiformats import multicodec"},{"note":"CID is re-exported at the package level; no need to go into submodule.","wrong":"from multiformats.cid import CID","symbol":"CID","correct":"from multiformats import CID"}],"quickstart":{"code":"from multiformats import multihash, multibase, CID\n\n# Create a multihash (SHA2-256, 32 bytes)\ndigest = b'\\x12' + b'\\x20' + (b'x' * 32)\nmh = multihash.decode(digest)\nprint(f\"Hash function: {mh.code}, digest size: {mh.size}\")\n\n# Encode to multibase (base58btc)\nencoded = multibase.encode('base58btc', digest)\nprint(f\"Encoded: {encoded}\")\n\n# Create a CIDv1\ncid = CID('base32', 'sha2-256', b'x' * 32)\nprint(f\"CID: {cid}\")\n\n# Validate\nassert cid.version == 1","lang":"python","description":"Demonstrates basic multihash, multibase, and CID creation/decoding."},"warnings":[{"fix":"Run 'pip install multiformats[full]' to get all hash implementations, or install specific extras (e.g., multiformats[sha2]).","message":"The 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.","severity":"gotcha","affected_versions":">=0.1.4"},{"fix":"Use string multibase names: CID('base32', 'sha2-256', content). See quickstart.","message":"In 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.","severity":"breaking","affected_versions":">=0.2.0"},{"fix":"Use named attributes: mh.code, mh.size, mh.digest instead of mh[0], mh[1], mh[2].","message":"The multihash.decode() function returns a namedtuple; accessing fields by index is deprecated in future versions.","severity":"deprecated","affected_versions":">=0.3.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Install the required hash extra, e.g., pip install multiformats[sha2].","cause":"The hash function is not registered because optional dependencies are missing.","error":"KeyError: 'sha2-256'"},{"fix":"Use 'from multiformats import multihash' instead.","cause":"Attempted to import multihash as a standalone package, but it is a submodule of multiformats.","error":"ModuleNotFoundError: No module named 'multihash'"},{"fix":"Use CID('base32', 'sha2-256', content) – the second positional argument is the multicodec name, not a keyword 'codec'.","cause":"Older code used 'codec' parameter; in v0.2.0+ the parameter is 'multicodec'.","error":"TypeError: CID() got an unexpected keyword argument 'codec'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}