Multicodec is a self-describing multiformat that wraps other formats with a tiny bit of self-description. A multicodec identifier is a varint and the code identifying the following data. This Python implementation provides functions for adding and removing prefixes, and for managing type-safe codec handling using `Code` objects. It is currently at version 1.0.0, released after a significant development period.
pip install py-multicodecVerified import paths — ran on the pinned version, not inferred.
Demonstrates adding and removing multicodec prefixes, retrieving codec names, and using the `Code` object for type-safe codec handling and listing all supported codecs.
Confirm `pip install py-multicodec` and use `from multicodec import ...` for imports.
Consult the project's release notes or GitHub history for migration guides if upgrading from older pre-1.0.0 versions.
Ensure the `Code` object used for unwrapping matches the codec embedded in the prefixed data, or use `remove_prefix` for a less strict approach that simply removes the prefix without validating its type against a specific `Code` object.
If working with very new or custom codecs, consider updating the local codec table by running the provided `update-table.py` script from the repository, or upgrade to the latest library version.
Always convert string data to bytes using `.encode('utf-8')` (or another appropriate encoding) before passing it to `py-multicodec` functions, e.g., `add_prefix('sha2-256', 'my string'.encode('utf-8'))`.Use direct imports for the functions you need, e.g., `from multicodec import add_prefix`, or import the module as `import multicodec` and then call `multicodec.add_prefix`.
Ensure the `Code` object used for unwrapping (`my_code.unwrap()`) corresponds to the actual codec of the data. If you only want to remove the prefix without strict validation, use `multicodec.remove_prefix(prefixed_data)` instead.
No dependency data recorded yet.