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.5.tar.gz (4.4 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.5-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: settingsloadertypesafe-0.1.5.tar.gz
  • Upload date:
  • Size: 4.4 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.5.tar.gz
Algorithm Hash digest
SHA256 99e3211b687d2fb2d90d6deb8b64624a963f7b71c47e62c89ab2bab586231100
MD5 fd1c5fec0d87baae60b562e6ce17efef
BLAKE2b-256 173455ca6d1c606fa33fdbb5a44023736e2ac6f443f3987090297002d09e50dd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for settingsloadertypesafe-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 cd7f2e0ed7896a1e290edac04d88de69cffb33c787098750586ac651cfa57a34
MD5 a0e1084e5af6d7bcf9f743266b7c58db
BLAKE2b-256 ea63e2c0466d8fb9c94be58832d8e6e90ec2caf1aeee7d1c33b13d3ea4fa6bcf

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