Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

settingsloadertypesafe-0.1.2.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

settingsloadertypesafe-0.1.2-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

Details for the file settingsloadertypesafe-0.1.2.tar.gz.

File metadata

  • Download URL: settingsloadertypesafe-0.1.2.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for settingsloadertypesafe-0.1.2.tar.gz
Algorithm Hash digest
SHA256 2634568298f6b7da9835bc5ee4b0b9cc787946e9405028e3ad9260ca81f40b1f
MD5 d8d2f17f85a8cda9c4dabee7e32bb902
BLAKE2b-256 a8cfd7446eee6be8e980ce056eeab5e2ed66d094000171004293323860b97e8c

See more details on using hashes here.

File details

Details for the file settingsloadertypesafe-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for settingsloadertypesafe-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 6f4818a5ba84c71a75e2ce2a22edd041ff59c23095c0e0f2047709df0ceb98ef
MD5 44a1d8cdd2289cddbbd17457fdacb01c
BLAKE2b-256 a81930dea7f2a2c1323fcd79009650b549491db1b7ab045743accd7fe177e046

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page