Named constants like SHA2_256, DAG_CBOR, IP4 etc. from code_table.py are not re-exported from the top-level multicodec package. Users must import from a submodule (from multicodec.code_table import SHA2_256) instead of the top-level package.
Problem
Current usage requires a submodule import:
# Current: requires submodule import
from multicodec.code_table import SHA2_256, DAG_CBOR, IP4
All other public symbols (Code, prefix functions, serialization, etc.) are available from the top-level package:
# Everything else is top-level
from multicodec import Code, add_prefix, get_codec, encode, decode
This inconsistency means users need to know about the internal module structure to use named constants.
Proposed Solution
There are two options:
Option A: Re-export the most commonly used constants from __init__.py:
from .code_table import (
IDENTITY, SHA1, SHA2_256, SHA2_512, SHA3_256, SHA3_512,
DAG_PB, DAG_CBOR, DAG_JSON, RAW,
IP4, IP6, TCP, UDP,
)
Option B: Keep them in the submodule but add a prominent note in the docs and README:
# Recommended import pattern
from multicodec.code_table import SHA2_256
Recommended: Option A with a curated set of ~20 most-used constants, plus a note that from multicodec.code_table import * is available for all 603.
Update __all__ accordingly.
Related
- File:
multicodec/__init__.py
- Constants source:
multicodec/code_table.py (603 constants)
Named constants like
SHA2_256,DAG_CBOR,IP4etc. fromcode_table.pyare not re-exported from the top-levelmulticodecpackage. Users must import from a submodule (from multicodec.code_table import SHA2_256) instead of the top-level package.Problem
Current usage requires a submodule import:
All other public symbols (Code, prefix functions, serialization, etc.) are available from the top-level package:
This inconsistency means users need to know about the internal module structure to use named constants.
Proposed Solution
There are two options:
Option A: Re-export the most commonly used constants from
__init__.py:Option B: Keep them in the submodule but add a prominent note in the docs and README:
Recommended: Option A with a curated set of ~20 most-used constants, plus a note that
from multicodec.code_table import *is available for all 603.Update
__all__accordingly.Related
multicodec/__init__.pymulticodec/code_table.py(603 constants)