Skip to content

Commit e946d18

Browse files
committed
feat: Add comprehensive codecs module with extension-based codec registries
Implements Pattern 1 (extension-based codec registries) for flexible configuration file parsing with support for bytes <-> JSON-friendly Python types. New features: - Core registry infrastructure with EXTENSION_TO_DECODER/ENCODER mappings - Registration API: register_codec(), register_decoder(), register_encoder() - Introspection API: list_registered_extensions(), is_extension_registered(), get_codec_info() - encode_by_extension() and decode_by_extension() for automatic codec routing Standard library codecs (always available): - JSON (.json) - with proper UTF-8 and indentation - Pickle (.pkl, .pickle) - Python object serialization - Plain text (.txt) - Line-separated values (.lsv, .list, .lines) - CSV (.csv) - with dict support - TSV (.tsv, .tab) - tab-separated values - INI/CFG (.ini, .cfg, .conf) - ConfigParser format - XML (.xml) - basic ElementTree support Conditional third-party codecs: - TOML (.toml) - tomllib (3.11+) / tomli + tomli_w - YAML (.yaml, .yml) - PyYAML with safe_load - ENV (.env) - python-dotenv with simple fallback - JSON5 (.json5) - lenient JSON parsing - Properties (.properties) - Java-style with jproperties fallback Extras added to pyproject.toml: - Individual extras: yaml, toml, env, json5, properties - Convenience groups: all-codecs, all Key implementation details: - Graceful fallback for missing third-party dependencies - Dotfile support (e.g., .env, .gitignore) - Comprehensive test suite with 100+ test cases - Full type hints and docstrings
1 parent 2b0cea2 commit e946d18

File tree

4 files changed

+1105
-0
lines changed

4 files changed

+1105
-0
lines changed

config2py/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@
2424
process_path,
2525
)
2626
from config2py.sync_store import SyncStore, FileStore, JsonStore, register_extension
27+
from config2py import codecs # noqa - Make codecs module available

0 commit comments

Comments
 (0)