Skip to main content

Multicodec implementation in Python

Project description

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 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

py_multicodec-1.0.0.tar.gz (44.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

py_multicodec-1.0.0-py3-none-any.whl (26.2 kB view details)

Uploaded Python 3

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

Hashes for py_multicodec-1.0.0.tar.gz
Algorithm Hash digest
SHA256 78e4e3e47b6288cf635c3ca987152e6cb5510bdcdab307e7690c76ec3d5bbfeb
MD5 3ace6016f090d71e1afd100764bb7547
BLAKE2b-256 5e26ef24db0fbfec080b72c5ac4a1000da3a4d696a1e31862c695d683097a1b5

See more details on using hashes here.

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

Hashes for py_multicodec-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ae2e687bac8fdf54e3f5b3feded36b61a304d5e3c3af9438f7481f543ec15b8d
MD5 eed648143eadc3772c95b2e91744d1e8
BLAKE2b-256 76da768d07490faeae88ac361184164be9c262fececc3c6241b5fc471be4f659

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page