psyplus 0.9.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.
- psyplus-0.9.2/LICENSE +21 -0
- psyplus-0.9.2/PKG-INFO +241 -0
- psyplus-0.9.2/README.md +220 -0
- psyplus-0.9.2/psyplus/__init__.py +2 -0
- psyplus-0.9.2/psyplus/env_var_handler.py +245 -0
- psyplus-0.9.2/psyplus/field_container.py +173 -0
- psyplus-0.9.2/psyplus/psyplus.py +223 -0
- psyplus-0.9.2/psyplus/utils.py +205 -0
- psyplus-0.9.2/psyplus/yaml_pydantic_metadata_comment_injector.py +137 -0
- psyplus-0.9.2/psyplus.egg-info/PKG-INFO +241 -0
- psyplus-0.9.2/psyplus.egg-info/SOURCES.txt +15 -0
- psyplus-0.9.2/psyplus.egg-info/dependency_links.txt +1 -0
- psyplus-0.9.2/psyplus.egg-info/requires.txt +4 -0
- psyplus-0.9.2/psyplus.egg-info/top_level.txt +1 -0
- psyplus-0.9.2/pyproject.toml +32 -0
- psyplus-0.9.2/setup.cfg +4 -0
- psyplus-0.9.2/tests/test.py +50 -0
psyplus-0.9.2/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Deutsche Zentrum für Diabetesforschung e.V.
|
|
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.
|
psyplus-0.9.2/PKG-INFO
ADDED
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: psyplus
|
|
3
|
+
Version: 0.9.2
|
|
4
|
+
Summary: A helper module that builds upon pydantic-settings to generate, read and comment a config file in yaml
|
|
5
|
+
Author-email: Tim Bleimehl <bleimehl@helmholtz-munich.de>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Source, https://github.com/DZD-eV-Diabetes-Research/pydantic-settings-yaml-plus
|
|
8
|
+
Project-URL: Issues, https://github.com/DZD-eV-Diabetes-Research/pydantic-settings-yaml-plus/issues
|
|
9
|
+
Keywords: DZD,pydantic,pydantic-settings
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
14
|
+
Requires-Python: >=3.10
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
License-File: LICENSE
|
|
17
|
+
Requires-Dist: pydantic
|
|
18
|
+
Requires-Dist: pydantic-setting
|
|
19
|
+
Requires-Dist: ruamel.yaml
|
|
20
|
+
Requires-Dist: pyaml
|
|
21
|
+
|
|
22
|
+
# pydantic-settings-yaml-plus
|
|
23
|
+
A helper module that builds upon [pydantic-settings](https://docs.pydantic.dev/latest/concepts/pydantic_settings/) to generate, read and comment a config file in yaml ~~and improve ENV var capabilities~~
|
|
24
|
+
|
|
25
|
+
> [!WARNING]
|
|
26
|
+
> work in progress. please ignore this repo for now
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
- [pydantic-settings-yaml-plus](#pydantic-settings-yaml-plus)
|
|
30
|
+
- [Target use cases](#target-use-cases)
|
|
31
|
+
- [Features](#features)
|
|
32
|
+
- [Known Issues](#known-issues)
|
|
33
|
+
- [Goals](#goals)
|
|
34
|
+
- [ToDo / ToInvestigate](#todo--toinvestigate)
|
|
35
|
+
- [Ideas/Roadmap](#ideasroadmap)
|
|
36
|
+
- [How to use](#how-to-use)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
## Target use cases
|
|
40
|
+
|
|
41
|
+
* **Config File Provisioning** The idea is to use this module during the build/release- (deploy on pypi.org) or init(First start)-process of your python module to generate a documented yaml file the user can understand.
|
|
42
|
+
* ~~**Extended Nested Env Var Parsing** Provide complex configs via env var without the need to write json~~ Needs a rewrite with pydantic-settings 2.x
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
## Features
|
|
47
|
+
|
|
48
|
+
* Generate a commented/documented yaml file based on your `pydantic-settings`.`BaseSettings` class
|
|
49
|
+
* ~~Support for nested listed and dict and var. E.g. `MYLIST__0__MYKEY=val` -> `config`.`MYLIST``[0]`.`MYKEY`=`val`~~ Needs a rewrite with pydantic-settings 2.x
|
|
50
|
+
|
|
51
|
+
## Known Issues
|
|
52
|
+
* Multiline values are crippled
|
|
53
|
+
|
|
54
|
+
## Goals
|
|
55
|
+
|
|
56
|
+
* Have a single source of truth for config and all its meta-data/documentation (type, descpription, examples)
|
|
57
|
+
* ~~All keys/values are addressable by env vars~~
|
|
58
|
+
|
|
59
|
+
### ToDo / ToInvestigate
|
|
60
|
+
* What about date(times) support?
|
|
61
|
+
* Make indexed env vars work again!
|
|
62
|
+
* Remove debug prints
|
|
63
|
+
* Write some more test
|
|
64
|
+
* Make pypi package
|
|
65
|
+
|
|
66
|
+
### Ideas/Roadmap
|
|
67
|
+
* Generate a mark down doc of all settings
|
|
68
|
+
* Generate template (minimal with required values only or maximum with all values listed) and example config files (all YAML only!)
|
|
69
|
+
* generate diff betwen current config and config model (when config model changed after update)
|
|
70
|
+
* update existing config files metadata
|
|
71
|
+
* Update info, descs
|
|
72
|
+
* Add missing/new required values
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
## How to use
|
|
78
|
+
|
|
79
|
+
Lets have the following examplary pydantic-settings config.py file:
|
|
80
|
+
|
|
81
|
+
```python
|
|
82
|
+
from typing import List, Dict, Optional, Literal, Annotated
|
|
83
|
+
|
|
84
|
+
from pydantic import Field
|
|
85
|
+
from pydantic_settings import BaseSettings
|
|
86
|
+
|
|
87
|
+
from pathlib import Path, PurePath
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
class DatabaseServerSettings(BaseSettings):
|
|
91
|
+
host: Optional[str] = Field(
|
|
92
|
+
default="localhost",
|
|
93
|
+
description="The Hostname the database will be available at",
|
|
94
|
+
)
|
|
95
|
+
port: Optional[int] = Field(
|
|
96
|
+
default=5678, description="The port to connect to the database"
|
|
97
|
+
)
|
|
98
|
+
database_names: List[str] = Field(
|
|
99
|
+
description="The names of the databases to use",
|
|
100
|
+
examples=[["mydb", "theotherdb"]],
|
|
101
|
+
)
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
class MyAppConfig(BaseSettings):
|
|
105
|
+
log_level: Optional[Literal["INFO", "DEBUG"]] = "INFO"
|
|
106
|
+
app_name: Optional[str] = Field(
|
|
107
|
+
default="THE APP",
|
|
108
|
+
description="The display name of the app",
|
|
109
|
+
examples=["THAT APP", "THIS APP"],
|
|
110
|
+
)
|
|
111
|
+
storage_dir: Optional[str] = Field(
|
|
112
|
+
description="A directory to store the file of the apps.",
|
|
113
|
+
default_factory=lambda: str(Path(PurePath(Path().home(), ".config/myapp/"))),
|
|
114
|
+
)
|
|
115
|
+
admin_pw: Annotated[str, Field(description="The init password the admin account")]
|
|
116
|
+
database_server: DatabaseServerSettings = Field(
|
|
117
|
+
description="The settings for the database server",
|
|
118
|
+
examples=[
|
|
119
|
+
DatabaseServerSettings(
|
|
120
|
+
host="db.company.org", port=1234, database_names=["db1", "db2"]
|
|
121
|
+
)
|
|
122
|
+
],
|
|
123
|
+
)
|
|
124
|
+
init_values: Dict[str, str]
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
With the help of psyplus we can generate a fully documented
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
```python
|
|
131
|
+
from psyplus import YamlSettingsPlus
|
|
132
|
+
from config import MyAppConfig
|
|
133
|
+
|
|
134
|
+
yaml_handler = YamlSettingsPlus(MyAppConfig, "test.config.yaml")
|
|
135
|
+
yaml_handler.generate_config_file(overwrite_existing=True)
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
which will generate a yaml file `./test.config.yaml` that looks like the following:
|
|
139
|
+
|
|
140
|
+
```yaml
|
|
141
|
+
# ## log_level ###
|
|
142
|
+
# Type: Enum
|
|
143
|
+
# Required: False
|
|
144
|
+
# Default: '"INFO"'
|
|
145
|
+
# Allowed vals: ['INFO', 'DEBUG']
|
|
146
|
+
# Env-var: 'LOG_LEVEL'
|
|
147
|
+
log_level: INFO
|
|
148
|
+
|
|
149
|
+
# ## app_name ###
|
|
150
|
+
# Type: str
|
|
151
|
+
# Required: False
|
|
152
|
+
# Default: '"THE APP"'
|
|
153
|
+
# Env-var: 'APP_NAME'
|
|
154
|
+
# Description: The display name of the app
|
|
155
|
+
# Example No. 1:
|
|
156
|
+
# >app_name: THAT APP
|
|
157
|
+
# >
|
|
158
|
+
# Example No. 2:
|
|
159
|
+
# >app_name: THIS APP
|
|
160
|
+
app_name: THE APP
|
|
161
|
+
|
|
162
|
+
# ## storage_dir ###
|
|
163
|
+
# Type: str
|
|
164
|
+
# Required: False
|
|
165
|
+
# Env-var: 'STORAGE_DIR'
|
|
166
|
+
# Description: A directory to store the file of the apps.
|
|
167
|
+
storage_dir: /home/tim/.config/myapp
|
|
168
|
+
|
|
169
|
+
# ## admin_pw ###
|
|
170
|
+
# Type: str
|
|
171
|
+
# Required: True
|
|
172
|
+
# Env-var: 'ADMIN_PW'
|
|
173
|
+
# Description: The init password the admin account
|
|
174
|
+
admin_pw: ''
|
|
175
|
+
|
|
176
|
+
# ## database_server ###
|
|
177
|
+
# Type: Object
|
|
178
|
+
# Required: True
|
|
179
|
+
# Env-var: 'DATABASE_SERVER'
|
|
180
|
+
# Description: The settings for the database server
|
|
181
|
+
# Example:
|
|
182
|
+
# >database_server:
|
|
183
|
+
# > database_names:
|
|
184
|
+
# > - db1
|
|
185
|
+
# > - db2
|
|
186
|
+
# > host: db.company.org
|
|
187
|
+
# > port: 1234
|
|
188
|
+
database_server:
|
|
189
|
+
|
|
190
|
+
# ## host ###
|
|
191
|
+
# YAML-path: database_server.host
|
|
192
|
+
# Type: str
|
|
193
|
+
# Required: False
|
|
194
|
+
# Default: '"localhost"'
|
|
195
|
+
# Env-var: 'DATABASE_SERVER__HOST'
|
|
196
|
+
# Description: The Hostname the database will be available at
|
|
197
|
+
host: localhost
|
|
198
|
+
|
|
199
|
+
# ## port ###
|
|
200
|
+
# YAML-path: database_server.port
|
|
201
|
+
# Type: int
|
|
202
|
+
# Required: False
|
|
203
|
+
# Default: '5678'
|
|
204
|
+
# Env-var: 'DATABASE_SERVER__PORT'
|
|
205
|
+
# Description: The port to connect to the database
|
|
206
|
+
port: 5678
|
|
207
|
+
|
|
208
|
+
# ## database_names ###
|
|
209
|
+
# YAML-path: database_server.database_names
|
|
210
|
+
# Type: List of str
|
|
211
|
+
# Required: True
|
|
212
|
+
# Env-var: 'DATABASE_SERVER__DATABASE_NAMES'
|
|
213
|
+
# Description: The names of the databases to use
|
|
214
|
+
# Example:
|
|
215
|
+
# >database_names:
|
|
216
|
+
# >- mydb
|
|
217
|
+
# >- theotherdb
|
|
218
|
+
database_names: []
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
To use this yaml file you just psyplus: need to parse it and validate on your pydantic-setting model.
|
|
222
|
+
|
|
223
|
+
```python
|
|
224
|
+
from psyplus import YamlSettingsPlus
|
|
225
|
+
|
|
226
|
+
yaml_handler = YamlSettingsPlus(MyAppConfig, "test.config.yaml")
|
|
227
|
+
config: MyAppConfig = yaml_handler.get_config()
|
|
228
|
+
print(config.database_server.host)
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
Alternativly you can parse and validate the pydantic-settings model yourself:
|
|
232
|
+
|
|
233
|
+
```python
|
|
234
|
+
import yaml # pip install PyYAML
|
|
235
|
+
|
|
236
|
+
with open("test.config.yaml") as file:
|
|
237
|
+
raw_yaml_str = file.read()
|
|
238
|
+
obj: Dict = yaml.safe_load(raw_yaml_str)
|
|
239
|
+
config: MyAppConfig = MyAppConfig.model_validate(obj)
|
|
240
|
+
|
|
241
|
+
```
|
psyplus-0.9.2/README.md
ADDED
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
# pydantic-settings-yaml-plus
|
|
2
|
+
A helper module that builds upon [pydantic-settings](https://docs.pydantic.dev/latest/concepts/pydantic_settings/) to generate, read and comment a config file in yaml ~~and improve ENV var capabilities~~
|
|
3
|
+
|
|
4
|
+
> [!WARNING]
|
|
5
|
+
> work in progress. please ignore this repo for now
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
- [pydantic-settings-yaml-plus](#pydantic-settings-yaml-plus)
|
|
9
|
+
- [Target use cases](#target-use-cases)
|
|
10
|
+
- [Features](#features)
|
|
11
|
+
- [Known Issues](#known-issues)
|
|
12
|
+
- [Goals](#goals)
|
|
13
|
+
- [ToDo / ToInvestigate](#todo--toinvestigate)
|
|
14
|
+
- [Ideas/Roadmap](#ideasroadmap)
|
|
15
|
+
- [How to use](#how-to-use)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
## Target use cases
|
|
19
|
+
|
|
20
|
+
* **Config File Provisioning** The idea is to use this module during the build/release- (deploy on pypi.org) or init(First start)-process of your python module to generate a documented yaml file the user can understand.
|
|
21
|
+
* ~~**Extended Nested Env Var Parsing** Provide complex configs via env var without the need to write json~~ Needs a rewrite with pydantic-settings 2.x
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
## Features
|
|
26
|
+
|
|
27
|
+
* Generate a commented/documented yaml file based on your `pydantic-settings`.`BaseSettings` class
|
|
28
|
+
* ~~Support for nested listed and dict and var. E.g. `MYLIST__0__MYKEY=val` -> `config`.`MYLIST``[0]`.`MYKEY`=`val`~~ Needs a rewrite with pydantic-settings 2.x
|
|
29
|
+
|
|
30
|
+
## Known Issues
|
|
31
|
+
* Multiline values are crippled
|
|
32
|
+
|
|
33
|
+
## Goals
|
|
34
|
+
|
|
35
|
+
* Have a single source of truth for config and all its meta-data/documentation (type, descpription, examples)
|
|
36
|
+
* ~~All keys/values are addressable by env vars~~
|
|
37
|
+
|
|
38
|
+
### ToDo / ToInvestigate
|
|
39
|
+
* What about date(times) support?
|
|
40
|
+
* Make indexed env vars work again!
|
|
41
|
+
* Remove debug prints
|
|
42
|
+
* Write some more test
|
|
43
|
+
* Make pypi package
|
|
44
|
+
|
|
45
|
+
### Ideas/Roadmap
|
|
46
|
+
* Generate a mark down doc of all settings
|
|
47
|
+
* Generate template (minimal with required values only or maximum with all values listed) and example config files (all YAML only!)
|
|
48
|
+
* generate diff betwen current config and config model (when config model changed after update)
|
|
49
|
+
* update existing config files metadata
|
|
50
|
+
* Update info, descs
|
|
51
|
+
* Add missing/new required values
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
## How to use
|
|
57
|
+
|
|
58
|
+
Lets have the following examplary pydantic-settings config.py file:
|
|
59
|
+
|
|
60
|
+
```python
|
|
61
|
+
from typing import List, Dict, Optional, Literal, Annotated
|
|
62
|
+
|
|
63
|
+
from pydantic import Field
|
|
64
|
+
from pydantic_settings import BaseSettings
|
|
65
|
+
|
|
66
|
+
from pathlib import Path, PurePath
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
class DatabaseServerSettings(BaseSettings):
|
|
70
|
+
host: Optional[str] = Field(
|
|
71
|
+
default="localhost",
|
|
72
|
+
description="The Hostname the database will be available at",
|
|
73
|
+
)
|
|
74
|
+
port: Optional[int] = Field(
|
|
75
|
+
default=5678, description="The port to connect to the database"
|
|
76
|
+
)
|
|
77
|
+
database_names: List[str] = Field(
|
|
78
|
+
description="The names of the databases to use",
|
|
79
|
+
examples=[["mydb", "theotherdb"]],
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
class MyAppConfig(BaseSettings):
|
|
84
|
+
log_level: Optional[Literal["INFO", "DEBUG"]] = "INFO"
|
|
85
|
+
app_name: Optional[str] = Field(
|
|
86
|
+
default="THE APP",
|
|
87
|
+
description="The display name of the app",
|
|
88
|
+
examples=["THAT APP", "THIS APP"],
|
|
89
|
+
)
|
|
90
|
+
storage_dir: Optional[str] = Field(
|
|
91
|
+
description="A directory to store the file of the apps.",
|
|
92
|
+
default_factory=lambda: str(Path(PurePath(Path().home(), ".config/myapp/"))),
|
|
93
|
+
)
|
|
94
|
+
admin_pw: Annotated[str, Field(description="The init password the admin account")]
|
|
95
|
+
database_server: DatabaseServerSettings = Field(
|
|
96
|
+
description="The settings for the database server",
|
|
97
|
+
examples=[
|
|
98
|
+
DatabaseServerSettings(
|
|
99
|
+
host="db.company.org", port=1234, database_names=["db1", "db2"]
|
|
100
|
+
)
|
|
101
|
+
],
|
|
102
|
+
)
|
|
103
|
+
init_values: Dict[str, str]
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
With the help of psyplus we can generate a fully documented
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
```python
|
|
110
|
+
from psyplus import YamlSettingsPlus
|
|
111
|
+
from config import MyAppConfig
|
|
112
|
+
|
|
113
|
+
yaml_handler = YamlSettingsPlus(MyAppConfig, "test.config.yaml")
|
|
114
|
+
yaml_handler.generate_config_file(overwrite_existing=True)
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
which will generate a yaml file `./test.config.yaml` that looks like the following:
|
|
118
|
+
|
|
119
|
+
```yaml
|
|
120
|
+
# ## log_level ###
|
|
121
|
+
# Type: Enum
|
|
122
|
+
# Required: False
|
|
123
|
+
# Default: '"INFO"'
|
|
124
|
+
# Allowed vals: ['INFO', 'DEBUG']
|
|
125
|
+
# Env-var: 'LOG_LEVEL'
|
|
126
|
+
log_level: INFO
|
|
127
|
+
|
|
128
|
+
# ## app_name ###
|
|
129
|
+
# Type: str
|
|
130
|
+
# Required: False
|
|
131
|
+
# Default: '"THE APP"'
|
|
132
|
+
# Env-var: 'APP_NAME'
|
|
133
|
+
# Description: The display name of the app
|
|
134
|
+
# Example No. 1:
|
|
135
|
+
# >app_name: THAT APP
|
|
136
|
+
# >
|
|
137
|
+
# Example No. 2:
|
|
138
|
+
# >app_name: THIS APP
|
|
139
|
+
app_name: THE APP
|
|
140
|
+
|
|
141
|
+
# ## storage_dir ###
|
|
142
|
+
# Type: str
|
|
143
|
+
# Required: False
|
|
144
|
+
# Env-var: 'STORAGE_DIR'
|
|
145
|
+
# Description: A directory to store the file of the apps.
|
|
146
|
+
storage_dir: /home/tim/.config/myapp
|
|
147
|
+
|
|
148
|
+
# ## admin_pw ###
|
|
149
|
+
# Type: str
|
|
150
|
+
# Required: True
|
|
151
|
+
# Env-var: 'ADMIN_PW'
|
|
152
|
+
# Description: The init password the admin account
|
|
153
|
+
admin_pw: ''
|
|
154
|
+
|
|
155
|
+
# ## database_server ###
|
|
156
|
+
# Type: Object
|
|
157
|
+
# Required: True
|
|
158
|
+
# Env-var: 'DATABASE_SERVER'
|
|
159
|
+
# Description: The settings for the database server
|
|
160
|
+
# Example:
|
|
161
|
+
# >database_server:
|
|
162
|
+
# > database_names:
|
|
163
|
+
# > - db1
|
|
164
|
+
# > - db2
|
|
165
|
+
# > host: db.company.org
|
|
166
|
+
# > port: 1234
|
|
167
|
+
database_server:
|
|
168
|
+
|
|
169
|
+
# ## host ###
|
|
170
|
+
# YAML-path: database_server.host
|
|
171
|
+
# Type: str
|
|
172
|
+
# Required: False
|
|
173
|
+
# Default: '"localhost"'
|
|
174
|
+
# Env-var: 'DATABASE_SERVER__HOST'
|
|
175
|
+
# Description: The Hostname the database will be available at
|
|
176
|
+
host: localhost
|
|
177
|
+
|
|
178
|
+
# ## port ###
|
|
179
|
+
# YAML-path: database_server.port
|
|
180
|
+
# Type: int
|
|
181
|
+
# Required: False
|
|
182
|
+
# Default: '5678'
|
|
183
|
+
# Env-var: 'DATABASE_SERVER__PORT'
|
|
184
|
+
# Description: The port to connect to the database
|
|
185
|
+
port: 5678
|
|
186
|
+
|
|
187
|
+
# ## database_names ###
|
|
188
|
+
# YAML-path: database_server.database_names
|
|
189
|
+
# Type: List of str
|
|
190
|
+
# Required: True
|
|
191
|
+
# Env-var: 'DATABASE_SERVER__DATABASE_NAMES'
|
|
192
|
+
# Description: The names of the databases to use
|
|
193
|
+
# Example:
|
|
194
|
+
# >database_names:
|
|
195
|
+
# >- mydb
|
|
196
|
+
# >- theotherdb
|
|
197
|
+
database_names: []
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
To use this yaml file you just psyplus: need to parse it and validate on your pydantic-setting model.
|
|
201
|
+
|
|
202
|
+
```python
|
|
203
|
+
from psyplus import YamlSettingsPlus
|
|
204
|
+
|
|
205
|
+
yaml_handler = YamlSettingsPlus(MyAppConfig, "test.config.yaml")
|
|
206
|
+
config: MyAppConfig = yaml_handler.get_config()
|
|
207
|
+
print(config.database_server.host)
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
Alternativly you can parse and validate the pydantic-settings model yourself:
|
|
211
|
+
|
|
212
|
+
```python
|
|
213
|
+
import yaml # pip install PyYAML
|
|
214
|
+
|
|
215
|
+
with open("test.config.yaml") as file:
|
|
216
|
+
raw_yaml_str = file.read()
|
|
217
|
+
obj: Dict = yaml.safe_load(raw_yaml_str)
|
|
218
|
+
config: MyAppConfig = MyAppConfig.model_validate(obj)
|
|
219
|
+
|
|
220
|
+
```
|