Skip to content

Commit a64cc9f

Browse files
Add comprehensive codec management functionality (#24)
* Add comprehensive codec management functionality * Address minor PR review recommendations - Add Code Management section to README with usage examples - Add return type annotation to load_codecs_from_file() - Improve newsfragment formatting (remove backticks) * Fix ReST title underline length in README --------- Co-authored-by: acul71 <[email protected]>
1 parent d8cba03 commit a64cc9f

File tree

7 files changed

+2018
-0
lines changed

7 files changed

+2018
-0
lines changed

README.rst

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,33 @@ Sample Usage
5353
>>> get_codec(b'\x12EiC5TSe5k00')
5454
'sha2-256'
5555
56+
Code Management
57+
===============
58+
59+
In addition to the basic prefix operations, py-multicodec provides type-safe codec
60+
management functionality:
61+
62+
.. code-block:: python
63+
64+
>>> from multicodec import Code, known_codes
65+
>>> from multicodec.code_table import SHA2_256, DAG_CBOR
66+
67+
>>> # Use named constants for type-safe codec handling
68+
>>> code = SHA2_256
69+
>>> str(code)
70+
'sha2-256'
71+
>>> int(code)
72+
18
73+
74+
>>> # Create Code from string (name or hex)
75+
>>> code = Code.from_string("sha2-256")
76+
>>> code = Code.from_string("0x12") # hex also works
77+
78+
>>> # List all known codecs
79+
>>> all_codes = known_codes()
80+
>>> len(all_codes)
81+
460
82+
5683
Updating the lookup table
5784
==========================
5885

multicodec/__init__.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,32 @@
44
__email__ = "[email protected]"
55
__version__ = "0.2.1"
66

7+
# Core Code type
8+
from .code import (
9+
RESERVED_END,
10+
RESERVED_START,
11+
Code,
12+
is_reserved,
13+
known_codes,
14+
)
15+
16+
# Original multicodec functions
717
from .multicodec import add_prefix, extract_prefix, get_codec, get_prefix, is_codec, remove_prefix
818

919
__all__ = [
20+
"RESERVED_END",
21+
# Constants
22+
"RESERVED_START",
23+
# Code type
24+
"Code",
25+
# Original functions
1026
"add_prefix",
1127
"extract_prefix",
1228
"get_codec",
1329
"get_prefix",
1430
"is_codec",
31+
"is_reserved",
32+
# Functions
33+
"known_codes",
1534
"remove_prefix",
1635
]

0 commit comments

Comments
 (0)