dd-config 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- dd_config-0.1.0/.gitignore +207 -0
- dd_config-0.1.0/LICENSE +21 -0
- dd_config-0.1.0/PKG-INFO +149 -0
- dd_config-0.1.0/README.md +93 -0
- dd_config-0.1.0/cookbook/01_basics/README.md +17 -0
- dd_config-0.1.0/cookbook/01_basics/main.py +136 -0
- dd_config-0.1.0/cookbook/01_basics/requirements.txt +1 -0
- dd_config-0.1.0/docs/DESIGN.md +92 -0
- dd_config-0.1.0/pyproject.toml +52 -0
- dd_config-0.1.0/src/dd_config/__init__.py +12 -0
- dd_config-0.1.0/src/dd_config/adapters/__init__.py +48 -0
- dd_config-0.1.0/src/dd_config/adapters/env_adapter.py +49 -0
- dd_config-0.1.0/src/dd_config/adapters/ini_adapter.py +47 -0
- dd_config-0.1.0/src/dd_config/adapters/json_adapter.py +30 -0
- dd_config-0.1.0/src/dd_config/adapters/toml_adapter.py +52 -0
- dd_config-0.1.0/src/dd_config/adapters/yaml_adapter.py +41 -0
- dd_config-0.1.0/src/dd_config/base.py +21 -0
- dd_config-0.1.0/src/dd_config/config.py +238 -0
- dd_config-0.1.0/src/dd_config/models.py +22 -0
- dd_config-0.1.0/src/dd_config/utils.py +92 -0
- dd_config-0.1.0/tests/__init__.py +0 -0
- dd_config-0.1.0/tests/test_config.py +241 -0
- dd_config-0.1.0/tests/test_env_adapter.py +48 -0
- dd_config-0.1.0/tests/test_ini_adapter.py +41 -0
- dd_config-0.1.0/tests/test_json_adapter.py +45 -0
- dd_config-0.1.0/tests/test_toml_adapter.py +43 -0
- dd_config-0.1.0/tests/test_yaml_adapter.py +51 -0
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[codz]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
share/python-wheels/
|
|
24
|
+
*.egg-info/
|
|
25
|
+
.installed.cfg
|
|
26
|
+
*.egg
|
|
27
|
+
MANIFEST
|
|
28
|
+
|
|
29
|
+
# PyInstaller
|
|
30
|
+
# Usually these files are written by a python script from a template
|
|
31
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
32
|
+
*.manifest
|
|
33
|
+
*.spec
|
|
34
|
+
|
|
35
|
+
# Installer logs
|
|
36
|
+
pip-log.txt
|
|
37
|
+
pip-delete-this-directory.txt
|
|
38
|
+
|
|
39
|
+
# Unit test / coverage reports
|
|
40
|
+
htmlcov/
|
|
41
|
+
.tox/
|
|
42
|
+
.nox/
|
|
43
|
+
.coverage
|
|
44
|
+
.coverage.*
|
|
45
|
+
.cache
|
|
46
|
+
nosetests.xml
|
|
47
|
+
coverage.xml
|
|
48
|
+
*.cover
|
|
49
|
+
*.py.cover
|
|
50
|
+
.hypothesis/
|
|
51
|
+
.pytest_cache/
|
|
52
|
+
cover/
|
|
53
|
+
|
|
54
|
+
# Translations
|
|
55
|
+
*.mo
|
|
56
|
+
*.pot
|
|
57
|
+
|
|
58
|
+
# Django stuff:
|
|
59
|
+
*.log
|
|
60
|
+
local_settings.py
|
|
61
|
+
db.sqlite3
|
|
62
|
+
db.sqlite3-journal
|
|
63
|
+
|
|
64
|
+
# Flask stuff:
|
|
65
|
+
instance/
|
|
66
|
+
.webassets-cache
|
|
67
|
+
|
|
68
|
+
# Scrapy stuff:
|
|
69
|
+
.scrapy
|
|
70
|
+
|
|
71
|
+
# Sphinx documentation
|
|
72
|
+
docs/_build/
|
|
73
|
+
|
|
74
|
+
# PyBuilder
|
|
75
|
+
.pybuilder/
|
|
76
|
+
target/
|
|
77
|
+
|
|
78
|
+
# Jupyter Notebook
|
|
79
|
+
.ipynb_checkpoints
|
|
80
|
+
|
|
81
|
+
# IPython
|
|
82
|
+
profile_default/
|
|
83
|
+
ipython_config.py
|
|
84
|
+
|
|
85
|
+
# pyenv
|
|
86
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
87
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
88
|
+
# .python-version
|
|
89
|
+
|
|
90
|
+
# pipenv
|
|
91
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
92
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
93
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
94
|
+
# install all needed dependencies.
|
|
95
|
+
#Pipfile.lock
|
|
96
|
+
|
|
97
|
+
# UV
|
|
98
|
+
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
|
|
99
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
100
|
+
# commonly ignored for libraries.
|
|
101
|
+
#uv.lock
|
|
102
|
+
|
|
103
|
+
# poetry
|
|
104
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
105
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
106
|
+
# commonly ignored for libraries.
|
|
107
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
108
|
+
#poetry.lock
|
|
109
|
+
#poetry.toml
|
|
110
|
+
|
|
111
|
+
# pdm
|
|
112
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
113
|
+
# pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
|
|
114
|
+
# https://pdm-project.org/en/latest/usage/project/#working-with-version-control
|
|
115
|
+
#pdm.lock
|
|
116
|
+
#pdm.toml
|
|
117
|
+
.pdm-python
|
|
118
|
+
.pdm-build/
|
|
119
|
+
|
|
120
|
+
# pixi
|
|
121
|
+
# Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
|
|
122
|
+
#pixi.lock
|
|
123
|
+
# Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
|
|
124
|
+
# in the .venv directory. It is recommended not to include this directory in version control.
|
|
125
|
+
.pixi
|
|
126
|
+
|
|
127
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
128
|
+
__pypackages__/
|
|
129
|
+
|
|
130
|
+
# Celery stuff
|
|
131
|
+
celerybeat-schedule
|
|
132
|
+
celerybeat.pid
|
|
133
|
+
|
|
134
|
+
# SageMath parsed files
|
|
135
|
+
*.sage.py
|
|
136
|
+
|
|
137
|
+
# Environments
|
|
138
|
+
.env
|
|
139
|
+
.envrc
|
|
140
|
+
.venv
|
|
141
|
+
env/
|
|
142
|
+
venv/
|
|
143
|
+
ENV/
|
|
144
|
+
env.bak/
|
|
145
|
+
venv.bak/
|
|
146
|
+
|
|
147
|
+
# Spyder project settings
|
|
148
|
+
.spyderproject
|
|
149
|
+
.spyproject
|
|
150
|
+
|
|
151
|
+
# Rope project settings
|
|
152
|
+
.ropeproject
|
|
153
|
+
|
|
154
|
+
# mkdocs documentation
|
|
155
|
+
/site
|
|
156
|
+
|
|
157
|
+
# mypy
|
|
158
|
+
.mypy_cache/
|
|
159
|
+
.dmypy.json
|
|
160
|
+
dmypy.json
|
|
161
|
+
|
|
162
|
+
# Pyre type checker
|
|
163
|
+
.pyre/
|
|
164
|
+
|
|
165
|
+
# pytype static type analyzer
|
|
166
|
+
.pytype/
|
|
167
|
+
|
|
168
|
+
# Cython debug symbols
|
|
169
|
+
cython_debug/
|
|
170
|
+
|
|
171
|
+
# PyCharm
|
|
172
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
173
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
174
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
175
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
176
|
+
#.idea/
|
|
177
|
+
|
|
178
|
+
# Abstra
|
|
179
|
+
# Abstra is an AI-powered process automation framework.
|
|
180
|
+
# Ignore directories containing user credentials, local state, and settings.
|
|
181
|
+
# Learn more at https://abstra.io/docs
|
|
182
|
+
.abstra/
|
|
183
|
+
|
|
184
|
+
# Visual Studio Code
|
|
185
|
+
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
|
|
186
|
+
# that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
|
|
187
|
+
# and can be added to the global gitignore or merged into this file. However, if you prefer,
|
|
188
|
+
# you could uncomment the following to ignore the entire vscode folder
|
|
189
|
+
# .vscode/
|
|
190
|
+
|
|
191
|
+
# Ruff stuff:
|
|
192
|
+
.ruff_cache/
|
|
193
|
+
|
|
194
|
+
# PyPI configuration file
|
|
195
|
+
.pypirc
|
|
196
|
+
|
|
197
|
+
# Cursor
|
|
198
|
+
# Cursor is an AI-powered code editor. `.cursorignore` specifies files/directories to
|
|
199
|
+
# exclude from AI features like autocomplete and code analysis. Recommended for sensitive data
|
|
200
|
+
# refer to https://docs.cursor.com/context/ignore-files
|
|
201
|
+
.cursorignore
|
|
202
|
+
.cursorindexingignore
|
|
203
|
+
|
|
204
|
+
# Marimo
|
|
205
|
+
marimo/_static/
|
|
206
|
+
marimo/_lsp/
|
|
207
|
+
__marimo__/
|
dd_config-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 digital-duck
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
dd_config-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: dd-config
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Unified configuration management for the dd-* ecosystem
|
|
5
|
+
Project-URL: Homepage, https://github.com/digital-duck/dd-config
|
|
6
|
+
Project-URL: Repository, https://github.com/digital-duck/dd-config
|
|
7
|
+
Author-email: Digital Duck <p2p2learn@outlook.com>
|
|
8
|
+
License: MIT License
|
|
9
|
+
|
|
10
|
+
Copyright (c) 2026 digital-duck
|
|
11
|
+
|
|
12
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
13
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
14
|
+
in the Software without restriction, including without limitation the rights
|
|
15
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
16
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
17
|
+
furnished to do so, subject to the following conditions:
|
|
18
|
+
|
|
19
|
+
The above copyright notice and this permission notice shall be included in all
|
|
20
|
+
copies or substantial portions of the Software.
|
|
21
|
+
|
|
22
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
23
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
24
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
25
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
26
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
27
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
28
|
+
SOFTWARE.
|
|
29
|
+
License-File: LICENSE
|
|
30
|
+
Keywords: config,configuration,env,ini,json,toml,yaml
|
|
31
|
+
Classifier: Development Status :: 3 - Alpha
|
|
32
|
+
Classifier: Intended Audience :: Developers
|
|
33
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
34
|
+
Classifier: Programming Language :: Python :: 3
|
|
35
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
36
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
37
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
38
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
39
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
40
|
+
Requires-Python: >=3.9
|
|
41
|
+
Requires-Dist: pydantic>=2.0.0
|
|
42
|
+
Provides-Extra: all
|
|
43
|
+
Requires-Dist: pyyaml>=6.0; extra == 'all'
|
|
44
|
+
Requires-Dist: tomli>=2.0; (python_version < '3.11') and extra == 'all'
|
|
45
|
+
Provides-Extra: dev
|
|
46
|
+
Requires-Dist: pytest-cov; extra == 'dev'
|
|
47
|
+
Requires-Dist: pytest>=7.0; extra == 'dev'
|
|
48
|
+
Requires-Dist: pyyaml>=6.0; extra == 'dev'
|
|
49
|
+
Requires-Dist: tomli-w>=1.0; extra == 'dev'
|
|
50
|
+
Requires-Dist: tomli>=2.0; (python_version < '3.11') and extra == 'dev'
|
|
51
|
+
Provides-Extra: toml
|
|
52
|
+
Requires-Dist: tomli>=2.0; (python_version < '3.11') and extra == 'toml'
|
|
53
|
+
Provides-Extra: yaml
|
|
54
|
+
Requires-Dist: pyyaml>=6.0; extra == 'yaml'
|
|
55
|
+
Description-Content-Type: text/markdown
|
|
56
|
+
|
|
57
|
+
# dd-config
|
|
58
|
+
|
|
59
|
+
Unified configuration management for the `dd-*` ecosystem — load, merge, validate and
|
|
60
|
+
convert config files across multiple formats with a single clean API.
|
|
61
|
+
|
|
62
|
+
## Install
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
pip install dd-config # JSON + INI + .env support (stdlib only)
|
|
66
|
+
pip install "dd-config[yaml]" # + YAML support
|
|
67
|
+
pip install "dd-config[all]" # all formats including TOML
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## Quick start
|
|
71
|
+
|
|
72
|
+
```python
|
|
73
|
+
from dd_config import Config
|
|
74
|
+
|
|
75
|
+
# Load a YAML config
|
|
76
|
+
cfg = Config.load("splflow.yaml")
|
|
77
|
+
|
|
78
|
+
# Plain key access
|
|
79
|
+
adapter = cfg["llm_adapter"] # "ollama"
|
|
80
|
+
|
|
81
|
+
# Dot-path access for nested keys
|
|
82
|
+
host = cfg["database.host"]
|
|
83
|
+
|
|
84
|
+
# Safe get with default
|
|
85
|
+
port = cfg.get("database.port", 5432)
|
|
86
|
+
|
|
87
|
+
# Layer overrides on top (later files win)
|
|
88
|
+
cfg = Config.load("base.yaml", overrides=["local.yaml", ".env"])
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Supported formats
|
|
92
|
+
|
|
93
|
+
| Format | Extension | Extra required |
|
|
94
|
+
|--------|-----------|----------------|
|
|
95
|
+
| JSON | `.json` | none (stdlib) |
|
|
96
|
+
| YAML | `.yaml`, `.yml` | `pip install "dd-config[yaml]"` |
|
|
97
|
+
| TOML | `.toml` | `pip install "dd-config[all]"` |
|
|
98
|
+
| INI | `.ini`, `.cfg` | none (stdlib) |
|
|
99
|
+
| Env | `.env` | none (stdlib) |
|
|
100
|
+
|
|
101
|
+
## Features
|
|
102
|
+
|
|
103
|
+
- **Multi-format** — one API for JSON, YAML, TOML, INI, `.env`
|
|
104
|
+
- **Auto-detection** — format inferred from file extension
|
|
105
|
+
- **Layered loading** — base config + multiple override files; last writer wins
|
|
106
|
+
- **Dot-path access** — `cfg["server.port"]` instead of `cfg["server"]["port"]`
|
|
107
|
+
- **Env interpolation** — `${VAR:-default}` tokens expanded on load
|
|
108
|
+
- **Format conversion** — `Config.convert("app.yaml", "app.json")`
|
|
109
|
+
- **Validation** — required-key and type checks raise `ValidationError`
|
|
110
|
+
- **Plain dict** — `cfg.to_dict()` returns a plain Python dict; no magic objects
|
|
111
|
+
- **Lazy deps** — YAML/TOML libraries only imported when actually used
|
|
112
|
+
|
|
113
|
+
## Validation
|
|
114
|
+
|
|
115
|
+
```python
|
|
116
|
+
cfg.validate(required=["llm_adapter", "database.host"])
|
|
117
|
+
cfg.validate(schema={"database.port": int, "debug": bool})
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
## Saving & converting
|
|
121
|
+
|
|
122
|
+
```python
|
|
123
|
+
cfg["llm_adapter"] = "openrouter"
|
|
124
|
+
cfg.save("splflow.yaml") # write back to YAML
|
|
125
|
+
Config.convert("splflow.yaml", "splflow.json") # one-liner format conversion
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## Environment variable interpolation
|
|
129
|
+
|
|
130
|
+
Values like `${OPENROUTER_API_KEY:-}` in config files are expanded from the
|
|
131
|
+
environment at load time. Useful for secrets that must not be committed to VCS:
|
|
132
|
+
|
|
133
|
+
```yaml
|
|
134
|
+
openrouter:
|
|
135
|
+
api_key: ${OPENROUTER_API_KEY}
|
|
136
|
+
base_url: https://openrouter.ai/api/v1
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
## Merge
|
|
140
|
+
|
|
141
|
+
```python
|
|
142
|
+
base = Config.load("base.yaml")
|
|
143
|
+
local = Config.load("local.yaml")
|
|
144
|
+
merged = base.merge(local) # local wins on conflict; non-destructive
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
## License
|
|
148
|
+
|
|
149
|
+
MIT © 2026 digital-duck
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# dd-config
|
|
2
|
+
|
|
3
|
+
Unified configuration management for the `dd-*` ecosystem — load, merge, validate and
|
|
4
|
+
convert config files across multiple formats with a single clean API.
|
|
5
|
+
|
|
6
|
+
## Install
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
pip install dd-config # JSON + INI + .env support (stdlib only)
|
|
10
|
+
pip install "dd-config[yaml]" # + YAML support
|
|
11
|
+
pip install "dd-config[all]" # all formats including TOML
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Quick start
|
|
15
|
+
|
|
16
|
+
```python
|
|
17
|
+
from dd_config import Config
|
|
18
|
+
|
|
19
|
+
# Load a YAML config
|
|
20
|
+
cfg = Config.load("splflow.yaml")
|
|
21
|
+
|
|
22
|
+
# Plain key access
|
|
23
|
+
adapter = cfg["llm_adapter"] # "ollama"
|
|
24
|
+
|
|
25
|
+
# Dot-path access for nested keys
|
|
26
|
+
host = cfg["database.host"]
|
|
27
|
+
|
|
28
|
+
# Safe get with default
|
|
29
|
+
port = cfg.get("database.port", 5432)
|
|
30
|
+
|
|
31
|
+
# Layer overrides on top (later files win)
|
|
32
|
+
cfg = Config.load("base.yaml", overrides=["local.yaml", ".env"])
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Supported formats
|
|
36
|
+
|
|
37
|
+
| Format | Extension | Extra required |
|
|
38
|
+
|--------|-----------|----------------|
|
|
39
|
+
| JSON | `.json` | none (stdlib) |
|
|
40
|
+
| YAML | `.yaml`, `.yml` | `pip install "dd-config[yaml]"` |
|
|
41
|
+
| TOML | `.toml` | `pip install "dd-config[all]"` |
|
|
42
|
+
| INI | `.ini`, `.cfg` | none (stdlib) |
|
|
43
|
+
| Env | `.env` | none (stdlib) |
|
|
44
|
+
|
|
45
|
+
## Features
|
|
46
|
+
|
|
47
|
+
- **Multi-format** — one API for JSON, YAML, TOML, INI, `.env`
|
|
48
|
+
- **Auto-detection** — format inferred from file extension
|
|
49
|
+
- **Layered loading** — base config + multiple override files; last writer wins
|
|
50
|
+
- **Dot-path access** — `cfg["server.port"]` instead of `cfg["server"]["port"]`
|
|
51
|
+
- **Env interpolation** — `${VAR:-default}` tokens expanded on load
|
|
52
|
+
- **Format conversion** — `Config.convert("app.yaml", "app.json")`
|
|
53
|
+
- **Validation** — required-key and type checks raise `ValidationError`
|
|
54
|
+
- **Plain dict** — `cfg.to_dict()` returns a plain Python dict; no magic objects
|
|
55
|
+
- **Lazy deps** — YAML/TOML libraries only imported when actually used
|
|
56
|
+
|
|
57
|
+
## Validation
|
|
58
|
+
|
|
59
|
+
```python
|
|
60
|
+
cfg.validate(required=["llm_adapter", "database.host"])
|
|
61
|
+
cfg.validate(schema={"database.port": int, "debug": bool})
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Saving & converting
|
|
65
|
+
|
|
66
|
+
```python
|
|
67
|
+
cfg["llm_adapter"] = "openrouter"
|
|
68
|
+
cfg.save("splflow.yaml") # write back to YAML
|
|
69
|
+
Config.convert("splflow.yaml", "splflow.json") # one-liner format conversion
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Environment variable interpolation
|
|
73
|
+
|
|
74
|
+
Values like `${OPENROUTER_API_KEY:-}` in config files are expanded from the
|
|
75
|
+
environment at load time. Useful for secrets that must not be committed to VCS:
|
|
76
|
+
|
|
77
|
+
```yaml
|
|
78
|
+
openrouter:
|
|
79
|
+
api_key: ${OPENROUTER_API_KEY}
|
|
80
|
+
base_url: https://openrouter.ai/api/v1
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## Merge
|
|
84
|
+
|
|
85
|
+
```python
|
|
86
|
+
base = Config.load("base.yaml")
|
|
87
|
+
local = Config.load("local.yaml")
|
|
88
|
+
merged = base.merge(local) # local wins on conflict; non-destructive
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## License
|
|
92
|
+
|
|
93
|
+
MIT © 2026 digital-duck
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# 01 — dd-config Basics
|
|
2
|
+
|
|
3
|
+
Demonstrates core `dd-config` features:
|
|
4
|
+
|
|
5
|
+
- Load JSON / YAML config files
|
|
6
|
+
- Dot-path access (`cfg["database.host"]`)
|
|
7
|
+
- Override layering (base + local + `.env`)
|
|
8
|
+
- Format conversion (`Config.convert`)
|
|
9
|
+
- Validation (required keys + type checking)
|
|
10
|
+
- Env-var interpolation (`${VAR:-default}`)
|
|
11
|
+
|
|
12
|
+
## Run
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
pip install -r requirements.txt
|
|
16
|
+
python main.py
|
|
17
|
+
```
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"""dd-config basics cookbook.
|
|
2
|
+
|
|
3
|
+
Run with:
|
|
4
|
+
python main.py
|
|
5
|
+
"""
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
import json
|
|
9
|
+
import tempfile
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
|
|
12
|
+
from dd_config import Config, ValidationError
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def section(title: str) -> None:
|
|
16
|
+
print(f"\n{'='*60}")
|
|
17
|
+
print(f" {title}")
|
|
18
|
+
print('='*60)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def main() -> None:
|
|
22
|
+
with tempfile.TemporaryDirectory() as tmpdir:
|
|
23
|
+
root = Path(tmpdir)
|
|
24
|
+
|
|
25
|
+
# ------------------------------------------------------------------ #
|
|
26
|
+
# 1. Write sample config files
|
|
27
|
+
# ------------------------------------------------------------------ #
|
|
28
|
+
base_cfg = root / "app.json"
|
|
29
|
+
base_cfg.write_text(json.dumps({
|
|
30
|
+
"app": "my-service",
|
|
31
|
+
"port": 8080,
|
|
32
|
+
"debug": False,
|
|
33
|
+
"database": {
|
|
34
|
+
"host": "${DB_HOST:-localhost}",
|
|
35
|
+
"port": 5432,
|
|
36
|
+
"name": "mydb",
|
|
37
|
+
},
|
|
38
|
+
}, indent=2))
|
|
39
|
+
|
|
40
|
+
local_cfg = root / "local.json"
|
|
41
|
+
local_cfg.write_text(json.dumps({"debug": True, "port": 9090}))
|
|
42
|
+
|
|
43
|
+
env_file = root / ".env"
|
|
44
|
+
env_file.write_text("DB_HOST=db.example.com\nAPI_KEY=secret123\n")
|
|
45
|
+
|
|
46
|
+
# ------------------------------------------------------------------ #
|
|
47
|
+
# 2. Basic load
|
|
48
|
+
# ------------------------------------------------------------------ #
|
|
49
|
+
section("1. Basic load")
|
|
50
|
+
cfg = Config.load(base_cfg)
|
|
51
|
+
print(f"app : {cfg['app']}")
|
|
52
|
+
print(f"port : {cfg['port']}")
|
|
53
|
+
print(f"repr : {cfg}")
|
|
54
|
+
|
|
55
|
+
# ------------------------------------------------------------------ #
|
|
56
|
+
# 3. Dot-path access
|
|
57
|
+
# ------------------------------------------------------------------ #
|
|
58
|
+
section("2. Dot-path access")
|
|
59
|
+
print(f"database.host : {cfg['database.host']}")
|
|
60
|
+
print(f"database.port : {cfg['database.port']}")
|
|
61
|
+
print(f"get missing : {cfg.get('missing_key', 'DEFAULT')}")
|
|
62
|
+
|
|
63
|
+
# ------------------------------------------------------------------ #
|
|
64
|
+
# 4. Layered loading with overrides
|
|
65
|
+
# ------------------------------------------------------------------ #
|
|
66
|
+
section("3. Layered loading (base + local + .env)")
|
|
67
|
+
full_cfg = Config.load(base_cfg, overrides=[local_cfg, env_file])
|
|
68
|
+
print(f"port (overridden) : {full_cfg['port']}")
|
|
69
|
+
print(f"debug (overridden) : {full_cfg['debug']}")
|
|
70
|
+
print(f"database.host (from env): {full_cfg['database.host']}")
|
|
71
|
+
print(f"API_KEY (from .env) : {full_cfg.get('API_KEY', 'NOT FOUND')}")
|
|
72
|
+
print(f"sources: {full_cfg.info.sources}")
|
|
73
|
+
|
|
74
|
+
# ------------------------------------------------------------------ #
|
|
75
|
+
# 5. Mutation + save
|
|
76
|
+
# ------------------------------------------------------------------ #
|
|
77
|
+
section("4. Mutation + save")
|
|
78
|
+
cfg["port"] = 7070
|
|
79
|
+
cfg["database.name"] = "newdb"
|
|
80
|
+
out = root / "updated.json"
|
|
81
|
+
cfg.save(out)
|
|
82
|
+
reloaded = Config.load(out)
|
|
83
|
+
print(f"saved port : {reloaded['port']}")
|
|
84
|
+
print(f"saved db name : {reloaded['database.name']}")
|
|
85
|
+
|
|
86
|
+
# ------------------------------------------------------------------ #
|
|
87
|
+
# 6. Format conversion
|
|
88
|
+
# ------------------------------------------------------------------ #
|
|
89
|
+
section("5. Format conversion (JSON → YAML)")
|
|
90
|
+
try:
|
|
91
|
+
import yaml # noqa: F401
|
|
92
|
+
yaml_out = root / "app.yaml"
|
|
93
|
+
Config.convert(base_cfg, yaml_out)
|
|
94
|
+
yaml_cfg = Config.load(yaml_out)
|
|
95
|
+
print(f"YAML app : {yaml_cfg['app']}")
|
|
96
|
+
print(f"YAML port : {yaml_cfg['port']}")
|
|
97
|
+
except ImportError:
|
|
98
|
+
print("pyyaml not installed — skipping YAML conversion demo")
|
|
99
|
+
|
|
100
|
+
# ------------------------------------------------------------------ #
|
|
101
|
+
# 7. Validation
|
|
102
|
+
# ------------------------------------------------------------------ #
|
|
103
|
+
section("6. Validation")
|
|
104
|
+
cfg2 = Config.load(base_cfg)
|
|
105
|
+
try:
|
|
106
|
+
cfg2.validate(
|
|
107
|
+
required=["app", "database.host"],
|
|
108
|
+
schema={"port": int, "app": str},
|
|
109
|
+
)
|
|
110
|
+
print("Validation passed ✓")
|
|
111
|
+
except ValidationError as exc:
|
|
112
|
+
print(f"Validation failed: {exc}")
|
|
113
|
+
|
|
114
|
+
# Trigger a validation failure
|
|
115
|
+
cfg3 = Config.from_dict({"app": "test"})
|
|
116
|
+
try:
|
|
117
|
+
cfg3.validate(required=["missing_required_key"])
|
|
118
|
+
except ValidationError as exc:
|
|
119
|
+
print(f"Expected ValidationError caught: {exc}")
|
|
120
|
+
|
|
121
|
+
# ------------------------------------------------------------------ #
|
|
122
|
+
# 8. Info / introspection
|
|
123
|
+
# ------------------------------------------------------------------ #
|
|
124
|
+
section("7. Introspection")
|
|
125
|
+
info = cfg2.info
|
|
126
|
+
print(f"format : {info.format}")
|
|
127
|
+
print(f"sources : {info.sources}")
|
|
128
|
+
print(f"keys : {list(cfg2.keys())}")
|
|
129
|
+
d = cfg2.to_dict()
|
|
130
|
+
print(f"to_dict type: {type(d).__name__}")
|
|
131
|
+
|
|
132
|
+
print("\nAll done!")
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
if __name__ == "__main__":
|
|
136
|
+
main()
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
dd-config[all]
|