Skip to content

Export code_table named constants from top-level __init__.py #46

Description

@sumanjeet0012

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)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions