Multicodec implementation in Python
Project description
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
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file py_multicodec-1.0.0.tar.gz.
File metadata
- Download URL: py_multicodec-1.0.0.tar.gz
- Upload date:
- Size: 44.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
78e4e3e47b6288cf635c3ca987152e6cb5510bdcdab307e7690c76ec3d5bbfeb
|
|
| MD5 |
3ace6016f090d71e1afd100764bb7547
|
|
| BLAKE2b-256 |
5e26ef24db0fbfec080b72c5ac4a1000da3a4d696a1e31862c695d683097a1b5
|
File details
Details for the file py_multicodec-1.0.0-py3-none-any.whl.
File metadata
- Download URL: py_multicodec-1.0.0-py3-none-any.whl
- Upload date:
- Size: 26.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ae2e687bac8fdf54e3f5b3feded36b61a304d5e3c3af9438f7481f543ec15b8d
|
|
| MD5 |
eed648143eadc3772c95b2e91744d1e8
|
|
| BLAKE2b-256 |
76da768d07490faeae88ac361184164be9c262fececc3c6241b5fc471be4f659
|