pydantic-settings-manager 0.2.0__py3-none-any.whl → 0.2.2__py3-none-any.whl

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.
@@ -21,7 +21,7 @@ from .base import BaseSettingsManager
21
21
  from .mapped import MappedSettingsManager, SettingsMap
22
22
  from .single import SingleSettingsManager
23
23
 
24
- __version__ = "0.2.0"
24
+ __version__ = "0.2.2"
25
25
 
26
26
  __all__ = [
27
27
  # Re-exports from pydantic_settings
@@ -0,0 +1,372 @@
1
+ Metadata-Version: 2.4
2
+ Name: pydantic-settings-manager
3
+ Version: 0.2.2
4
+ Summary: A library for managing Pydantic settings objects
5
+ Project-URL: homepage, https://github.com/kiarina/pydantic-settings-manager
6
+ Project-URL: repository, https://github.com/kiarina/pydantic-settings-manager
7
+ Project-URL: documentation, https://github.com/kiarina/pydantic-settings-manager
8
+ Author-email: kiarina <kiarinadawa@gmail.com>
9
+ License: MIT
10
+ License-File: LICENSE
11
+ Keywords: configuration,pydantic,settings
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Operating System :: OS Independent
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.9
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
22
+ Requires-Python: >=3.9
23
+ Requires-Dist: pydantic-settings>=2.0.0
24
+ Requires-Dist: pydantic>=2.0.0
25
+ Description-Content-Type: text/markdown
26
+
27
+ # pydantic-settings-manager
28
+
29
+ A library for managing Pydantic settings objects.
30
+
31
+ ## Features
32
+
33
+ - Two types of settings managers:
34
+ - `SingleSettingsManager`: For managing a single settings object
35
+ - `MappedSettingsManager`: For managing multiple settings objects mapped to keys
36
+ - Support for loading settings from multiple sources
37
+ - Command line argument overrides
38
+ - Settings validation through Pydantic
39
+ - Type hints and documentation
40
+
41
+ ## Installation
42
+
43
+ ```bash
44
+ pip install pydantic-settings-manager
45
+ ```
46
+
47
+ ## Quick Start
48
+
49
+ ### Basic Usage
50
+
51
+ Let's start with a simple example you can try immediately:
52
+
53
+ ```python
54
+ from pydantic_settings import BaseSettings
55
+ from pydantic_settings_manager import SingleSettingsManager
56
+
57
+ # 1. Define your settings
58
+ class AppSettings(BaseSettings):
59
+ app_name: str = "MyApp"
60
+ debug: bool = False
61
+ max_connections: int = 100
62
+
63
+ # 2. Create a settings manager
64
+ settings_manager = SingleSettingsManager(AppSettings)
65
+
66
+ # 3. Use your settings
67
+ settings = settings_manager.settings
68
+ print(f"App: {settings.app_name}, Debug: {settings.debug}")
69
+ ```
70
+
71
+ ### Loading from Configuration Files
72
+
73
+ You can load settings from external sources:
74
+
75
+ ```python
76
+ # Load from a dictionary (could be from JSON, YAML, etc.)
77
+ settings_manager.user_config = {
78
+ "app_name": "ProductionApp",
79
+ "debug": False,
80
+ "max_connections": 500
81
+ }
82
+
83
+ settings = settings_manager.settings
84
+ print(f"App: {settings.app_name}") # Output: App: ProductionApp
85
+ ```
86
+
87
+ ### Command Line Overrides
88
+
89
+ Override specific settings at runtime:
90
+
91
+ ```python
92
+ # Simulate command line arguments
93
+ settings_manager.cli_args["debug"] = True
94
+ settings_manager.cli_args["max_connections"] = 50
95
+
96
+ # Clear cache to apply changes
97
+ settings_manager.clear()
98
+
99
+ settings = settings_manager.settings
100
+ print(f"Debug: {settings.debug}") # Output: Debug: True
101
+ print(f"Connections: {settings.max_connections}") # Output: Connections: 50
102
+ ```
103
+
104
+ ### Multiple Configurations (Mapped Settings)
105
+
106
+ For managing multiple environments or configurations:
107
+
108
+ ```python
109
+ from pydantic_settings_manager import MappedSettingsManager
110
+
111
+ # Create a mapped settings manager
112
+ mapped_manager = MappedSettingsManager(AppSettings)
113
+
114
+ # Configure multiple environments
115
+ mapped_manager.user_config = {
116
+ "map": {
117
+ "development": {
118
+ "app_name": "MyApp-Dev",
119
+ "debug": True,
120
+ "max_connections": 10
121
+ },
122
+ "production": {
123
+ "app_name": "MyApp-Prod",
124
+ "debug": False,
125
+ "max_connections": 1000
126
+ }
127
+ }
128
+ }
129
+
130
+ # Switch between configurations
131
+ mapped_manager.set_cli_args("development")
132
+ dev_settings = mapped_manager.settings
133
+ print(f"Dev: {dev_settings.app_name}, Debug: {dev_settings.debug}")
134
+
135
+ mapped_manager.set_cli_args("production")
136
+ prod_settings = mapped_manager.settings
137
+ print(f"Prod: {prod_settings.app_name}, Debug: {prod_settings.debug}")
138
+ ```
139
+
140
+ ## Advanced Usage
141
+
142
+ ### Project Structure for Large Applications
143
+
144
+ For complex applications with multiple modules, you can organize your settings like this:
145
+
146
+ ```
147
+ your_project/
148
+ ├── hoge/
149
+ │ ├── __init__.py
150
+ │ ├── settings.py
151
+ │ ├── client.py
152
+ │ └── registry.py
153
+ ├── fuga/
154
+ │ ├── __init__.py
155
+ │ ├── settings.py
156
+ │ ├── client.py
157
+ │ └── registry.py
158
+ ├── bootstrap.py
159
+ ├── __main__.py
160
+ └── config.yaml
161
+ ```
162
+
163
+ ### Module-based Settings Management
164
+
165
+ ```python
166
+ # fuga/__init__.py
167
+ from .settings import settings_manager
168
+
169
+ __all__ = ["settings_manager"]
170
+ ```
171
+
172
+ ```python
173
+ # fuga/settings.py
174
+ from pydantic_settings import BaseSettings
175
+ from pydantic_settings_manager import MappedSettingsManager
176
+
177
+ class FugaSettings(BaseSettings):
178
+ name: str = "default"
179
+ api_key: str = "***"
180
+
181
+ settings_manager = MappedSettingsManager(FugaSettings)
182
+ ```
183
+
184
+ ```python
185
+ # fuga/client.py
186
+ from .settings import FugaSettings
187
+
188
+ class FugaClient:
189
+ def __init__(self, settings: FugaSettings):
190
+ self.settings = settings
191
+ ```
192
+
193
+ ```python
194
+ # fuga/registry.py
195
+ from .settings import settings_manager
196
+
197
+ def create_fuga_client(config_key: str = ""):
198
+ settings = settings_manager.get_settings_by_key(config_key)
199
+ return FugaClient(settings)
200
+ ```
201
+
202
+ ### Bootstrap
203
+
204
+ The bootstrap process loads configuration from external sources (like YAML files) and applies them to your settings managers. This allows you to centralize configuration management and easily switch between different environments.
205
+
206
+ ```yaml
207
+ # config.yaml
208
+ hoge:
209
+ name: "star"
210
+ value: 7
211
+ fuga:
212
+ key: first
213
+ map:
214
+ first:
215
+ name: "first"
216
+ api_key: "***"
217
+ second:
218
+ name: "second"
219
+ api_key: "***"
220
+ ```
221
+
222
+ ```python
223
+ # bootstrap.py
224
+ import importlib
225
+ import yaml
226
+
227
+ from pydantic_settings_manager import BaseSettingsManager
228
+
229
+ def bootstrap():
230
+ config = yaml.safe_load(open("/path/to/config.yaml"))
231
+
232
+ for module_name, user_config in config.items():
233
+ try:
234
+ module = importlib.import_module(module_name)
235
+ settings_manager = getattr(module, 'settings_manager', None)
236
+
237
+ if isinstance(settings_manager, BaseSettingsManager):
238
+ settings_manager.user_config = user_config
239
+ settings_manager.clear()
240
+ ```
241
+
242
+ ### CLI Integration
243
+
244
+ You can integrate command-line arguments to override specific settings at runtime. This is useful for debugging, testing different configurations, or providing runtime flexibility without modifying configuration files.
245
+
246
+ ```python
247
+ # __main__.py
248
+ import click
249
+
250
+ from .bootstrap import bootstrap
251
+ from .hoge import settings_manager as hoge_settings_manager
252
+ from .fuga import settings_manager as fuga_settings_manager
253
+
254
+ @click.command
255
+ @click.option("--name", type=str, default="", help="Name of the Hoge")
256
+ @click.option("--key", type=str, default="", help="Key for Fuga settings")
257
+ def main(name: str, key: str):
258
+ bootstrap()
259
+
260
+ if name:
261
+ hoge_settings_manager.cli_args["name"] = name
262
+ hoge_settings_manager.clear()
263
+
264
+ if key:
265
+ fuga_settings_manager.cli_args["key"] = key
266
+ fuga_settings_manager.clear()
267
+
268
+ # ...
269
+ ```
270
+
271
+ ## Related Tools
272
+
273
+ ### pydantic-config-builder
274
+
275
+ For complex projects with multiple configuration files, you might want to use [`pydantic-config-builder`](https://github.com/kiarina/pydantic-config-builder) to merge and build your YAML configuration files:
276
+
277
+ ```bash
278
+ pip install pydantic-config-builder
279
+ ```
280
+
281
+ This tool allows you to:
282
+ - Merge multiple YAML files into a single configuration
283
+ - Use base configurations with overlay files
284
+ - Build different configurations for different environments
285
+ - Support glob patterns and recursive merging
286
+
287
+ Example workflow:
288
+ ```yaml
289
+ # pydantic_config_builder.yml
290
+ development:
291
+ input:
292
+ - base/*.yaml
293
+ - dev-overrides.yaml
294
+ output:
295
+ - config/dev.yaml
296
+
297
+ production:
298
+ input:
299
+ - base/*.yaml
300
+ - prod-overrides.yaml
301
+ output:
302
+ - config/prod.yaml
303
+ ```
304
+
305
+ Then use the generated configurations with your settings manager:
306
+ ```python
307
+ import yaml
308
+ from your_app import settings_manager
309
+
310
+ # Load the built configuration
311
+ with open("config/dev.yaml") as f:
312
+ config = yaml.safe_load(f)
313
+
314
+ settings_manager.user_config = config
315
+ ```
316
+
317
+ ## Development
318
+
319
+ This project uses modern Python development tools with flexible dependency groups:
320
+
321
+ - **ruff**: Fast linter and formatter (replaces black, isort, and flake8)
322
+ - **mypy**: Static type checking
323
+ - **pytest**: Testing framework with coverage reporting
324
+ - **uv**: Fast Python package manager with PEP 735 dependency groups support
325
+
326
+ ### Setup
327
+
328
+ ```bash
329
+ # Install all development dependencies
330
+ uv sync --group dev
331
+
332
+ # Or install specific dependency groups
333
+ uv sync --group test # Testing tools only
334
+ uv sync --group lint # Linting tools only
335
+
336
+ # Format code
337
+ uv run ruff check --fix .
338
+
339
+ # Run linting
340
+ uv run ruff check .
341
+ uv run mypy .
342
+
343
+ # Run tests
344
+ uv run pytest --cov=pydantic_settings_manager tests/
345
+
346
+ # Build and test everything
347
+ make build
348
+ ```
349
+
350
+ ### Development Workflow
351
+
352
+ ```bash
353
+ # Quick setup for testing
354
+ uv sync --group test
355
+ make test
356
+
357
+ # Quick setup for linting
358
+ uv sync --group lint
359
+ make lint
360
+
361
+ # Full development environment
362
+ uv sync --group dev
363
+ make build
364
+ ```
365
+
366
+ ## Documentation
367
+
368
+ For more detailed documentation, please see the [GitHub repository](https://github.com/kiarina/pydantic-settings-manager).
369
+
370
+ ## License
371
+
372
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
@@ -1,11 +1,11 @@
1
- pydantic_settings_manager/__init__.py,sha256=qlee3Dzwc5Noldzte2FpCr3VjsNOpFVKNP9n0YBWsUs,955
1
+ pydantic_settings_manager/__init__.py,sha256=eqe0IVD6o9FuoVR1xKqE0jyyhzd1u3yd77rnOe_9zQs,955
2
2
  pydantic_settings_manager/base.py,sha256=k141GoasYGd-AoEo2qN86xWjW6StOuE1QhDqmEDP9XI,1258
3
3
  pydantic_settings_manager/mapped.py,sha256=8O9tmh72_KgEWF5aIyXRsqiwsm2yUFfhxEmTkz9MfDM,7706
4
4
  pydantic_settings_manager/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
5
  pydantic_settings_manager/single.py,sha256=cuGzkLafDaTS_598148qKFTwVgNZjdhihgV7wiKiuBI,2759
6
6
  pydantic_settings_manager/types.py,sha256=-LUZIr6g14nensFLgIs3CL4bxkcG7i7GlW3BmWHyub4,156
7
7
  pydantic_settings_manager/utils.py,sha256=_DaEPdQjHFka_xlcC5E6e1QT0OAIymt6BL8RYIM_8Dg,1316
8
- pydantic_settings_manager-0.2.0.dist-info/METADATA,sha256=Q-LlWjq7ae7TOjAorJGcf50YR8jytFu_PNjKAEJhV1w,4383
9
- pydantic_settings_manager-0.2.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
10
- pydantic_settings_manager-0.2.0.dist-info/licenses/LICENSE,sha256=GtwfENGLMnpE6iSmuiVTC1AhFCLGvBYycR--RKNSs80,1060
11
- pydantic_settings_manager-0.2.0.dist-info/RECORD,,
8
+ pydantic_settings_manager-0.2.2.dist-info/METADATA,sha256=A8vfiGLrV422FvqhwhLcHEgf7eVeudyhH8H_ZT_SVes,9410
9
+ pydantic_settings_manager-0.2.2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
10
+ pydantic_settings_manager-0.2.2.dist-info/licenses/LICENSE,sha256=GtwfENGLMnpE6iSmuiVTC1AhFCLGvBYycR--RKNSs80,1060
11
+ pydantic_settings_manager-0.2.2.dist-info/RECORD,,
@@ -1,165 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: pydantic-settings-manager
3
- Version: 0.2.0
4
- Summary: A library for managing Pydantic settings objects
5
- Project-URL: homepage, https://github.com/kiarina/pydantic-settings-manager
6
- Project-URL: repository, https://github.com/kiarina/pydantic-settings-manager
7
- Project-URL: documentation, https://github.com/kiarina/pydantic-settings-manager
8
- Author-email: kiarina <kiarinadawa@gmail.com>
9
- License: MIT
10
- License-File: LICENSE
11
- Keywords: configuration,pydantic,settings
12
- Classifier: Development Status :: 4 - Beta
13
- Classifier: Intended Audience :: Developers
14
- Classifier: License :: OSI Approved :: MIT License
15
- Classifier: Operating System :: OS Independent
16
- Classifier: Programming Language :: Python :: 3
17
- Classifier: Programming Language :: Python :: 3.9
18
- Classifier: Programming Language :: Python :: 3.10
19
- Classifier: Programming Language :: Python :: 3.11
20
- Classifier: Programming Language :: Python :: 3.12
21
- Classifier: Topic :: Software Development :: Libraries :: Python Modules
22
- Requires-Python: >=3.9
23
- Requires-Dist: pydantic-settings>=2.0.0
24
- Requires-Dist: pydantic>=2.0.0
25
- Description-Content-Type: text/markdown
26
-
27
- # pydantic-settings-manager
28
-
29
- A library for managing Pydantic settings objects.
30
-
31
- ## Features
32
-
33
- - Two types of settings managers:
34
- - `SingleSettingsManager`: For managing a single settings object
35
- - `MappedSettingsManager`: For managing multiple settings objects mapped to keys
36
- - Support for loading settings from multiple sources
37
- - Command line argument overrides
38
- - Settings validation through Pydantic
39
- - Type hints and documentation
40
-
41
- ## Installation
42
-
43
- ```bash
44
- pip install pydantic-settings-manager
45
- ```
46
-
47
- ## Quick Start
48
-
49
- ### Single Settings Manager
50
-
51
- ```python
52
- from pydantic_settings import BaseSettings
53
- from pydantic_settings_manager import SingleSettingsManager
54
-
55
- class MySettings(BaseSettings):
56
- name: str = "default"
57
- value: int = 0
58
-
59
- # Create a settings manager
60
- manager = SingleSettingsManager(MySettings)
61
-
62
- # Update settings from a configuration file
63
- manager.user_config = {"name": "from_file", "value": 42}
64
-
65
- # Update settings from command line arguments
66
- manager.cli_args = {"value": 100}
67
-
68
- # Get the current settings (combines both sources)
69
- settings = manager.settings
70
- assert settings.name == "from_file" # from user_config
71
- assert settings.value == 100 # from cli_args (overrides user_config)
72
- ```
73
-
74
- ### Mapped Settings Manager
75
-
76
- ```python
77
- from pydantic_settings import BaseSettings
78
- from pydantic_settings_manager import MappedSettingsManager
79
-
80
- class MySettings(BaseSettings):
81
- name: str = "default"
82
- value: int = 0
83
-
84
- # Create a settings manager
85
- manager = MappedSettingsManager(MySettings)
86
-
87
- # Set up multiple configurations
88
- manager.user_config = {
89
- "map": {
90
- "dev": {"name": "development", "value": 42},
91
- "prod": {"name": "production", "value": 100}
92
- }
93
- }
94
-
95
- # Select which configuration to use
96
- manager.set_cli_args("dev")
97
-
98
- # Get the current settings
99
- settings = manager.settings
100
- assert settings.name == "development"
101
- assert settings.value == 42
102
-
103
- # Switch to a different configuration
104
- manager.set_cli_args("prod")
105
- settings = manager.settings
106
- assert settings.name == "production"
107
- assert settings.value == 100
108
- ```
109
-
110
- ## Development
111
-
112
- This project uses modern Python development tools with flexible dependency groups:
113
-
114
- - **ruff**: Fast linter and formatter (replaces black, isort, and flake8)
115
- - **mypy**: Static type checking
116
- - **pytest**: Testing framework with coverage reporting
117
- - **uv**: Fast Python package manager with PEP 735 dependency groups support
118
-
119
- ### Setup
120
-
121
- ```bash
122
- # Install all development dependencies
123
- uv sync --group dev
124
-
125
- # Or install specific dependency groups
126
- uv sync --group test # Testing tools only
127
- uv sync --group lint # Linting tools only
128
-
129
- # Format code
130
- uv run ruff check --fix .
131
-
132
- # Run linting
133
- uv run ruff check .
134
- uv run mypy .
135
-
136
- # Run tests
137
- uv run pytest --cov=pydantic_settings_manager tests/
138
-
139
- # Build and test everything
140
- make build
141
- ```
142
-
143
- ### Development Workflow
144
-
145
- ```bash
146
- # Quick setup for testing
147
- uv sync --group test
148
- make test
149
-
150
- # Quick setup for linting
151
- uv sync --group lint
152
- make lint
153
-
154
- # Full development environment
155
- uv sync --group dev
156
- make build
157
- ```
158
-
159
- ## Documentation
160
-
161
- For more detailed documentation, please see the [GitHub repository](https://github.com/kiarina/pydantic-settings-manager).
162
-
163
- ## License
164
-
165
- This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.