Metadata-Version: 2.4
Name: SettingsLoaderTypeSafe
Version: 0.1.1
Summary: Type safe settings loader for python - support for env, args, secrets and app setttings
Author: aqzi
License: MIT License
        
        Copyright (c) 2025 Aquila Ziedins
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Homepage, https://github.com/aqzi/SettingsLoader
Project-URL: Repository, https://github.com/aqzi/SettingsLoader
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: pydantic
Requires-Dist: python-dotenv
Requires-Dist: pyyaml
Requires-Dist: pytest
Dynamic: license-file

# 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:
```sh
pip install SettingsLoaderTypeSafe
```

When installed through pip, import it with:
```python
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:

```python
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.

```python
class Settings(SettingsBase):
    app: AppSettings
    env: EnvSettings
    secrets: SecretsSettings
```

Finally, to load the settings you can do following:
```python
    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.
