confkit 0.1.1__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.
- confkit-0.1.1/.github/workflows/pypi.yml +50 -0
- confkit-0.1.1/.github/workflows/test.yml +36 -0
- confkit-0.1.1/.gitignore +207 -0
- confkit-0.1.1/.python-version +1 -0
- confkit-0.1.1/.vscode/settings.json +10 -0
- confkit-0.1.1/PKG-INFO +143 -0
- confkit-0.1.1/README.md +135 -0
- confkit-0.1.1/examples/basic.py +21 -0
- confkit-0.1.1/examples/config.ini +16 -0
- confkit-0.1.1/examples/decorators.py +28 -0
- confkit-0.1.1/examples/enums.py +25 -0
- confkit-0.1.1/pyproject.toml +23 -0
- confkit-0.1.1/ruff.toml +7 -0
- confkit-0.1.1/src/confkit/__init__.py +37 -0
- confkit-0.1.1/src/confkit/config.py +299 -0
- confkit-0.1.1/src/confkit/data_types.py +154 -0
- confkit-0.1.1/src/confkit/exceptions.py +8 -0
- confkit-0.1.1/src/confkit/py.typed +0 -0
- confkit-0.1.1/src/confkit/sentinels.py +21 -0
- confkit-0.1.1/tests/__init__.py +1 -0
- confkit-0.1.1/tests/test_config.py +338 -0
- confkit-0.1.1/tests/test_sentinel.py +29 -0
- confkit-0.1.1/uv.lock +212 -0
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
name: Publish Python 🐍 distribution 📦 to PyPI and TestPyPI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
workflow_dispatch:
|
|
5
|
+
|
|
6
|
+
jobs:
|
|
7
|
+
build:
|
|
8
|
+
name: Build distribution 📦
|
|
9
|
+
runs-on: ubuntu-latest
|
|
10
|
+
|
|
11
|
+
steps:
|
|
12
|
+
- uses: actions/checkout@v4
|
|
13
|
+
with:
|
|
14
|
+
persist-credentials: false
|
|
15
|
+
- name: Set up Python
|
|
16
|
+
uses: actions/setup-python@v5
|
|
17
|
+
with:
|
|
18
|
+
python-version: "3.x"
|
|
19
|
+
- name: Install pypa/build
|
|
20
|
+
run: >-
|
|
21
|
+
python3 -m
|
|
22
|
+
pip install
|
|
23
|
+
uv
|
|
24
|
+
- name: Build a binary wheel and a source tarball
|
|
25
|
+
run: uv build --sdist --wheel --out-dir dist
|
|
26
|
+
- name: Store the distribution packages
|
|
27
|
+
uses: actions/upload-artifact@v4
|
|
28
|
+
with:
|
|
29
|
+
name: python-package-distributions
|
|
30
|
+
path: dist/
|
|
31
|
+
|
|
32
|
+
publish-to-pypi:
|
|
33
|
+
name: Publish Python 🐍 distribution 📦 to PyPI
|
|
34
|
+
needs:
|
|
35
|
+
- build
|
|
36
|
+
runs-on: ubuntu-latest
|
|
37
|
+
environment:
|
|
38
|
+
name: pypi
|
|
39
|
+
url: https://pypi.org/p/confkit
|
|
40
|
+
permissions:
|
|
41
|
+
id-token: write # IMPORTANT: mandatory for trusted publishing
|
|
42
|
+
|
|
43
|
+
steps:
|
|
44
|
+
- name: Download all the dists
|
|
45
|
+
uses: actions/download-artifact@v4
|
|
46
|
+
with:
|
|
47
|
+
name: python-package-distributions
|
|
48
|
+
path: dist/
|
|
49
|
+
- name: Publish distribution 📦 to PyPI
|
|
50
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
name: Test
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [ master ]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [ master ]
|
|
8
|
+
workflow_dispatch:
|
|
9
|
+
workflow_call:
|
|
10
|
+
|
|
11
|
+
jobs:
|
|
12
|
+
test:
|
|
13
|
+
runs-on: ubuntu-latest
|
|
14
|
+
|
|
15
|
+
steps:
|
|
16
|
+
- uses: actions/checkout@v4
|
|
17
|
+
|
|
18
|
+
- name: Install uv
|
|
19
|
+
uses: astral-sh/setup-uv@v4
|
|
20
|
+
with:
|
|
21
|
+
version: "latest"
|
|
22
|
+
|
|
23
|
+
- name: Set up Python
|
|
24
|
+
run: uv python install 3.13
|
|
25
|
+
|
|
26
|
+
- name: Install dependencies
|
|
27
|
+
run: uv sync --group dev
|
|
28
|
+
|
|
29
|
+
- name: Run tests
|
|
30
|
+
run: uv run pytest .
|
|
31
|
+
|
|
32
|
+
- name: Run ruff check
|
|
33
|
+
run: uv run ruff check .
|
|
34
|
+
|
|
35
|
+
- name: Run type checking
|
|
36
|
+
run: uvx ty check .
|
confkit-0.1.1/.gitignore
ADDED
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
# https://github.com/github/gitignore/blob/main/Python.gitignore
|
|
2
|
+
# Byte-compiled / optimized / DLL files
|
|
3
|
+
__pycache__/
|
|
4
|
+
*.py[codz]
|
|
5
|
+
*$py.class
|
|
6
|
+
|
|
7
|
+
# C extensions
|
|
8
|
+
*.so
|
|
9
|
+
|
|
10
|
+
# Distribution / packaging
|
|
11
|
+
.Python
|
|
12
|
+
build/
|
|
13
|
+
develop-eggs/
|
|
14
|
+
dist/
|
|
15
|
+
downloads/
|
|
16
|
+
eggs/
|
|
17
|
+
.eggs/
|
|
18
|
+
lib/
|
|
19
|
+
lib64/
|
|
20
|
+
parts/
|
|
21
|
+
sdist/
|
|
22
|
+
var/
|
|
23
|
+
wheels/
|
|
24
|
+
share/python-wheels/
|
|
25
|
+
*.egg-info/
|
|
26
|
+
.installed.cfg
|
|
27
|
+
*.egg
|
|
28
|
+
MANIFEST
|
|
29
|
+
|
|
30
|
+
# PyInstaller
|
|
31
|
+
# Usually these files are written by a python script from a template
|
|
32
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
33
|
+
*.manifest
|
|
34
|
+
*.spec
|
|
35
|
+
|
|
36
|
+
# Installer logs
|
|
37
|
+
pip-log.txt
|
|
38
|
+
pip-delete-this-directory.txt
|
|
39
|
+
|
|
40
|
+
# Unit test / coverage reports
|
|
41
|
+
htmlcov/
|
|
42
|
+
.tox/
|
|
43
|
+
.nox/
|
|
44
|
+
.coverage
|
|
45
|
+
.coverage.*
|
|
46
|
+
.cache
|
|
47
|
+
nosetests.xml
|
|
48
|
+
coverage.xml
|
|
49
|
+
*.cover
|
|
50
|
+
*.py.cover
|
|
51
|
+
.hypothesis/
|
|
52
|
+
.pytest_cache/
|
|
53
|
+
cover/
|
|
54
|
+
|
|
55
|
+
# Translations
|
|
56
|
+
*.mo
|
|
57
|
+
*.pot
|
|
58
|
+
|
|
59
|
+
# Django stuff:
|
|
60
|
+
*.log
|
|
61
|
+
local_settings.py
|
|
62
|
+
db.sqlite3
|
|
63
|
+
db.sqlite3-journal
|
|
64
|
+
|
|
65
|
+
# Flask stuff:
|
|
66
|
+
instance/
|
|
67
|
+
.webassets-cache
|
|
68
|
+
|
|
69
|
+
# Scrapy stuff:
|
|
70
|
+
.scrapy
|
|
71
|
+
|
|
72
|
+
# Sphinx documentation
|
|
73
|
+
docs/_build/
|
|
74
|
+
|
|
75
|
+
# PyBuilder
|
|
76
|
+
.pybuilder/
|
|
77
|
+
target/
|
|
78
|
+
|
|
79
|
+
# Jupyter Notebook
|
|
80
|
+
.ipynb_checkpoints
|
|
81
|
+
|
|
82
|
+
# IPython
|
|
83
|
+
profile_default/
|
|
84
|
+
ipython_config.py
|
|
85
|
+
|
|
86
|
+
# pyenv
|
|
87
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
88
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
89
|
+
# .python-version
|
|
90
|
+
|
|
91
|
+
# pipenv
|
|
92
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
93
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
94
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
95
|
+
# install all needed dependencies.
|
|
96
|
+
#Pipfile.lock
|
|
97
|
+
|
|
98
|
+
# UV
|
|
99
|
+
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
|
|
100
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
101
|
+
# commonly ignored for libraries.
|
|
102
|
+
#uv.lock
|
|
103
|
+
|
|
104
|
+
# poetry
|
|
105
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
106
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
107
|
+
# commonly ignored for libraries.
|
|
108
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
109
|
+
#poetry.lock
|
|
110
|
+
#poetry.toml
|
|
111
|
+
|
|
112
|
+
# pdm
|
|
113
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
114
|
+
# pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
|
|
115
|
+
# https://pdm-project.org/en/latest/usage/project/#working-with-version-control
|
|
116
|
+
#pdm.lock
|
|
117
|
+
#pdm.toml
|
|
118
|
+
.pdm-python
|
|
119
|
+
.pdm-build/
|
|
120
|
+
|
|
121
|
+
# pixi
|
|
122
|
+
# Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
|
|
123
|
+
#pixi.lock
|
|
124
|
+
# Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
|
|
125
|
+
# in the .venv directory. It is recommended not to include this directory in version control.
|
|
126
|
+
.pixi
|
|
127
|
+
|
|
128
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
129
|
+
__pypackages__/
|
|
130
|
+
|
|
131
|
+
# Celery stuff
|
|
132
|
+
celerybeat-schedule
|
|
133
|
+
celerybeat.pid
|
|
134
|
+
|
|
135
|
+
# SageMath parsed files
|
|
136
|
+
*.sage.py
|
|
137
|
+
|
|
138
|
+
# Environments
|
|
139
|
+
.env
|
|
140
|
+
.envrc
|
|
141
|
+
.venv
|
|
142
|
+
env/
|
|
143
|
+
venv/
|
|
144
|
+
ENV/
|
|
145
|
+
env.bak/
|
|
146
|
+
venv.bak/
|
|
147
|
+
|
|
148
|
+
# Spyder project settings
|
|
149
|
+
.spyderproject
|
|
150
|
+
.spyproject
|
|
151
|
+
|
|
152
|
+
# Rope project settings
|
|
153
|
+
.ropeproject
|
|
154
|
+
|
|
155
|
+
# mkdocs documentation
|
|
156
|
+
/site
|
|
157
|
+
|
|
158
|
+
# mypy
|
|
159
|
+
.mypy_cache/
|
|
160
|
+
.dmypy.json
|
|
161
|
+
dmypy.json
|
|
162
|
+
|
|
163
|
+
# Pyre type checker
|
|
164
|
+
.pyre/
|
|
165
|
+
|
|
166
|
+
# pytype static type analyzer
|
|
167
|
+
.pytype/
|
|
168
|
+
|
|
169
|
+
# Cython debug symbols
|
|
170
|
+
cython_debug/
|
|
171
|
+
|
|
172
|
+
# PyCharm
|
|
173
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
174
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
175
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
176
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
177
|
+
#.idea/
|
|
178
|
+
|
|
179
|
+
# Abstra
|
|
180
|
+
# Abstra is an AI-powered process automation framework.
|
|
181
|
+
# Ignore directories containing user credentials, local state, and settings.
|
|
182
|
+
# Learn more at https://abstra.io/docs
|
|
183
|
+
.abstra/
|
|
184
|
+
|
|
185
|
+
# Visual Studio Code
|
|
186
|
+
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
|
|
187
|
+
# that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
|
|
188
|
+
# and can be added to the global gitignore or merged into this file. However, if you prefer,
|
|
189
|
+
# you could uncomment the following to ignore the entire vscode folder
|
|
190
|
+
# .vscode/
|
|
191
|
+
|
|
192
|
+
# Ruff stuff:
|
|
193
|
+
.ruff_cache/
|
|
194
|
+
|
|
195
|
+
# PyPI configuration file
|
|
196
|
+
.pypirc
|
|
197
|
+
|
|
198
|
+
# Marimo
|
|
199
|
+
marimo/_static/
|
|
200
|
+
marimo/_lsp/
|
|
201
|
+
__marimo__/
|
|
202
|
+
|
|
203
|
+
# Streamlit
|
|
204
|
+
.streamlit/secrets.toml
|
|
205
|
+
|
|
206
|
+
# Custom ignores
|
|
207
|
+
test.ini
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
3.13
|
confkit-0.1.1/PKG-INFO
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: confkit
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: Lightweight and Easy to use configuration manager for Python projects
|
|
5
|
+
Author-email: HEROgold <martijnwieringa28@gmail.com>
|
|
6
|
+
Requires-Python: >=3.13
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
|
|
9
|
+
# confkit
|
|
10
|
+
|
|
11
|
+
[](https://github.com/HEROgold/confkit/actions/workflows/test.yml)
|
|
12
|
+
|
|
13
|
+
Type-safe configuration manager for Python projects using descriptors and ConfigParser.
|
|
14
|
+
|
|
15
|
+
## What is it?
|
|
16
|
+
|
|
17
|
+
confkit is a Python library that provides type-safe configuration management with automatic type conversion and validation.
|
|
18
|
+
It uses descriptors to define configuration values as class attributes that automatically read from and write to INI files.
|
|
19
|
+
|
|
20
|
+
## What does it do?
|
|
21
|
+
|
|
22
|
+
- Type-safe configuration with automatic type conversion
|
|
23
|
+
- Automatic INI file management
|
|
24
|
+
- Default value handling with file persistence
|
|
25
|
+
- Optional value support
|
|
26
|
+
- Enum support (Enum, StrEnum, IntEnum, IntFlag)
|
|
27
|
+
- Method decorators for injecting configuration values
|
|
28
|
+
- Runtime type validation
|
|
29
|
+
|
|
30
|
+
## How to use it?
|
|
31
|
+
|
|
32
|
+
### Setup
|
|
33
|
+
|
|
34
|
+
```python
|
|
35
|
+
from configparser import ConfigParser
|
|
36
|
+
from pathlib import Path
|
|
37
|
+
from confkit import Config
|
|
38
|
+
|
|
39
|
+
parser = ConfigParser()
|
|
40
|
+
Config.set_parser(parser)
|
|
41
|
+
Config.set_file(Path("config.ini"))
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### Basic Usage
|
|
45
|
+
|
|
46
|
+
- Note: imports have been left out. see [examples/basic.py](basic.py) for the entire example.
|
|
47
|
+
|
|
48
|
+
```python
|
|
49
|
+
class AppConfig:
|
|
50
|
+
debug = Config(False)
|
|
51
|
+
port = Config(8080)
|
|
52
|
+
host = Config("localhost")
|
|
53
|
+
timeout = Config(30.5)
|
|
54
|
+
api_key = Config("", optional=True)
|
|
55
|
+
|
|
56
|
+
config = AppConfig()
|
|
57
|
+
print(config.debug) # False
|
|
58
|
+
config.port = 9000 # Automatically saves to config.ini if write_on_edit is true (default).
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### Enums and Custom Types
|
|
62
|
+
|
|
63
|
+
- Note: imports have been left out. see [examples/enums.py](enums.py) for the entire example.
|
|
64
|
+
|
|
65
|
+
```python
|
|
66
|
+
class LogLevel(StrEnum):
|
|
67
|
+
DEBUG = "debug"
|
|
68
|
+
INFO = "info"
|
|
69
|
+
ERROR = "error"
|
|
70
|
+
|
|
71
|
+
class ServerConfig:
|
|
72
|
+
log_level = Config(ConfigEnum(LogLevel.INFO))
|
|
73
|
+
db_url = Config(String("sqlite:///app.db"))
|
|
74
|
+
fallback_level = Config(Optional(ConfigEnum(LogLevel.ERROR)))
|
|
75
|
+
|
|
76
|
+
config = ServerConfig()
|
|
77
|
+
config.log_level = LogLevel.DEBUG # Type-safe
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### Method Decorators
|
|
81
|
+
|
|
82
|
+
- Note: imports have been left out. see [examples/decorators.py](decorators.py) for the entire example.
|
|
83
|
+
|
|
84
|
+
```python
|
|
85
|
+
class ServiceConfig:
|
|
86
|
+
retry_count = Config(3)
|
|
87
|
+
timeout = Config(30)
|
|
88
|
+
|
|
89
|
+
@Config.with_setting(retry_count)
|
|
90
|
+
def process(self, data, **kwargs):
|
|
91
|
+
retries = kwargs.get('retry_count')
|
|
92
|
+
return f"Processing with {retries} retries"
|
|
93
|
+
|
|
94
|
+
@Config.as_kwarg("ServiceConfig", "timeout", "request_timeout", 60)
|
|
95
|
+
def request(self, url, **kwargs):
|
|
96
|
+
timeout = kwargs.get('request_timeout')
|
|
97
|
+
return f"Request timeout: {timeout}s"
|
|
98
|
+
|
|
99
|
+
service = ServiceConfig()
|
|
100
|
+
result = service.process("data") # Uses current retry_count
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### Configuration File
|
|
104
|
+
|
|
105
|
+
Generated INI file structure see [examples/config.ini](config.ini) for the entire example.:
|
|
106
|
+
|
|
107
|
+
```ini
|
|
108
|
+
[AppConfig]
|
|
109
|
+
debug = False
|
|
110
|
+
port = 9000
|
|
111
|
+
host = localhost
|
|
112
|
+
timeout = 30.5
|
|
113
|
+
api_key =
|
|
114
|
+
|
|
115
|
+
[ServiceConfig]
|
|
116
|
+
retry_count = 3
|
|
117
|
+
timeout = 30
|
|
118
|
+
|
|
119
|
+
[ServerConfig]
|
|
120
|
+
log_level = debug
|
|
121
|
+
db_url = sqlite:///app.db
|
|
122
|
+
fallback_level = error
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
## How to contribute?
|
|
126
|
+
|
|
127
|
+
1. Fork the repository and clone locally
|
|
128
|
+
2. Install dependencies: `uv sync --group test`
|
|
129
|
+
3. Run tests: `pytest .`
|
|
130
|
+
4. Run linting: `ruff check .`
|
|
131
|
+
5. Make changes following existing patterns
|
|
132
|
+
6. Add tests for new functionality
|
|
133
|
+
7. Submit a pull request
|
|
134
|
+
|
|
135
|
+
### Development
|
|
136
|
+
|
|
137
|
+
```bash
|
|
138
|
+
git clone https://github.com/HEROgold/confkit.git
|
|
139
|
+
cd confkit
|
|
140
|
+
uv sync --group test
|
|
141
|
+
pytest .
|
|
142
|
+
ruff check .
|
|
143
|
+
```
|
confkit-0.1.1/README.md
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
# confkit
|
|
2
|
+
|
|
3
|
+
[](https://github.com/HEROgold/confkit/actions/workflows/test.yml)
|
|
4
|
+
|
|
5
|
+
Type-safe configuration manager for Python projects using descriptors and ConfigParser.
|
|
6
|
+
|
|
7
|
+
## What is it?
|
|
8
|
+
|
|
9
|
+
confkit is a Python library that provides type-safe configuration management with automatic type conversion and validation.
|
|
10
|
+
It uses descriptors to define configuration values as class attributes that automatically read from and write to INI files.
|
|
11
|
+
|
|
12
|
+
## What does it do?
|
|
13
|
+
|
|
14
|
+
- Type-safe configuration with automatic type conversion
|
|
15
|
+
- Automatic INI file management
|
|
16
|
+
- Default value handling with file persistence
|
|
17
|
+
- Optional value support
|
|
18
|
+
- Enum support (Enum, StrEnum, IntEnum, IntFlag)
|
|
19
|
+
- Method decorators for injecting configuration values
|
|
20
|
+
- Runtime type validation
|
|
21
|
+
|
|
22
|
+
## How to use it?
|
|
23
|
+
|
|
24
|
+
### Setup
|
|
25
|
+
|
|
26
|
+
```python
|
|
27
|
+
from configparser import ConfigParser
|
|
28
|
+
from pathlib import Path
|
|
29
|
+
from confkit import Config
|
|
30
|
+
|
|
31
|
+
parser = ConfigParser()
|
|
32
|
+
Config.set_parser(parser)
|
|
33
|
+
Config.set_file(Path("config.ini"))
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### Basic Usage
|
|
37
|
+
|
|
38
|
+
- Note: imports have been left out. see [examples/basic.py](basic.py) for the entire example.
|
|
39
|
+
|
|
40
|
+
```python
|
|
41
|
+
class AppConfig:
|
|
42
|
+
debug = Config(False)
|
|
43
|
+
port = Config(8080)
|
|
44
|
+
host = Config("localhost")
|
|
45
|
+
timeout = Config(30.5)
|
|
46
|
+
api_key = Config("", optional=True)
|
|
47
|
+
|
|
48
|
+
config = AppConfig()
|
|
49
|
+
print(config.debug) # False
|
|
50
|
+
config.port = 9000 # Automatically saves to config.ini if write_on_edit is true (default).
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### Enums and Custom Types
|
|
54
|
+
|
|
55
|
+
- Note: imports have been left out. see [examples/enums.py](enums.py) for the entire example.
|
|
56
|
+
|
|
57
|
+
```python
|
|
58
|
+
class LogLevel(StrEnum):
|
|
59
|
+
DEBUG = "debug"
|
|
60
|
+
INFO = "info"
|
|
61
|
+
ERROR = "error"
|
|
62
|
+
|
|
63
|
+
class ServerConfig:
|
|
64
|
+
log_level = Config(ConfigEnum(LogLevel.INFO))
|
|
65
|
+
db_url = Config(String("sqlite:///app.db"))
|
|
66
|
+
fallback_level = Config(Optional(ConfigEnum(LogLevel.ERROR)))
|
|
67
|
+
|
|
68
|
+
config = ServerConfig()
|
|
69
|
+
config.log_level = LogLevel.DEBUG # Type-safe
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### Method Decorators
|
|
73
|
+
|
|
74
|
+
- Note: imports have been left out. see [examples/decorators.py](decorators.py) for the entire example.
|
|
75
|
+
|
|
76
|
+
```python
|
|
77
|
+
class ServiceConfig:
|
|
78
|
+
retry_count = Config(3)
|
|
79
|
+
timeout = Config(30)
|
|
80
|
+
|
|
81
|
+
@Config.with_setting(retry_count)
|
|
82
|
+
def process(self, data, **kwargs):
|
|
83
|
+
retries = kwargs.get('retry_count')
|
|
84
|
+
return f"Processing with {retries} retries"
|
|
85
|
+
|
|
86
|
+
@Config.as_kwarg("ServiceConfig", "timeout", "request_timeout", 60)
|
|
87
|
+
def request(self, url, **kwargs):
|
|
88
|
+
timeout = kwargs.get('request_timeout')
|
|
89
|
+
return f"Request timeout: {timeout}s"
|
|
90
|
+
|
|
91
|
+
service = ServiceConfig()
|
|
92
|
+
result = service.process("data") # Uses current retry_count
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### Configuration File
|
|
96
|
+
|
|
97
|
+
Generated INI file structure see [examples/config.ini](config.ini) for the entire example.:
|
|
98
|
+
|
|
99
|
+
```ini
|
|
100
|
+
[AppConfig]
|
|
101
|
+
debug = False
|
|
102
|
+
port = 9000
|
|
103
|
+
host = localhost
|
|
104
|
+
timeout = 30.5
|
|
105
|
+
api_key =
|
|
106
|
+
|
|
107
|
+
[ServiceConfig]
|
|
108
|
+
retry_count = 3
|
|
109
|
+
timeout = 30
|
|
110
|
+
|
|
111
|
+
[ServerConfig]
|
|
112
|
+
log_level = debug
|
|
113
|
+
db_url = sqlite:///app.db
|
|
114
|
+
fallback_level = error
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## How to contribute?
|
|
118
|
+
|
|
119
|
+
1. Fork the repository and clone locally
|
|
120
|
+
2. Install dependencies: `uv sync --group test`
|
|
121
|
+
3. Run tests: `pytest .`
|
|
122
|
+
4. Run linting: `ruff check .`
|
|
123
|
+
5. Make changes following existing patterns
|
|
124
|
+
6. Add tests for new functionality
|
|
125
|
+
7. Submit a pull request
|
|
126
|
+
|
|
127
|
+
### Development
|
|
128
|
+
|
|
129
|
+
```bash
|
|
130
|
+
git clone https://github.com/HEROgold/confkit.git
|
|
131
|
+
cd confkit
|
|
132
|
+
uv sync --group test
|
|
133
|
+
pytest .
|
|
134
|
+
ruff check .
|
|
135
|
+
```
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
|
|
2
|
+
from configparser import ConfigParser
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
|
|
5
|
+
from confkit import Config
|
|
6
|
+
|
|
7
|
+
parser = ConfigParser()
|
|
8
|
+
Config.set_parser(parser)
|
|
9
|
+
Config.set_file(Path("config.ini"))
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class AppConfig:
|
|
13
|
+
debug = Config(False)
|
|
14
|
+
port = Config(8080)
|
|
15
|
+
host = Config("localhost")
|
|
16
|
+
timeout = Config(30.5)
|
|
17
|
+
api_key = Config("", optional=True)
|
|
18
|
+
|
|
19
|
+
config = AppConfig()
|
|
20
|
+
print(config.debug) # False
|
|
21
|
+
config.port = 9000 # Automatically saves to config.ini if write_on_edit is true (default).
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
|
|
2
|
+
from configparser import ConfigParser
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
from typing import Any
|
|
5
|
+
|
|
6
|
+
from confkit.config import Config
|
|
7
|
+
|
|
8
|
+
parser = ConfigParser()
|
|
9
|
+
Config.set_parser(parser)
|
|
10
|
+
Config.set_file(Path("config.ini"))
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class ServiceConfig:
|
|
14
|
+
retry_count = Config(3)
|
|
15
|
+
timeout = Config(30)
|
|
16
|
+
|
|
17
|
+
@Config.with_setting(retry_count)
|
|
18
|
+
def process(self, _data: Any, **kwargs: Any) -> str:
|
|
19
|
+
retries = kwargs.get("retry_count")
|
|
20
|
+
return f"Processing with {retries} retries"
|
|
21
|
+
|
|
22
|
+
@Config.as_kwarg("ServiceConfig", "timeout", "request_timeout", 60)
|
|
23
|
+
def request(self, _url: Any, **kwargs: Any) -> str:
|
|
24
|
+
timeout = kwargs.get("request_timeout")
|
|
25
|
+
return f"Request timeout: {timeout}s"
|
|
26
|
+
|
|
27
|
+
service = ServiceConfig()
|
|
28
|
+
result = service.process("data") # Uses current retry_count
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
|
|
2
|
+
from configparser import ConfigParser
|
|
3
|
+
from enum import StrEnum
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
|
|
6
|
+
from confkit import Config, Optional, String
|
|
7
|
+
from confkit import StrEnum as ConfigEnum
|
|
8
|
+
|
|
9
|
+
parser = ConfigParser()
|
|
10
|
+
Config.set_parser(parser)
|
|
11
|
+
Config.set_file(Path("config.ini"))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class LogLevel(StrEnum):
|
|
15
|
+
DEBUG = "debug"
|
|
16
|
+
INFO = "info"
|
|
17
|
+
ERROR = "error"
|
|
18
|
+
|
|
19
|
+
class ServerConfig:
|
|
20
|
+
log_level = Config(ConfigEnum(LogLevel.INFO))
|
|
21
|
+
db_url = Config(String("sqlite:///app.db"))
|
|
22
|
+
fallback_level = Config(Optional(ConfigEnum(LogLevel.ERROR)))
|
|
23
|
+
|
|
24
|
+
config = ServerConfig()
|
|
25
|
+
config.log_level = LogLevel.DEBUG # Type-safe
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "confkit"
|
|
3
|
+
version = "0.1.1"
|
|
4
|
+
description = "Lightweight and Easy to use configuration manager for Python projects"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
authors = [
|
|
7
|
+
{ name = "HEROgold", email = "martijnwieringa28@gmail.com" }
|
|
8
|
+
]
|
|
9
|
+
requires-python = ">=3.13"
|
|
10
|
+
dependencies = []
|
|
11
|
+
|
|
12
|
+
[build-system]
|
|
13
|
+
requires = ["hatchling"]
|
|
14
|
+
build-backend = "hatchling.build"
|
|
15
|
+
|
|
16
|
+
[dependency-groups]
|
|
17
|
+
dev = [
|
|
18
|
+
"coverage>=7.10.1",
|
|
19
|
+
"pytest-cov>=6.2.1",
|
|
20
|
+
"hypothesis>=6.136.7",
|
|
21
|
+
"pytest>=8.4.1",
|
|
22
|
+
"ruff>=0.8.0",
|
|
23
|
+
]
|