Multicodec implementation in Python
multicodec is a self-describing multiformat, it wraps other formats with a tiny bit of self-description.
A multicodec identifier is both a varint and the code identifying the following data, this means that the most significant bit of every multicodec code is reserved to signal the continuation.
You can check the table here for the list of supported codecs by py-multicodec.
Free software: MIT license
Documentation: https://py-multicodec.readthedocs.io.
Python versions: 3.10, 3.11, 3.12, 3.13, 3.14
Installation
$ pip install py-multicodec
Sample Usage
>>> from multicodec import add_prefix, remove_prefix, get_codec
>>> # adding a prefix to existing data
>>> add_prefix('sha2-256', b'EiC5TSe5k00')
b'\x12EiC5TSe5k00'
>>> # removing prefix from prefixed data
>>> remove_prefix(b'\x12EiC5TSe5k00')
EiC5TSe5k00
>>> # get codec used to prefix the prefixed data
>>> get_codec(b'\x12EiC5TSe5k00')
'sha2-256'
Code Management
In addition to the basic prefix operations, py-multicodec provides type-safe codec management functionality:
>>> from multicodec import Code, known_codes
>>> from multicodec.code_table import SHA2_256, DAG_CBOR
>>> # Use named constants for type-safe codec handling
>>> code = SHA2_256
>>> str(code)
'sha2-256'
>>> int(code)
18
>>> # Create Code from string (name or hex)
>>> code = Code.from_string("sha2-256")
>>> code = Code.from_string("0x12") # hex also works
>>> # List all known codecs
>>> all_codes = known_codes()
>>> len(all_codes)
460
Updating the lookup table
Updating the lookup table is done with a script. The source of truth is the multicodec default table. Update the table with running:
$ curl -X GET https://raw.githubusercontent.com/multiformats/multicodec/master/table.csv | ./tools/update-table.py
Metadata
Release files for py-multicodec 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| py_multicodec-1.0.0.tar.gz | 44.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| py_multicodec-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 70.9 kB
Release files / py_multicodec-1.0.0.tar.gz
| Download URL | py_multicodec-1.0.0.tar.gz |
|---|---|
| Size | 44.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
78e4e3e47b6288cf635c3ca987152e6cb5510bdcdab307e7690c76ec3d5bbfeb
|
|
BLAKE2b-256 checksum How to use checksums |
5e26ef24db0fbfec080b72c5ac4a1000da3a4d696a1e31862c695d683097a1b5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.4
|
Release files / py_multicodec-1.0.0-py3-none-any.whl
| Download URL | py_multicodec-1.0.0-py3-none-any.whl |
|---|---|
| Size | 26.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ae2e687bac8fdf54e3f5b3feded36b61a304d5e3c3af9438f7481f543ec15b8d
|
|
BLAKE2b-256 checksum How to use checksums |
76da768d07490faeae88ac361184164be9c262fececc3c6241b5fc471be4f659
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.4
|