Type safe settings loader for python - support for env, args, secrets and app setttings
Project description
SettingsLoader
SettingsLoader is a component to load env, args, secrets and app settings into one type safe object.
Install
You can either copy the code under the src directory or install it with:
pip install SettingsLoaderTypeSafe
When installed through pip, import it with:
from settings_loader import SettingsBase, SettingsLoader
Usage guide
First define the data classes to represent the information in your setting (env, args, secrets and app) files. Example:
class InferenceSettings(BaseModel):
model_name: str
max_output_tokens: int
timout: int
max_retries: int
class AppServerSettings(BaseModel):
host: str
port: int
workers: int
class EnvSettings(BaseModel):
test: str
class SecretsSettings(BaseModel):
chatbot_api_key: str
test: str
class ArgsSettings(BaseModel):
show_config: bool = Field(False, description="Entire config will be printed if true")
class AppSettings(BaseModel):
data_path: str
text_classifier: InferenceSettings
app_server: AppServerSettings
Create a settings class that inherits from settingsBase. Overwrite the existing fields and give them custom types. Fields that are not overwriten, have a default value of None.
class Settings(SettingsBase):
app: AppSettings
env: EnvSettings
secrets: SecretsSettings
Finally, to load the settings you can do following:
settings = (
SettingsLoader(Settings)
.configure_app('settings/app_settings.yaml')
.configure_env('settings/.env')
.configure_secrets('settings/.secrets.env')
.build()
)
The configure functions are optional and can be used to load settings from a specific file. The default values are:
- env: .env
- secrets: .secrets.env
- app: app_settings.yaml
For more information and examples you can take a look at the unit tests.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file settingsloadertypesafe-0.1.1.tar.gz.
File metadata
- Download URL: settingsloadertypesafe-0.1.1.tar.gz
- Upload date:
- Size: 4.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
59d0217d63d067aa6fce6b2304f06123b967a1cd6132ca2b487f5aa231d79f13
|
|
| MD5 |
1fd32491146874da0144f8ab8e288807
|
|
| BLAKE2b-256 |
cffb74eabcf897ea2c2c76c56d50a931d273de298443502c89f69f96729d1261
|
File details
Details for the file settingsloadertypesafe-0.1.1-py3-none-any.whl.
File metadata
- Download URL: settingsloadertypesafe-0.1.1-py3-none-any.whl
- Upload date:
- Size: 4.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7c2257898d38e13790b466489fdcb57566b2bb0a0927ffaac747a9d84ee61c39
|
|
| MD5 |
79055a14e6a7fcbf68202a97150f6527
|
|
| BLAKE2b-256 |
c36e0880f86ad4d35b1b44ad77966bdf6a1a7cb8b2b29f7d0f0a6258832c6ff0
|