Skip to main content

py-multicodec

https://img.shields.io/pypi/v/py-multicodec.svg https://github.com/multiformats/py-multicodec/actions/workflows/tox.yml/badge.svg?branch=master Documentation Status

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.

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 authoritative table is vendored in the multicodec-spec git submodule (table.csv). After a fresh clone, run git submodule update --init --recursive so the submodule and spec compliance test are available.

To refresh the registry from upstream, bump the submodule pin and regenerate multicodec/constants.py:

$ git -C multicodec-spec fetch origin
$ git -C multicodec-spec checkout origin/master
$ git add multicodec-spec
$ ./tools/update-table.py < multicodec-spec/table.csv

Alternatively, pipe the latest upstream CSV directly:

$ curl -X GET https://raw.githubusercontent.com/multiformats/multicodec/master/table.csv | ./tools/update-table.py

Commit the updated constants.py together with the new submodule commit SHA.

Metadata

Release files for py-multicodec 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for py-multicodec 1.1.0
File Size Uploaded Provenance Actions
py_multicodec-1.1.0.tar.gz 54.8 kB Without provenance Details for py_multicodec-1.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for py-multicodec 1.1.0
File Interpreter ABI Platform Actions
py_multicodec-1.1.0-py3-none-any.whl Python 3 none any Details for py_multicodec-1.1.0-py3-none-any.whl

Total release size: 86.7 kB

Release files / py_multicodec-1.1.0.tar.gz

Download URL py_multicodec-1.1.0.tar.gz
Size 54.8 kB
Tags Source
SHA-256 checksum
How to use checksums
9e3f07e17cb047b2a058a049f70ee00751faadbff104c939d1358679295e138a
BLAKE2b-256 checksum
How to use checksums
d17bb8969890d4f73ab2fa59cdabe1018c7dbd4b1265041184349cbec175657d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.10

Release files / py_multicodec-1.1.0-py3-none-any.whl

Download URL py_multicodec-1.1.0-py3-none-any.whl
Size 31.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4a6d778d7d0bb46d93b84003f481a16b4dd792e9a5710c56aa4a5a2f656686e5
BLAKE2b-256 checksum
How to use checksums
18511ba1f818c1429f0cc49f2b0b1f665b1e4ba1fa8833ea94da7c8240e5d300
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.10

Security for py-multicodec 1.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page