{"id":17673288,"url":"https://github.com/hashberg-io/multiformats","last_synced_at":"2025-04-14T20:20:46.608Z","repository":{"id":57443940,"uuid":"408955666","full_name":"hashberg-io/multiformats","owner":"hashberg-io","description":"Python implementation of multiformat protocols.","archived":false,"fork":false,"pushed_at":"2024-07-20T11:59:37.000Z","size":1099,"stargazers_count":28,"open_issues_count":1,"forks_count":6,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-05T18:58:58.932Z","etag":null,"topics":["ipld","multiformats","python"],"latest_commit_sha":null,"homepage":"https://multiformats.readthedocs.io","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hashberg-io.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-09-21T19:52:20.000Z","updated_at":"2025-03-26T14:12:57.000Z","dependencies_parsed_at":"2023-12-18T21:38:00.093Z","dependency_job_id":"820b0d65-1ee1-4438-b32f-ee15480dd0ba","html_url":"https://github.com/hashberg-io/multiformats","commit_stats":{"total_commits":76,"total_committers":4,"mean_commits":19.0,"dds":0.03947368421052633,"last_synced_commit":"1ed633b922a7c9e99c485ec59b6efefb84141ff5"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hashberg-io%2Fmultiformats","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hashberg-io%2Fmultiformats/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hashberg-io%2Fmultiformats/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hashberg-io%2Fmultiformats/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hashberg-io","download_url":"https://codeload.github.com/hashberg-io/multiformats/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248952345,"owners_count":21188427,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ipld","multiformats","python"],"created_at":"2024-10-24T05:08:53.148Z","updated_at":"2025-04-14T20:20:46.589Z","avatar_url":"https://github.com/hashberg-io.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"multiformats: Python implementation of `multiformat protocols \u003chttps://multiformats.io/\u003e`_\n============================================================================================\n\n.. image:: https://img.shields.io/badge/python-3.7+-green.svg\n    :target: https://docs.python.org/3.7/\n    :alt: Python versions\n\n.. image:: https://img.shields.io/pypi/v/multiformats.svg\n    :target: https://pypi.python.org/pypi/multiformats/\n    :alt: PyPI version\n\n.. image:: https://img.shields.io/pypi/status/multiformats.svg\n    :target: https://pypi.python.org/pypi/multiformats/\n    :alt: PyPI status\n\n.. image:: http://www.mypy-lang.org/static/mypy_badge.svg\n    :target: https://github.com/python/mypy\n    :alt: Checked with Mypy\n    \n.. image:: https://readthedocs.org/projects/multiformats/badge/?version=latest\n    :target: https://multiformats.readthedocs.io/en/latest/?badge=latest\n    :alt: Documentation Status\n\n.. image:: https://github.com/hashberg-io/multiformats/actions/workflows/python-pytest.yml/badge.svg\n    :target: https://github.com/hashberg-io/multiformats/actions/workflows/python-pytest.yml\n    :alt: Python package status\n\n.. image:: https://img.shields.io/badge/readme%20style-standard-brightgreen.svg?style=flat-square\n    :target: https://github.com/RichardLitt/standard-readme\n    :alt: standard-readme compliant\n\n\nMultiformats is a compliant implementation of `multiformat protocols \u003chttps://multiformats.io/\u003e`_:\n\n.. contents::\n\n\nInstall\n-------\n\nYou can install the latest release from `PyPI \u003chttps://pypi.org/project/multiformats/\u003e`_ as follows:\n\n.. code-block:: console\n\n    $ pip install --upgrade multiformats\n\nThe following are mandatory dependencies for this module:\n\n- `typing-extensions \u003chttps://github.com/python/typing_extensions\u003e`_, for backward compatibility of static typing.\n- `typing-validation \u003chttps://github.com/hashberg-io/typing-validation\u003e`_, for dynamic typechecking\n- `bases \u003chttps://github.com/hashberg-io/bases\u003e`_, for implementation of base encodings used by Multibase\n\nThe following are optional dependencies for this module:\n\n- `blake3 \u003chttps://github.com/oconnor663/blake3-py\u003e`_, for the ``blake3`` hash function.\n- `pyskein \u003chttps://pythonhosted.org/pyskein/\u003e`_, for the ``skein`` hash functions.\n- `mmh3 \u003chttps://github.com/hajimes/mmh3\u003e`_, for the ``murmur3`` hash functions.\n- `pycryptodomex \u003chttps://github.com/Legrandin/pycryptodome/\u003e`_, for the ``ripemd-160`` hash function, \\\n  the ``kangarootwelve`` hash function, the ``keccak`` hash functions and the ``sha2-512-224``/``sha2-512-256`` hash functions.\n\nYou can install the latest release together with all optional dependencies as follows:\n\n.. code-block:: console\n\n    $ pip install --upgrade multiformats[full]\n\n\nUsage\n-----\n\nYou can import multiformat protocols directly from top level:\n\n\u003e\u003e\u003e from multiformats import *\n\nThe above will import the following names:\n\n.. code-block:: python\n\n    varint, multicodec, multibase, multihash, multiaddr, CID\n\nThe first five are modules implementing the homonymous specifications, while ``CID`` is a class for Content IDentifiers.\nBelow are some basic usage examples, to get you started: for detailed documentation, see https://multiformats.readthedocs.io/\n\n\nVarint encode/decode\n^^^^^^^^^^^^^^^^^^^^\n\n\u003e\u003e\u003e varint.encode(128)\nb'\\x80\\x01'\n\u003e\u003e\u003e varint.decode(b'\\x80\\x01')\n128\n\n\nMulticodec wrap/unwrap\n^^^^^^^^^^^^^^^^^^^^^^\n\nProcedural style:\n\n\u003e\u003e\u003e raw_data = bytes([192, 168, 0, 254])\n\u003e\u003e\u003e multicodec_data = multicodec.wrap(\"ip4\", raw_data)\n\u003e\u003e\u003e raw_data.hex()\n  'c0a800fe'\n\u003e\u003e\u003e multicodec_data.hex()\n'04c0a800fe'\n\u003e\u003e\u003e codec, _raw_data = multicodec.unwrap(multicodec_data)\n\u003e\u003e\u003e _raw_data.hex()\n  'c0a800fe'\n\u003e\u003e\u003e codec\nMulticodec(name='ip4', tag='multiaddr', code='0x04',\n           status='permanent', description='')\n\nObject-oriented style:\n\n\u003e\u003e\u003e ip4 = multicodec.get(\"ip4\")\n\u003e\u003e\u003e ip4\nMulticodec(name='ip4', tag='multiaddr', code='0x04',\n           status='permanent', description='')\n\u003e\u003e\u003e raw_data = bytes([192, 168, 0, 254])\n\u003e\u003e\u003e multicodec_data = ip4.wrap(raw_data)\n\u003e\u003e\u003e raw_data.hex()\n  'c0a800fe'\n\u003e\u003e\u003e multicodec_data.hex()\n'04c0a800fe'\n\u003e\u003e\u003e ip4.unwrap(multicodec_data).hex()\n  'c0a800fe'\n\n\nMultibase encode/decode\n^^^^^^^^^^^^^^^^^^^^^^^\n\nProcedural style:\n\n\u003e\u003e\u003e multibase.encode(b\"Hello World!\", \"base32\")\n'bjbswy3dpeblw64tmmqqq'\n\u003e\u003e\u003e multibase.decode('bjbswy3dpeblw64tmmqqq')\nb'Hello World!'\n\nObject-oriented style:\n\n\u003e\u003e\u003e base32 = multibase.get(\"base32\")\n\u003e\u003e\u003e base32.encode(b\"Hello World!\")\n'bjbswy3dpeblw64tmmqqq'\n\u003e\u003e\u003e base32.decode('bjbswy3dpeblw64tmmqqq')\nb'Hello World!'\n\nObject-oriented style without prefix:\n\n\u003e\u003e\u003e multibase.get(\"base64url\").raw_decoder(\"1IFOwqNRAXr7bxkzsaUP4c5TsfODswA3L8EZYoaWP08\")\nb'\\xd4\\x81N\\xc2\\xa3Q\\x01z\\xfbo\\x193\\xb1\\xa5\\x0f\\xe1\\xceS\\xb1\\xf3\\x83\\xb3\\x007/\\xc1\\x19b\\x86\\x96?O'\n\n\nMultihash digest\n^^^^^^^^^^^^^^^^\n\nProcedural style:\n\n\u003e\u003e\u003e data = b\"Hello world!\"\n\u003e\u003e\u003e digest = multihash.digest(data, \"sha2-256\")\n\u003e\u003e\u003e digest.hex()\n'1220c0535e4be2b79ffd93291305436bf889314e4a3faec05ecffcbb7df31ad9e51a'\n\nObject-oriented style:\n\n\u003e\u003e\u003e sha2_256 = multihash.get(\"sha2-256\")\n\u003e\u003e\u003e digest = sha2_256.digest(data)\n\u003e\u003e\u003e digest.hex()\n'1220c0535e4be2b79ffd93291305436bf889314e4a3faec05ecffcbb7df31ad9e51a'\n\nOptional truncated digests:\n\n\u003e\u003e\u003e digest = multihash.digest(data, \"sha2-256\", size=20)\n#        optional truncated hash size, in bytes ^^^^^^^\n\u003e\u003e\u003e digest.hex()\n'1214c0535e4be2b79ffd93291305436bf889314e4a3f'\n\n\nMultihash wrap/unwrap\n^^^^^^^^^^^^^^^^^^^^^\n\nProcedural style:\n\n\u003e\u003e\u003e digest.hex()\n'1214c0535e4be2b79ffd93291305436bf889314e4a3f'\n\u003e\u003e\u003e raw_digest = multihash.unwrap(digest)\n\u003e\u003e\u003e raw_digest.hex()\n    'c0535e4be2b79ffd93291305436bf889314e4a3f'\n\u003e\u003e\u003e multihash.wrap(raw_digest, \"sha2-256\").hex()\n'1214c0535e4be2b79ffd93291305436bf889314e4a3f'\n\nObject-oriented style:\n\n\u003e\u003e\u003e sha2_256 = multihash.get(\"sha2-256\")\n\u003e\u003e\u003e raw_digest = sha2_256.unwrap(digest)\n\u003e\u003e\u003e raw_digest.hex()\n    'c0535e4be2b79ffd93291305436bf889314e4a3f'\n\u003e\u003e\u003e sha2_256.wrap(raw_digest).hex()\n'1214c0535e4be2b79ffd93291305436bf889314e4a3f'\n\n\nCID encode/decode\n^^^^^^^^^^^^^^^^^\n\nDecoding from multibase encoded strings:\n\n\u003e\u003e\u003e cid = CID.decode(\"zb2rhe5P4gXftAwvA4eXQ5HJwsER2owDyS9sKaQRRVQPn93bA\")\n\u003e\u003e\u003e cid\nCID('base58btc', 1, 'raw',\n  '12206e6ff7950a36187a801613426e858dce686cd7d7e3c0fc42ee0330072d245c95')\n\u003e\u003e\u003e cid.base\nMultibase(name='base58btc', code='z',\n          status='default', description='base58 bitcoin')\n\u003e\u003e\u003e cid.codec\nMulticodec(name='raw', tag='ipld', code='0x55',\n           status='permanent', description='raw binary')\n\u003e\u003e\u003e cid.digest.hex()\n'12206e6ff7950a36187a801613426e858dce686cd7d7e3c0fc42ee0330072d245c95'\n\u003e\u003e\u003e cid.hashfun\nMulticodec(name='sha2-256', tag='multihash', code='0x12',\n           status='permanent', description='')\n\u003e\u003e\u003e cid.raw_digest.hex()\n    '6e6ff7950a36187a801613426e858dce686cd7d7e3c0fc42ee0330072d245c95'\n\nMultibase encoding:\n\n\u003e\u003e\u003e str(cid) # encode with own multibase 'base58btc'\n'zb2rhe5P4gXftAwvA4eXQ5HJwsER2owDyS9sKaQRRVQPn93bA'\n\u003e\u003e\u003e cid.encode(\"base32\") # encode with different multibase\n'bafkreidon73zkcrwdb5iafqtijxildoonbwnpv7dyd6ef3qdgads2jc4su'\n\n\nPeerID creation\n^^^^^^^^^^^^^^^\n\nCreation of `CIDv1 PeerIDs \u003chttps://docs.libp2p.io/concepts/peer-id/\u003e`_:\n\n\u003e\u003e\u003e pk_bytes = bytes.fromhex( # hex-string of 32-byte Ed25519 public key\n... \"1498b5467a63dffa2dc9d9e069caf075d16fc33fdd4c3b01bfadae6433767d93\")\n\u003e\u003e\u003e peer_id = CID.peer_id(pk_bytes)\n\u003e\u003e\u003e peer_id\nCID('base32', 1, 'libp2p-key',\n'00201498b5467a63dffa2dc9d9e069caf075d16fc33fdd4c3b01bfadae6433767d93')\n#^^   0x00 = 'identity' multihash used (public key length \u003c= 42)\n#  ^^ 0x20 = 32-bytes of raw hash digest length\n\u003e\u003e\u003e str(peer_id)\n'bafzaaiautc2um6td375c3soz4bu4v4dv2fx4gp65jq5qdp5nvzsdg5t5sm'\n\n\nMultiaddr parse/decode\n^^^^^^^^^^^^^^^^^^^^^^\n\n\u003e\u003e\u003e s = '/ip4/127.0.0.1/udp/9090/quic'\n\u003e\u003e\u003e multiaddr.parse(s)\nMultiaddr(Addr('ip4', '127.0.0.1'), Addr('udp', '9090'), Proto('quic'))\n\u003e\u003e\u003e b = bytes.fromhex('047f00000191022382cc03')\n\u003e\u003e\u003e multiaddr.decode(b)\nMultiaddr(Addr('ip4', '127.0.0.1'), Addr('udp', '9090'), Proto('quic'))\n\n\nMultiaddr protocols/addresses\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\nAccessing multiaddr protocols:\n\n\u003e\u003e\u003e ip4 = multiaddr.proto(\"ip4\")\n\u003e\u003e\u003e ip4\nProto(\"ip4\")\n\u003e\u003e\u003e udp = multiaddr.proto(\"udp\")\n\u003e\u003e\u003e quic = multiaddr.proto(\"quic\")\n\nCreating protocol addresses from human-readable strings:\n\n\u003e\u003e\u003e a = ip4/\"192.168.1.1\"\n\u003e\u003e\u003e a\nAddr('ip4', '192.168.1.1')\n\u003e\u003e\u003e str(a)\n'/ip4/192.168.1.1'\n\u003e\u003e\u003e a.value\n'192.168.1.1'\n\u003e\u003e\u003e bytes(a).hex()\n'04c0a80101'\n\u003e\u003e\u003e a.value_bytes.hex()\n  'c0a80101'\n\nCreating protocol addresses from bytestrings:\n\n\u003e\u003e\u003e a = ip4/bytes([192, 168, 1, 1])\n\u003e\u003e\u003e a\nAddr('ip4', '192.168.1.1')\n\n\nMultiaddr encapsulation/decapsulation\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\nCreating multiaddresses by protocol encapsulation:\n\n\u003e\u003e\u003e ma = ip4/\"127.0.0.1\"/udp/9090/quic\n\u003e\u003e\u003e ma\nMultiaddr(Addr('ip4', '127.0.0.1'), Addr('udp', '9090'), Proto('quic'))\n\u003e\u003e\u003e str(ma)\n'/ip4/127.0.0.1/udp/9090/quic'\n\nBytes for multiaddrs are computed according to the `(TLV)+ multiaddr format \u003chttps://multiformats.io/multiaddr/\u003e`_:\n\n\u003e\u003e\u003e bytes(ip4/\"127.0.0.1\").hex()\n'047f000001'\n\u003e\u003e\u003e bytes(udp/9090).hex()\n          '91022382'\n\u003e\u003e\u003e bytes(quic).hex()\n                  'cc03'\n\u003e\u003e\u003e bytes(ma).hex()\n'047f00000191022382cc03'\n\nProtocol decapsulation by indexing and slicing:\n\n\u003e\u003e\u003e ma[0]\nAddr('ip4', '127.0.0.1')\n\u003e\u003e\u003e ma[:2]\nMultiaddr(Addr('ip4', '127.0.0.1'), Addr('udp', '9090'))\n\u003e\u003e\u003e ma[1:]\nMultiaddr(Addr('udp', '9090'), Proto('quic'))\n\n\nAPI\n---\n\nFor the full API documentation, see https://multiformats.readthedocs.io/\n\nThe tables specifying all multicodecs and multibases known to this package are maintained as part of the `multiformats-config \u003chttps://github.com/hashberg-io/multiformats-config\u003e`_ repository.\n\n\nContributing\n------------\n\nPlease see `\u003cCONTRIBUTING.md\u003e`_.\n\n\nLicense\n-------\n\n`MIT © Hashberg Ltd. \u003cLICENSE\u003e`_\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhashberg-io%2Fmultiformats","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhashberg-io%2Fmultiformats","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhashberg-io%2Fmultiformats/lists"}