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.core 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.3.tar.gz (4.3 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.3-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: settingsloadertypesafe-0.1.3.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

Hashes for settingsloadertypesafe-0.1.3.tar.gz
Algorithm Hash digest
SHA256 32aad0cded8d5cea1263b80f24de748466aac75f1243329e9ceb9c885f5e08c5
MD5 4ba5dcd5c188d3cd312e36eb7f30c3fd
BLAKE2b-256 98f73979e236b782784fdd50eb8e9719109c24fd3015693f5d6ee7ed8f80628b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for settingsloadertypesafe-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 73f4d27834e16e4d71c4e0d095357753e41117aeef1ac4db8013c3ff80d16294
MD5 cac7e69014dfaeb24201a78f7df29cfb
BLAKE2b-256 ec1b48c7a1122eeb4c840bac026b4a017a2fbba13d878556f381af7563f410fa

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