multiformats: Python implementation of `multiformat protocols <https://multiformats.io/>`_
============================================================================================
.. image:: https://img.shields.io/badge/python-3.7+-green.svg
:target: https://docs.python.org/3.7/
:alt: Python versions
.. image:: https://img.shields.io/pypi/v/multiformats.svg
:target: https://pypi.python.org/pypi/multiformats/
:alt: PyPI version
.. image:: https://img.shields.io/pypi/status/multiformats.svg
:target: https://pypi.python.org/pypi/multiformats/
:alt: PyPI status
.. image:: http://www.mypy-lang.org/static/mypy_badge.svg
:target: https://github.com/python/mypy
:alt: Checked with Mypy
.. image:: https://readthedocs.org/projects/multiformats/badge/?version=latest
:target: https://multiformats.readthedocs.io/en/latest/?badge=latest
:alt: Documentation Status
.. image:: https://github.com/hashberg-io/multiformats/actions/workflows/python-pytest.yml/badge.svg
:target: https://github.com/hashberg-io/multiformats/actions/workflows/python-pytest.yml
:alt: Python package status
.. image:: https://img.shields.io/badge/readme%20style-standard-brightgreen.svg?style=flat-square
:target: https://github.com/RichardLitt/standard-readme
:alt: standard-readme compliant
Multiformats is a compliant implementation of `multiformat protocols <https://multiformats.io/>`_:
.. contents::
Install
-------
You can install the latest release from `PyPI <https://pypi.org/project/multiformats/>`_ as follows:
.. code-block:: console
$ pip install --upgrade multiformats
The following are mandatory dependencies for this module:
- `typing-extensions <https://github.com/python/typing_extensions>`_, for backward compatibility of static typing.
- `typing-validation <https://github.com/hashberg-io/typing-validation>`_, for dynamic typechecking
- `bases <https://github.com/hashberg-io/bases>`_, for implementation of base encodings used by Multibase
The following are optional dependencies for this module:
- `blake3 <https://github.com/oconnor663/blake3-py>`_, for the ``blake3`` hash function.
- `pyskein <https://pythonhosted.org/pyskein/>`_, for the ``skein`` hash functions.
- `mmh3 <https://github.com/hajimes/mmh3>`_, for the ``murmur3`` hash functions.
- `pycryptodomex <https://github.com/Legrandin/pycryptodome/>`_, for the ``ripemd-160`` hash function, \
the ``kangarootwelve`` hash function, the ``keccak`` hash functions and the ``sha2-512-224``/``sha2-512-256`` hash functions.
You can install the latest release together with all optional dependencies as follows:
.. code-block:: console
$ pip install --upgrade multiformats[full]
Usage
-----
You can import multiformat protocols directly from top level:
>>> from multiformats import *
The above will import the following names:
.. code-block:: python
varint, multicodec, multibase, multihash, multiaddr, CID
The first five are modules implementing the homonymous specifications, while ``CID`` is a class for Content IDentifiers.
Below are some basic usage examples, to get you started: for detailed documentation, see https://multiformats.readthedocs.io/
Varint encode/decode
^^^^^^^^^^^^^^^^^^^^
>>> varint.encode(128)
b'\x80\x01'
>>> varint.decode(b'\x80\x01')
128
Multicodec wrap/unwrap
^^^^^^^^^^^^^^^^^^^^^^
Procedural style:
>>> raw_data = bytes([192, 168, 0, 254])
>>> multicodec_data = multicodec.wrap("ip4", raw_data)
>>> raw_data.hex()
'c0a800fe'
>>> multicodec_data.hex()
'04c0a800fe'
>>> codec, _raw_data = multicodec.unwrap(multicodec_data)
>>> _raw_data.hex()
'c0a800fe'
>>> codec
Multicodec(name='ip4', tag='multiaddr', code='0x04',
status='permanent', description='')
Object-oriented style:
>>> ip4 = multicodec.get("ip4")
>>> ip4
Multicodec(name='ip4', tag='multiaddr', code='0x04',
status='permanent', description='')
>>> raw_data = bytes([192, 168, 0, 254])
>>> multicodec_data = ip4.wrap(raw_data)
>>> raw_data.hex()
'c0a800fe'
>>> multicodec_data.hex()
'04c0a800fe'
>>> ip4.unwrap(multicodec_data).hex()
'c0a800fe'
Multibase encode/decode
^^^^^^^^^^^^^^^^^^^^^^^
Procedural style:
>>> multibase.encode(b"Hello World!", "base32")
'bjbswy3dpeblw64tmmqqq'
>>> multibase.decode('bjbswy3dpeblw64tmmqqq')
b'Hello World!'
Object-oriented style:
>>> base32 = multibase.get("base32")
>>> base32.encode(b"Hello World!")
'bjbswy3dpeblw64tmmqqq'
>>> base32.decode('bjbswy3dpeblw64tmmqqq')
b'Hello World!'
Multihash digest
^^^^^^^^^^^^^^^^
Procedural style:
>>> data = b"Hello world!"
>>> digest = multihash.digest(data, "sha2-256")
>>> digest.hex()
'1220c0535e4be2b79ffd93291305436bf889314e4a3faec05ecffcbb7df31ad9e51a'
Object-oriented style:
>>> sha2_256 = multihash.get("sha2-256")
>>> digest = sha2_256.digest(data)
>>> digest.hex()
'1220c0535e4be2b79ffd93291305436bf889314e4a3faec05ecffcbb7df31ad9e51a'
Optional truncated digests:
>>> digest = multihash.digest(data, "sha2-256", size=20)
# optional truncated hash size, in bytes ^^^^^^^
>>> digest.hex()
'1214c0535e4be2b79ffd93291305436bf889314e4a3f'
Multihash wrap/unwrap
^^^^^^^^^^^^^^^^^^^^^
Procedural style:
>>> digest.hex()
'1214c0535e4be2b79ffd93291305436bf889314e4a3f'
>>> raw_digest = multihash.unwrap(digest)
>>> raw_digest.hex()
'c0535e4be2b79ffd93291305436bf889314e4a3f'
>>> multihash.wrap(raw_digest, "sha2-256").hex()
'1214c0535e4be2b79ffd93291305436bf889314e4a3f'
Object-oriented style:
>>> sha2_256 = multihash.get("sha2-256")
>>> raw_digest = sha2_256.unwrap(digest)
>>> raw_digest.hex()
'c0535e4be2b79ffd93291305436bf889314e4a3f'
>>> sha2_256.wrap(raw_digest).hex()
'1214c0535e4be2b79ffd93291305436bf889314e4a3f'
CID encode/decode
^^^^^^^^^^^^^^^^^
Decoding from multibase encoded strings:
>>> cid = CID.decode("zb2rhe5P4gXftAwvA4eXQ5HJwsER2owDyS9sKaQRRVQPn93bA")
>>> cid
CID('base58btc', 1, 'raw',
'12206e6ff7950a36187a801613426e858dce686cd7d7e3c0fc42ee0330072d245c95')
>>> cid.base
Multibase(name='base58btc', code='z',
status='default', description='base58 bitcoin')
>>> cid.codec
Multicodec(name='raw', tag='ipld', code='0x55',
status='permanent', description='raw binary')
>>> cid.digest.hex()
'12206e6ff7950a36187a801613426e858dce686cd7d7e3c0fc42ee0330072d245c95'
>>> cid.hashfun
Multicodec(name='sha2-256', tag='multihash', code='0x12',
status='permanent', description='')
>>> cid.raw_digest.hex()
'6e6ff7950a36187a801613426e858dce686cd7d7e3c0fc42ee0330072d245c95'
Multibase encoding:
>>> str(cid) # encode with own multibase 'base58btc'
'zb2rhe5P4gXftAwvA4eXQ5HJwsER2owDyS9sKaQRRVQPn93bA'
>>> cid.encode("base32") # encode with different multibase
'bafkreidon73zkcrwdb5iafqtijxildoonbwnpv7dyd6ef3qdgads2jc4su'
PeerID creation
^^^^^^^^^^^^^^^
Creation of `CIDv1 PeerIDs <https://docs.libp2p.io/concepts/peer-id/>`_:
>>> pk_bytes = bytes.fromhex( # hex-string of 32-byte Ed25519 public key
... "1498b5467a63dffa2dc9d9e069caf075d16fc33fdd4c3b01bfadae6433767d93")
>>> peer_id = CID.peer_id(pk_bytes)
>>> peer_id
CID('base32', 1, 'libp2p-key',
'00201498b5467a63dffa2dc9d9e069caf075d16fc33fdd4c3b01bfadae6433767d93')
#^^ 0x00 = 'identity' multihash used (public key length <= 42)
# ^^ 0x20 = 32-bytes of raw hash digest length
>>> str(peer_id)
'bafzaaiautc2um6td375c3soz4bu4v4dv2fx4gp65jq5qdp5nvzsdg5t5sm'
Multiaddr parse/decode
^^^^^^^^^^^^^^^^^^^^^^
>>> s = '/ip4/127.0.0.1/udp/9090/quic'
>>> multiaddr.parse(s)
Multiaddr(Addr('ip4', '127.0.0.1'), Addr('udp', '9090'), Proto('quic'))
>>> b = bytes.fromhex('047f00000191022382cc03')
>>> multiaddr.decode(b)
Multiaddr(Addr('ip4', '127.0.0.1'), Addr('udp', '9090'), Proto('quic'))
Multiaddr protocols/addresses
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Accessing multiaddr protocols:
>>> ip4 = multiaddr.proto("ip4")
>>> ip4
Proto("ip4")
>>> udp = multiaddr.proto("udp")
>>> quic = multiaddr.proto("quic")
Creating protocol addresses from human-readable strings:
>>> a = ip4/"192.168.1.1"
>>> a
Addr('ip4', '192.168.1.1')
>>> str(a)
'/ip4/192.168.1.1'
>>> a.value
'192.168.1.1'
>>> bytes(a).hex()
'04c0a80101'
>>> a.value_bytes.hex()
'c0a80101'
Creating protocol addresses from bytestrings:
>>> a = ip4/bytes([192, 168, 1, 1])
>>> a
Addr('ip4', '192.168.1.1')
Multiaddr encapsulation/decapsulation
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Creating multiaddresses by protocol encapsulation:
>>> ma = ip4/"127.0.0.1"/udp/9090/quic
>>> ma
Multiaddr(Addr('ip4', '127.0.0.1'), Addr('udp', '9090'), Proto('quic'))
>>> str(ma)
'/ip4/127.0.0.1/udp/9090/quic'
Bytes for multiaddrs are computed according to the `(TLV)+ multiaddr format <https://multiformats.io/multiaddr/>`_:
>>> bytes(ip4/"127.0.0.1").hex()
'047f000001'
>>> bytes(udp/9090).hex()
'91022382'
>>> bytes(quic).hex()
'cc03'
>>> bytes(ma).hex()
'047f00000191022382cc03'
Protocol decapsulation by indexing and slicing:
>>> ma[0]
Addr('ip4', '127.0.0.1')
>>> ma[:2]
Multiaddr(Addr('ip4', '127.0.0.1'), Addr('udp', '9090'))
>>> ma[1:]
Multiaddr(Addr('udp', '9090'), Proto('quic'))
API
---
For the full API documentation, see https://multiformats.readthedocs.io/
The tables specifying all multicodecs and multibases known to this package are maintained as part of the `multiformats-config <https://github.com/hashberg-io/multiformats-config>`_ repository.
Contributing
------------
Please see `<CONTRIBUTING.md>`_.
License
-------
`MIT © Hashberg Ltd. <LICENSE>`_
Raw data
{
"_id": null,
"home_page": "https://github.com/hashberg-io/multiformats",
"name": "multiformats",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": "",
"keywords": "",
"author": "hashberg",
"author_email": "sg495@users.noreply.github.com",
"download_url": "https://files.pythonhosted.org/packages/b2/41/2efc6e99fa2ed9f1a47fbfed5d124215e35db0a849585db72eeb1490de0e/multiformats-0.3.1.post4.tar.gz",
"platform": null,
"description": "multiformats: Python implementation of `multiformat protocols <https://multiformats.io/>`_\r\n============================================================================================\r\n\r\n.. image:: https://img.shields.io/badge/python-3.7+-green.svg\r\n :target: https://docs.python.org/3.7/\r\n :alt: Python versions\r\n\r\n.. image:: https://img.shields.io/pypi/v/multiformats.svg\r\n :target: https://pypi.python.org/pypi/multiformats/\r\n :alt: PyPI version\r\n\r\n.. image:: https://img.shields.io/pypi/status/multiformats.svg\r\n :target: https://pypi.python.org/pypi/multiformats/\r\n :alt: PyPI status\r\n\r\n.. image:: http://www.mypy-lang.org/static/mypy_badge.svg\r\n :target: https://github.com/python/mypy\r\n :alt: Checked with Mypy\r\n \r\n.. image:: https://readthedocs.org/projects/multiformats/badge/?version=latest\r\n :target: https://multiformats.readthedocs.io/en/latest/?badge=latest\r\n :alt: Documentation Status\r\n\r\n.. image:: https://github.com/hashberg-io/multiformats/actions/workflows/python-pytest.yml/badge.svg\r\n :target: https://github.com/hashberg-io/multiformats/actions/workflows/python-pytest.yml\r\n :alt: Python package status\r\n\r\n.. image:: https://img.shields.io/badge/readme%20style-standard-brightgreen.svg?style=flat-square\r\n :target: https://github.com/RichardLitt/standard-readme\r\n :alt: standard-readme compliant\r\n\r\n\r\nMultiformats is a compliant implementation of `multiformat protocols <https://multiformats.io/>`_:\r\n\r\n.. contents::\r\n\r\n\r\nInstall\r\n-------\r\n\r\nYou can install the latest release from `PyPI <https://pypi.org/project/multiformats/>`_ as follows:\r\n\r\n.. code-block:: console\r\n\r\n $ pip install --upgrade multiformats\r\n\r\nThe following are mandatory dependencies for this module:\r\n\r\n- `typing-extensions <https://github.com/python/typing_extensions>`_, for backward compatibility of static typing.\r\n- `typing-validation <https://github.com/hashberg-io/typing-validation>`_, for dynamic typechecking\r\n- `bases <https://github.com/hashberg-io/bases>`_, for implementation of base encodings used by Multibase\r\n\r\nThe following are optional dependencies for this module:\r\n\r\n- `blake3 <https://github.com/oconnor663/blake3-py>`_, for the ``blake3`` hash function.\r\n- `pyskein <https://pythonhosted.org/pyskein/>`_, for the ``skein`` hash functions.\r\n- `mmh3 <https://github.com/hajimes/mmh3>`_, for the ``murmur3`` hash functions.\r\n- `pycryptodomex <https://github.com/Legrandin/pycryptodome/>`_, for the ``ripemd-160`` hash function, \\\r\n the ``kangarootwelve`` hash function, the ``keccak`` hash functions and the ``sha2-512-224``/``sha2-512-256`` hash functions.\r\n\r\nYou can install the latest release together with all optional dependencies as follows:\r\n\r\n.. code-block:: console\r\n\r\n $ pip install --upgrade multiformats[full]\r\n\r\n\r\nUsage\r\n-----\r\n\r\nYou can import multiformat protocols directly from top level:\r\n\r\n>>> from multiformats import *\r\n\r\nThe above will import the following names:\r\n\r\n.. code-block:: python\r\n\r\n varint, multicodec, multibase, multihash, multiaddr, CID\r\n\r\nThe first five are modules implementing the homonymous specifications, while ``CID`` is a class for Content IDentifiers.\r\nBelow are some basic usage examples, to get you started: for detailed documentation, see https://multiformats.readthedocs.io/\r\n\r\n\r\nVarint encode/decode\r\n^^^^^^^^^^^^^^^^^^^^\r\n\r\n>>> varint.encode(128)\r\nb'\\x80\\x01'\r\n>>> varint.decode(b'\\x80\\x01')\r\n128\r\n\r\n\r\nMulticodec wrap/unwrap\r\n^^^^^^^^^^^^^^^^^^^^^^\r\n\r\nProcedural style:\r\n\r\n>>> raw_data = bytes([192, 168, 0, 254])\r\n>>> multicodec_data = multicodec.wrap(\"ip4\", raw_data)\r\n>>> raw_data.hex()\r\n 'c0a800fe'\r\n>>> multicodec_data.hex()\r\n'04c0a800fe'\r\n>>> codec, _raw_data = multicodec.unwrap(multicodec_data)\r\n>>> _raw_data.hex()\r\n 'c0a800fe'\r\n>>> codec\r\nMulticodec(name='ip4', tag='multiaddr', code='0x04',\r\n status='permanent', description='')\r\n\r\nObject-oriented style:\r\n\r\n>>> ip4 = multicodec.get(\"ip4\")\r\n>>> ip4\r\nMulticodec(name='ip4', tag='multiaddr', code='0x04',\r\n status='permanent', description='')\r\n>>> raw_data = bytes([192, 168, 0, 254])\r\n>>> multicodec_data = ip4.wrap(raw_data)\r\n>>> raw_data.hex()\r\n 'c0a800fe'\r\n>>> multicodec_data.hex()\r\n'04c0a800fe'\r\n>>> ip4.unwrap(multicodec_data).hex()\r\n 'c0a800fe'\r\n\r\n\r\nMultibase encode/decode\r\n^^^^^^^^^^^^^^^^^^^^^^^\r\n\r\nProcedural style:\r\n\r\n>>> multibase.encode(b\"Hello World!\", \"base32\")\r\n'bjbswy3dpeblw64tmmqqq'\r\n>>> multibase.decode('bjbswy3dpeblw64tmmqqq')\r\nb'Hello World!'\r\n\r\nObject-oriented style:\r\n\r\n>>> base32 = multibase.get(\"base32\")\r\n>>> base32.encode(b\"Hello World!\")\r\n'bjbswy3dpeblw64tmmqqq'\r\n>>> base32.decode('bjbswy3dpeblw64tmmqqq')\r\nb'Hello World!'\r\n\r\n\r\nMultihash digest\r\n^^^^^^^^^^^^^^^^\r\n\r\nProcedural style:\r\n\r\n>>> data = b\"Hello world!\"\r\n>>> digest = multihash.digest(data, \"sha2-256\")\r\n>>> digest.hex()\r\n'1220c0535e4be2b79ffd93291305436bf889314e4a3faec05ecffcbb7df31ad9e51a'\r\n\r\nObject-oriented style:\r\n\r\n>>> sha2_256 = multihash.get(\"sha2-256\")\r\n>>> digest = sha2_256.digest(data)\r\n>>> digest.hex()\r\n'1220c0535e4be2b79ffd93291305436bf889314e4a3faec05ecffcbb7df31ad9e51a'\r\n\r\nOptional truncated digests:\r\n\r\n>>> digest = multihash.digest(data, \"sha2-256\", size=20)\r\n# optional truncated hash size, in bytes ^^^^^^^\r\n>>> digest.hex()\r\n'1214c0535e4be2b79ffd93291305436bf889314e4a3f'\r\n\r\n\r\nMultihash wrap/unwrap\r\n^^^^^^^^^^^^^^^^^^^^^\r\n\r\nProcedural style:\r\n\r\n>>> digest.hex()\r\n'1214c0535e4be2b79ffd93291305436bf889314e4a3f'\r\n>>> raw_digest = multihash.unwrap(digest)\r\n>>> raw_digest.hex()\r\n 'c0535e4be2b79ffd93291305436bf889314e4a3f'\r\n>>> multihash.wrap(raw_digest, \"sha2-256\").hex()\r\n'1214c0535e4be2b79ffd93291305436bf889314e4a3f'\r\n\r\nObject-oriented style:\r\n\r\n>>> sha2_256 = multihash.get(\"sha2-256\")\r\n>>> raw_digest = sha2_256.unwrap(digest)\r\n>>> raw_digest.hex()\r\n 'c0535e4be2b79ffd93291305436bf889314e4a3f'\r\n>>> sha2_256.wrap(raw_digest).hex()\r\n'1214c0535e4be2b79ffd93291305436bf889314e4a3f'\r\n\r\n\r\nCID encode/decode\r\n^^^^^^^^^^^^^^^^^\r\n\r\nDecoding from multibase encoded strings:\r\n\r\n>>> cid = CID.decode(\"zb2rhe5P4gXftAwvA4eXQ5HJwsER2owDyS9sKaQRRVQPn93bA\")\r\n>>> cid\r\nCID('base58btc', 1, 'raw',\r\n '12206e6ff7950a36187a801613426e858dce686cd7d7e3c0fc42ee0330072d245c95')\r\n>>> cid.base\r\nMultibase(name='base58btc', code='z',\r\n status='default', description='base58 bitcoin')\r\n>>> cid.codec\r\nMulticodec(name='raw', tag='ipld', code='0x55',\r\n status='permanent', description='raw binary')\r\n>>> cid.digest.hex()\r\n'12206e6ff7950a36187a801613426e858dce686cd7d7e3c0fc42ee0330072d245c95'\r\n>>> cid.hashfun\r\nMulticodec(name='sha2-256', tag='multihash', code='0x12',\r\n status='permanent', description='')\r\n>>> cid.raw_digest.hex()\r\n '6e6ff7950a36187a801613426e858dce686cd7d7e3c0fc42ee0330072d245c95'\r\n\r\nMultibase encoding:\r\n\r\n>>> str(cid) # encode with own multibase 'base58btc'\r\n'zb2rhe5P4gXftAwvA4eXQ5HJwsER2owDyS9sKaQRRVQPn93bA'\r\n>>> cid.encode(\"base32\") # encode with different multibase\r\n'bafkreidon73zkcrwdb5iafqtijxildoonbwnpv7dyd6ef3qdgads2jc4su'\r\n\r\n\r\nPeerID creation\r\n^^^^^^^^^^^^^^^\r\n\r\nCreation of `CIDv1 PeerIDs <https://docs.libp2p.io/concepts/peer-id/>`_:\r\n\r\n>>> pk_bytes = bytes.fromhex( # hex-string of 32-byte Ed25519 public key\r\n... \"1498b5467a63dffa2dc9d9e069caf075d16fc33fdd4c3b01bfadae6433767d93\")\r\n>>> peer_id = CID.peer_id(pk_bytes)\r\n>>> peer_id\r\nCID('base32', 1, 'libp2p-key',\r\n'00201498b5467a63dffa2dc9d9e069caf075d16fc33fdd4c3b01bfadae6433767d93')\r\n#^^ 0x00 = 'identity' multihash used (public key length <= 42)\r\n# ^^ 0x20 = 32-bytes of raw hash digest length\r\n>>> str(peer_id)\r\n'bafzaaiautc2um6td375c3soz4bu4v4dv2fx4gp65jq5qdp5nvzsdg5t5sm'\r\n\r\n\r\nMultiaddr parse/decode\r\n^^^^^^^^^^^^^^^^^^^^^^\r\n\r\n>>> s = '/ip4/127.0.0.1/udp/9090/quic'\r\n>>> multiaddr.parse(s)\r\nMultiaddr(Addr('ip4', '127.0.0.1'), Addr('udp', '9090'), Proto('quic'))\r\n>>> b = bytes.fromhex('047f00000191022382cc03')\r\n>>> multiaddr.decode(b)\r\nMultiaddr(Addr('ip4', '127.0.0.1'), Addr('udp', '9090'), Proto('quic'))\r\n\r\n\r\nMultiaddr protocols/addresses\r\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\r\n\r\nAccessing multiaddr protocols:\r\n\r\n>>> ip4 = multiaddr.proto(\"ip4\")\r\n>>> ip4\r\nProto(\"ip4\")\r\n>>> udp = multiaddr.proto(\"udp\")\r\n>>> quic = multiaddr.proto(\"quic\")\r\n\r\nCreating protocol addresses from human-readable strings:\r\n\r\n>>> a = ip4/\"192.168.1.1\"\r\n>>> a\r\nAddr('ip4', '192.168.1.1')\r\n>>> str(a)\r\n'/ip4/192.168.1.1'\r\n>>> a.value\r\n'192.168.1.1'\r\n>>> bytes(a).hex()\r\n'04c0a80101'\r\n>>> a.value_bytes.hex()\r\n 'c0a80101'\r\n\r\nCreating protocol addresses from bytestrings:\r\n\r\n>>> a = ip4/bytes([192, 168, 1, 1])\r\n>>> a\r\nAddr('ip4', '192.168.1.1')\r\n\r\n\r\nMultiaddr encapsulation/decapsulation\r\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\r\n\r\nCreating multiaddresses by protocol encapsulation:\r\n\r\n>>> ma = ip4/\"127.0.0.1\"/udp/9090/quic\r\n>>> ma\r\nMultiaddr(Addr('ip4', '127.0.0.1'), Addr('udp', '9090'), Proto('quic'))\r\n>>> str(ma)\r\n'/ip4/127.0.0.1/udp/9090/quic'\r\n\r\nBytes for multiaddrs are computed according to the `(TLV)+ multiaddr format <https://multiformats.io/multiaddr/>`_:\r\n\r\n>>> bytes(ip4/\"127.0.0.1\").hex()\r\n'047f000001'\r\n>>> bytes(udp/9090).hex()\r\n '91022382'\r\n>>> bytes(quic).hex()\r\n 'cc03'\r\n>>> bytes(ma).hex()\r\n'047f00000191022382cc03'\r\n\r\nProtocol decapsulation by indexing and slicing:\r\n\r\n>>> ma[0]\r\nAddr('ip4', '127.0.0.1')\r\n>>> ma[:2]\r\nMultiaddr(Addr('ip4', '127.0.0.1'), Addr('udp', '9090'))\r\n>>> ma[1:]\r\nMultiaddr(Addr('udp', '9090'), Proto('quic'))\r\n\r\n\r\nAPI\r\n---\r\n\r\nFor the full API documentation, see https://multiformats.readthedocs.io/\r\n\r\nThe tables specifying all multicodecs and multibases known to this package are maintained as part of the `multiformats-config <https://github.com/hashberg-io/multiformats-config>`_ repository.\r\n\r\n\r\nContributing\r\n------------\r\n\r\nPlease see `<CONTRIBUTING.md>`_.\r\n\r\n\r\nLicense\r\n-------\r\n\r\n`MIT \u00a9 Hashberg Ltd. <LICENSE>`_\r\n",
"bugtrack_url": null,
"license": "",
"summary": "Python implementation of multiformats protocols.",
"version": "0.3.1.post4",
"project_urls": {
"Bug Tracker": "https://github.com/hashberg-io/multiformats/issues",
"Homepage": "https://github.com/hashberg-io/multiformats"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "fa020eff41b136c6723441d052c61c9dae36b86b3ae68ec064813445580222a6",
"md5": "82eaa30003f540239397efb24458edec",
"sha256": "5b1d61bd8275c9e817bdbee38dbd501b26629011962ee3c86c46e7ccd0b14129"
},
"downloads": -1,
"filename": "multiformats-0.3.1.post4-py3-none-any.whl",
"has_sig": false,
"md5_digest": "82eaa30003f540239397efb24458edec",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 57148,
"upload_time": "2023-12-20T14:17:58",
"upload_time_iso_8601": "2023-12-20T14:17:58.576419Z",
"url": "https://files.pythonhosted.org/packages/fa/02/0eff41b136c6723441d052c61c9dae36b86b3ae68ec064813445580222a6/multiformats-0.3.1.post4-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "b2412efc6e99fa2ed9f1a47fbfed5d124215e35db0a849585db72eeb1490de0e",
"md5": "63c9331d1ed581b2b6a8026abb5e0f12",
"sha256": "d00074fdbc7d603c2084b4c38fa17bbc28173cf2750f51f46fbbc5c4d5605fbb"
},
"downloads": -1,
"filename": "multiformats-0.3.1.post4.tar.gz",
"has_sig": false,
"md5_digest": "63c9331d1ed581b2b6a8026abb5e0f12",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 826017,
"upload_time": "2023-12-20T14:18:00",
"upload_time_iso_8601": "2023-12-20T14:18:00.571465Z",
"url": "https://files.pythonhosted.org/packages/b2/41/2efc6e99fa2ed9f1a47fbfed5d124215e35db0a849585db72eeb1490de0e/multiformats-0.3.1.post4.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-12-20 14:18:00",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "hashberg-io",
"github_project": "multiformats",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [],
"tox": true,
"lcname": "multiformats"
}