gpconfig 0.3.2__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.
- gpconfig-0.3.2/.github/workflows/docs.yml +44 -0
- gpconfig-0.3.2/.github/workflows/python-publish.yml +71 -0
- gpconfig-0.3.2/.gitignore +219 -0
- gpconfig-0.3.2/LICENSE +21 -0
- gpconfig-0.3.2/PKG-INFO +200 -0
- gpconfig-0.3.2/README.md +166 -0
- gpconfig-0.3.2/README.zh-CN.md +166 -0
- gpconfig-0.3.2/docs/configurable.md +239 -0
- gpconfig-0.3.2/docs/exceptions.md +268 -0
- gpconfig-0.3.2/docs/gpconfig.md +270 -0
- gpconfig-0.3.2/docs/index.md +160 -0
- gpconfig-0.3.2/docs/manager.md +464 -0
- gpconfig-0.3.2/docs/zh/configurable.md +239 -0
- gpconfig-0.3.2/docs/zh/exceptions.md +268 -0
- gpconfig-0.3.2/docs/zh/gpconfig.md +270 -0
- gpconfig-0.3.2/docs/zh/index.md +160 -0
- gpconfig-0.3.2/docs/zh/manager.md +464 -0
- gpconfig-0.3.2/mkdocs.yml +55 -0
- gpconfig-0.3.2/pyproject.toml +54 -0
- gpconfig-0.3.2/src/gpconfig/__init__.py +31 -0
- gpconfig-0.3.2/src/gpconfig/config.py +59 -0
- gpconfig-0.3.2/src/gpconfig/configurable.py +31 -0
- gpconfig-0.3.2/src/gpconfig/exceptions.py +43 -0
- gpconfig-0.3.2/src/gpconfig/manager.py +744 -0
- gpconfig-0.3.2/tests/__init__.py +1 -0
- gpconfig-0.3.2/tests/mock_configs/app.yaml +8 -0
- gpconfig-0.3.2/tests/mock_configs/cache/memcached.yaml +7 -0
- gpconfig-0.3.2/tests/mock_configs/cache/redis.yaml +7 -0
- gpconfig-0.3.2/tests/mock_configs/database.yaml +10 -0
- gpconfig-0.3.2/tests/mock_configs/databases/primary/postgres.yaml +7 -0
- gpconfig-0.3.2/tests/mock_configs/databases/replica/postgres.yaml +7 -0
- gpconfig-0.3.2/tests/mock_configs/global_env.yaml +7 -0
- gpconfig-0.3.2/tests/mock_configs/readonly_config.yaml +4 -0
- gpconfig-0.3.2/tests/mock_configs/services/api/v1/config.yaml +7 -0
- gpconfig-0.3.2/tests/mock_configs/services/api/v2/config.yaml +8 -0
- gpconfig-0.3.2/tests/mock_configs/services/workers/email.yaml +6 -0
- gpconfig-0.3.2/tests/mock_configs/services/workers/notification.yaml +6 -0
- gpconfig-0.3.2/tests/test_config.py +184 -0
- gpconfig-0.3.2/tests/test_configurable.py +57 -0
- gpconfig-0.3.2/tests/test_exceptions.py +67 -0
- gpconfig-0.3.2/tests/test_exports.py +54 -0
- gpconfig-0.3.2/tests/test_gpconfig_folder.py +126 -0
- gpconfig-0.3.2/tests/test_integration.py +210 -0
- gpconfig-0.3.2/tests/test_manager_get_config.py +122 -0
- gpconfig-0.3.2/tests/test_manager_init.py +123 -0
- gpconfig-0.3.2/tests/test_manager_make_new_folder.py +184 -0
- gpconfig-0.3.2/tests/test_manager_objects.py +250 -0
- gpconfig-0.3.2/tests/test_manager_path_parsing.py +83 -0
- gpconfig-0.3.2/tests/test_mock_configs.py +885 -0
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
name: Deploy Docs
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- mkdocs_pre_publish
|
|
7
|
+
paths:
|
|
8
|
+
- docs/**
|
|
9
|
+
- mkdocs.yml
|
|
10
|
+
- .github/workflows/docs.yml
|
|
11
|
+
workflow_dispatch:
|
|
12
|
+
|
|
13
|
+
permissions:
|
|
14
|
+
contents: read
|
|
15
|
+
pages: write
|
|
16
|
+
id-token: write
|
|
17
|
+
|
|
18
|
+
concurrency:
|
|
19
|
+
group: pages
|
|
20
|
+
cancel-in-progress: true
|
|
21
|
+
|
|
22
|
+
jobs:
|
|
23
|
+
build:
|
|
24
|
+
runs-on: ubuntu-latest
|
|
25
|
+
steps:
|
|
26
|
+
- uses: actions/checkout@v4
|
|
27
|
+
- uses: actions/setup-python@v5
|
|
28
|
+
with:
|
|
29
|
+
python-version: "3.12"
|
|
30
|
+
- run: pip install mkdocs-material mkdocs-static-i18n
|
|
31
|
+
- run: mkdocs build
|
|
32
|
+
- uses: actions/upload-pages-artifact@v3
|
|
33
|
+
with:
|
|
34
|
+
path: site
|
|
35
|
+
|
|
36
|
+
deploy:
|
|
37
|
+
needs: build
|
|
38
|
+
runs-on: ubuntu-latest
|
|
39
|
+
environment:
|
|
40
|
+
name: github-pages
|
|
41
|
+
url: ${{ steps.deployment.outputs.page_url }}
|
|
42
|
+
steps:
|
|
43
|
+
- uses: actions/deploy-pages@v5
|
|
44
|
+
id: deployment
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# This workflow will upload a Python Package to PyPI when a release is created
|
|
2
|
+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries
|
|
3
|
+
|
|
4
|
+
# This workflow uses actions that are not certified by GitHub.
|
|
5
|
+
# They are provided by a third-party and are governed by
|
|
6
|
+
# separate terms of service, privacy policy, and support
|
|
7
|
+
# documentation.
|
|
8
|
+
|
|
9
|
+
name: Upload Python Package
|
|
10
|
+
|
|
11
|
+
on:
|
|
12
|
+
release:
|
|
13
|
+
types: [published]
|
|
14
|
+
workflow_dispatch:
|
|
15
|
+
|
|
16
|
+
permissions:
|
|
17
|
+
contents: read
|
|
18
|
+
|
|
19
|
+
jobs:
|
|
20
|
+
release-build:
|
|
21
|
+
runs-on: ubuntu-latest
|
|
22
|
+
|
|
23
|
+
steps:
|
|
24
|
+
- uses: actions/checkout@v5
|
|
25
|
+
|
|
26
|
+
- uses: actions/setup-python@v6
|
|
27
|
+
with:
|
|
28
|
+
python-version: "3.x"
|
|
29
|
+
|
|
30
|
+
- name: Build release distributions
|
|
31
|
+
run: |
|
|
32
|
+
# NOTE: put your own distribution build steps here.
|
|
33
|
+
python -m pip install build
|
|
34
|
+
python -m build
|
|
35
|
+
|
|
36
|
+
- name: Upload distributions
|
|
37
|
+
uses: actions/upload-artifact@v5
|
|
38
|
+
with:
|
|
39
|
+
name: release-dists
|
|
40
|
+
path: dist/
|
|
41
|
+
|
|
42
|
+
pypi-publish:
|
|
43
|
+
runs-on: ubuntu-latest
|
|
44
|
+
needs:
|
|
45
|
+
- release-build
|
|
46
|
+
permissions:
|
|
47
|
+
# IMPORTANT: this permission is mandatory for trusted publishing
|
|
48
|
+
id-token: write
|
|
49
|
+
|
|
50
|
+
# Dedicated environments with protections for publishing are strongly recommended.
|
|
51
|
+
# For more information, see: https://docs.github.com/en/actions/deployment/targeting-different-environments/using-environments-for-deployment#deployment-protection-rules
|
|
52
|
+
environment:
|
|
53
|
+
name: pypi
|
|
54
|
+
# OPTIONAL: uncomment and update to include your PyPI project URL in the deployment status:
|
|
55
|
+
url: https://pypi.org/project/gpconfig
|
|
56
|
+
#
|
|
57
|
+
# ALTERNATIVE: if your GitHub Release name is the PyPI project version string
|
|
58
|
+
# ALTERNATIVE: exactly, uncomment the following line instead:
|
|
59
|
+
# url: https://pypi.org/project/YOURPROJECT/${{ github.event.release.name }}
|
|
60
|
+
|
|
61
|
+
steps:
|
|
62
|
+
- name: Retrieve release distributions
|
|
63
|
+
uses: actions/download-artifact@v5
|
|
64
|
+
with:
|
|
65
|
+
name: release-dists
|
|
66
|
+
path: dist/
|
|
67
|
+
|
|
68
|
+
- name: Publish release distributions to PyPI
|
|
69
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
70
|
+
with:
|
|
71
|
+
packages-dir: dist/
|
|
@@ -0,0 +1,219 @@
|
|
|
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__/
|
|
208
|
+
|
|
209
|
+
# Claude Code
|
|
210
|
+
CLAUDE.md
|
|
211
|
+
.claude/
|
|
212
|
+
|
|
213
|
+
# OpenCode
|
|
214
|
+
AGENTS.md
|
|
215
|
+
.opencode/
|
|
216
|
+
|
|
217
|
+
# User excluded
|
|
218
|
+
draft/
|
|
219
|
+
dev_docs/
|
gpconfig-0.3.2/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 LinnetCodes
|
|
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.
|
gpconfig-0.3.2/PKG-INFO
ADDED
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: gpconfig
|
|
3
|
+
Version: 0.3.2
|
|
4
|
+
Summary: A type-safe, YAML-based configuration management library built on Pydantic
|
|
5
|
+
Project-URL: Homepage, https://github.com/LinnetCodes/gpconfig
|
|
6
|
+
Project-URL: Documentation, https://linnetcodes.github.io/gpconfig
|
|
7
|
+
Project-URL: Repository, https://github.com/LinnetCodes/gpconfig
|
|
8
|
+
Project-URL: Issues, https://github.com/LinnetCodes/gpconfig/issues
|
|
9
|
+
Author-email: HAN Lin <lin_han@foxmail.com>
|
|
10
|
+
License-Expression: MIT
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: config,configuration,pydantic,settings,type-safe,yaml
|
|
13
|
+
Classifier: Development Status :: 3 - Alpha
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
22
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
23
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
24
|
+
Classifier: Typing :: Typed
|
|
25
|
+
Requires-Python: >=3.10
|
|
26
|
+
Requires-Dist: pydantic-settings>=2.0
|
|
27
|
+
Requires-Dist: pydantic>=2.0
|
|
28
|
+
Requires-Dist: pyyaml>=6.0
|
|
29
|
+
Provides-Extra: dev
|
|
30
|
+
Requires-Dist: pytest-cov>=4.0; extra == 'dev'
|
|
31
|
+
Requires-Dist: pytest>=8.0; extra == 'dev'
|
|
32
|
+
Requires-Dist: ruff>=0.4.0; extra == 'dev'
|
|
33
|
+
Description-Content-Type: text/markdown
|
|
34
|
+
|
|
35
|
+
# gpconfig
|
|
36
|
+
|
|
37
|
+
[简体中文](README.zh-CN.md) | English
|
|
38
|
+
|
|
39
|
+
General Purpose Configuration management library for Python projects.
|
|
40
|
+
|
|
41
|
+
A type-safe, YAML-based configuration management library built on Pydantic.
|
|
42
|
+
|
|
43
|
+
## Features
|
|
44
|
+
|
|
45
|
+
- **Type-safe configuration** - Built on Pydantic with full type validation
|
|
46
|
+
- **YAML-based** - Human-readable configuration files
|
|
47
|
+
- **Nested configs** - Organize configs in directories (e.g., `llm/openai.yaml`)
|
|
48
|
+
- **Auto-detection** - Automatically detect config classes from YAML files
|
|
49
|
+
- **Configurable objects** - Create object instances directly from configs
|
|
50
|
+
- **Environment variable support** - Configure paths via environment variables
|
|
51
|
+
- **Readonly configs** - Protect sensitive configurations
|
|
52
|
+
|
|
53
|
+
## Installation
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
pip install gpconfig
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Quick Start
|
|
60
|
+
|
|
61
|
+
### 1. Define Config Classes
|
|
62
|
+
|
|
63
|
+
```python
|
|
64
|
+
from typing import ClassVar
|
|
65
|
+
from gpconfig import GPConfig
|
|
66
|
+
|
|
67
|
+
class DatabaseConfig(GPConfig):
|
|
68
|
+
cfg_class_name: ClassVar[str] = "DatabaseConfig"
|
|
69
|
+
host: str
|
|
70
|
+
port: int = 5432
|
|
71
|
+
username: str
|
|
72
|
+
password: str
|
|
73
|
+
database: str
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### 2. Create Config Folder
|
|
77
|
+
|
|
78
|
+
```
|
|
79
|
+
myapp/
|
|
80
|
+
├── global_env.yaml # Required: global environment config
|
|
81
|
+
├── database.yaml # Your config files
|
|
82
|
+
└── llm/ # Nested configs
|
|
83
|
+
├── openai.yaml
|
|
84
|
+
└── anthropic.yaml
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
**global_env.yaml:**
|
|
88
|
+
```yaml
|
|
89
|
+
version: "1.0.0"
|
|
90
|
+
debug: true
|
|
91
|
+
log_level: INFO
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
**database.yaml:**
|
|
95
|
+
```yaml
|
|
96
|
+
cfg_class_name: "DatabaseConfig"
|
|
97
|
+
host: localhost
|
|
98
|
+
port: 5432
|
|
99
|
+
username: admin
|
|
100
|
+
password: secret
|
|
101
|
+
database: myapp
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### 3. Initialize Manager and Load Configs
|
|
105
|
+
|
|
106
|
+
```python
|
|
107
|
+
from gpconfig import GPConfigManager
|
|
108
|
+
|
|
109
|
+
# Config folder search order:
|
|
110
|
+
# 1. Explicit cfg_folder parameter
|
|
111
|
+
# 2. Environment variable: {PROJECT_NAME}_CFG_PATH
|
|
112
|
+
# 3. User directory: ~/.{project_name}/
|
|
113
|
+
manager = GPConfigManager("myapp", cfg_folder="/path/to/myapp")
|
|
114
|
+
|
|
115
|
+
# Read global_env values
|
|
116
|
+
debug = manager.get_config("global_env.debug")
|
|
117
|
+
|
|
118
|
+
# Load config (auto-detect class by cfg_class_name)
|
|
119
|
+
db_config = manager.get_config("database")
|
|
120
|
+
|
|
121
|
+
# Load nested config
|
|
122
|
+
llm_config = manager.get_config("llm.openai")
|
|
123
|
+
|
|
124
|
+
# Read specific field
|
|
125
|
+
host = manager.get_config("database.host")
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
### 4. Create Configurable Objects
|
|
129
|
+
|
|
130
|
+
```python
|
|
131
|
+
from gpconfig import GPConfigurable
|
|
132
|
+
|
|
133
|
+
class Database(GPConfigurable):
|
|
134
|
+
def __init__(self, config: DatabaseConfig) -> None:
|
|
135
|
+
super().__init__(config)
|
|
136
|
+
self.host = config.host
|
|
137
|
+
self.port = config.port
|
|
138
|
+
self.username = config.username
|
|
139
|
+
self.password = config.password
|
|
140
|
+
self.database = config.database
|
|
141
|
+
|
|
142
|
+
@property
|
|
143
|
+
def connection_string(self) -> str:
|
|
144
|
+
return f"postgresql://{self.username}:{self.password}@{self.host}:{self.port}/{self.database}"
|
|
145
|
+
|
|
146
|
+
# Register classes
|
|
147
|
+
GPConfigManager.register_config_class(DatabaseConfig)
|
|
148
|
+
GPConfigManager.register_configurable_class(Database)
|
|
149
|
+
|
|
150
|
+
# Create object instance
|
|
151
|
+
db = manager.get_object("database")
|
|
152
|
+
print(db.connection_string)
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
**Note:** Add `configured_class_name` to your YAML for `get_object()`:
|
|
156
|
+
|
|
157
|
+
```yaml
|
|
158
|
+
cfg_class_name: "DatabaseConfig"
|
|
159
|
+
configured_class_name: "Database"
|
|
160
|
+
host: localhost
|
|
161
|
+
port: 5432
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
### 5. Save Configs
|
|
165
|
+
|
|
166
|
+
```python
|
|
167
|
+
# Modify and save
|
|
168
|
+
db_config.port = 5433
|
|
169
|
+
db_config.save()
|
|
170
|
+
|
|
171
|
+
# Save to new location
|
|
172
|
+
manager.save(db_config, "backups/database_backup")
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
## Core Components
|
|
176
|
+
|
|
177
|
+
| Component | Description |
|
|
178
|
+
|-----------|-------------|
|
|
179
|
+
| `GPConfig` | Base class for all config classes |
|
|
180
|
+
| `GPConfigurable` | Base class for objects created from configs |
|
|
181
|
+
| `GPConfigManager` | Manages config folder, loading, and object creation |
|
|
182
|
+
|
|
183
|
+
## Exceptions
|
|
184
|
+
|
|
185
|
+
| Exception | Description |
|
|
186
|
+
|-----------|-------------|
|
|
187
|
+
| `GPConfigError` | Base exception for all gpconfig errors |
|
|
188
|
+
| `ConfigFolderError` | Config folder not found or invalid |
|
|
189
|
+
| `ConfigNotFoundError` | Requested config path does not exist |
|
|
190
|
+
| `ConfigReadonlyError` | Attempted to modify readonly config |
|
|
191
|
+
| `RegistrationError` | Class registration issues |
|
|
192
|
+
| `ConfigValidationError` | Config file validation failed |
|
|
193
|
+
|
|
194
|
+
## API Reference
|
|
195
|
+
|
|
196
|
+
See the [API documentation](docs/api/en/index.md) for detailed usage.
|
|
197
|
+
|
|
198
|
+
## License
|
|
199
|
+
|
|
200
|
+
MIT
|