{"library":"py-multihash","title":"Multihash for Python","description":"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.","language":"python","status":"active","last_verified":"Thu Apr 16","install":{"commands":["pip install py-multihash"],"cli":null},"imports":["from multihash import encode","from multihash import decode","from multihash import Digest","from multihash import encode, decode, Digest"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import multihash\nimport multicodec\n\n# Encode a byte string with a specific hash algorithm\ndata = b'Hello multihash world!'\nmh = multihash.encode(data, 'sha2-256')\nprint(f\"Encoded multihash: {mh.hex()}\")\n\n# Decode a multihash digest\ndecoded_digest = multihash.decode(mh)\nprint(f\"Decoded digest name: {decoded_digest.name}\")\nprint(f\"Decoded digest code: {hex(decoded_digest.code)}\")\nprint(f\"Decoded digest length: {decoded_digest.length}\")\nprint(f\"Original digest: {decoded_digest.digest.hex()}\")\n\n# Verify the algorithm code using multicodec constants\nassert decoded_digest.code == multicodec.SHA2_256\nprint(\"Verification successful!\")","lang":"python","description":"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.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}