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.4.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.4-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: settingsloadertypesafe-0.1.4.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.4.tar.gz
Algorithm Hash digest
SHA256 683dde948e703decaa8977498cc4dff2f1d87895a92e30a997eb4fb759fc6d6c
MD5 1f2d7f03eaeb77e0143151d75a98e982
BLAKE2b-256 eecab15ab96fe81d0d03424b2a92862948278defc10b7c9fef6b46b68602969b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for settingsloadertypesafe-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 f1519cb321858cf77597863ee29baca34f6e2810347f5c620af08dd90849860e
MD5 5d4dfa689c876ba2ce62c1f0ae49da64
BLAKE2b-256 deb4ef6cd7594a012202b395e517cf1040cf5064be8e3f3b2e3907df80c4544d

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