{"id":24366,"library":"pymultihash","title":"pymultihash","description":"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.","status":"active","version":"0.8.2","language":"python","source_language":"en","source_url":"https://github.com/ivilata/pymultihash","tags":["multihash","hashing","ipfs","self-describing"],"install":[{"cmd":"pip install pymultihash","lang":"bash","label":"Install from PyPI"}],"dependencies":[],"imports":[{"note":"The package provides a top-level module `multihash`, not a submodule under `pymultihash`.","wrong":"from pymultihash import multihash","symbol":"multihash","correct":"import multihash"}],"quickstart":{"code":"import multihash\n\n# Hash data using SHA2-256 (code 0x12)\ndigest = multihash.digest(b'hello world', 'sha2-256')\nprint(digest.hex())  # multihash encoded\n\n# Decode a multihash\ndecoded = multihash.decode(digest)\nprint(decoded.code)  # 0x12\nprint(decoded.digest.hex())  # raw digest\n\n# Hash with a specific length (truncated)\ndigest_trunc = multihash.digest(b'hello world', 'sha2-256', 8)\nprint(len(digest_trunc))  # 1 (varint code) + 1 (length) + 8 = 10 bytes","lang":"python","description":"Encode and decode multihashes using the standard functions."},"warnings":[{"fix":"Use `multihash.decode()` to extract the raw digest, or use `hashlib` for raw hashing and then `multihash.encode()` to wrap it.","message":"The `digest` function returns a multihash-encoded byte string (with code and length prefix), not a raw hash digest. This differs from other multihash libraries.","severity":"gotcha","affected_versions":"all"},{"fix":"Use the exact names as defined in the multihash table: 'sha1', 'sha2-256', 'sha2-512', 'sha3-512', 'blake2b-256', etc.","message":"Hash function names are lowercase with hyphens (e.g., 'sha2-256', 'sha3-512'). Using incorrect casing (e.g., 'SHA256') raises a ValueError.","severity":"gotcha","affected_versions":"all"},{"fix":"Monitor the repo for API changes; no breaking changes have occurred yet.","message":"The `encode` and `decode` functions may be renamed or deprecated in future versions. Check the latest documentation.","severity":"deprecated","affected_versions":"0.8.x"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Ensure the input to `decode()` is a complete multihash-encoded byte string, not a raw hash. Use `digest()` to create a valid multihash.","cause":"Passing a raw digest (without the multihash code+length prefix) to `decode()`.","error":"ValueError: Unknown multihash code: 0x12"},{"fix":"Use `import multihash` (the package exposes a top-level module).","cause":"Using incorrect import path (e.g., `from pymultihash import multihash`).","error":"NameError: name 'multihash' is not defined"},{"fix":"Use the full multihash name: 'sha2-256', 'sha2-512', 'sha3-512', etc.","cause":"Using an incorrect hash function name (common mistake: using 'sha256' instead of 'sha2-256').","error":"ValueError: Unsupported hash function: sha256"},{"fix":"Use `multihash.digest(data, 'sha2-256', length=16)` instead of positional third argument.","cause":"The third argument `length` is optional but must be passed as a keyword argument if provided.","error":"TypeError: digest() takes 2 positional arguments but 3 were given"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}