Typed Settings

Safe and flexible settings with types

Home | PyPI | Repo | Issues


Typed Settings allows you to cleanly structure your settings with attrs classes. Type annotations will be used to automatically convert values to the proper type. You can currently load settings from these sources:

  • TOML files (multiple, if you want to). Paths can be statically specified or dynamically set via an environment variable.

  • Environment variables

  • click command line options

You can use Typed settings, e.g., for

  • server processes

  • containerized apps

  • command line applications

Installation

Install and update using pip:

$ python -m pip install typed-settings

Example

This is a very simple example that demonstrates how you can load settings from environment variables.

# example.py
import typed_settings as ts

@ts.settings
class Settings:
    option_one: str
    option_two: int

settings = ts.load_settings(
    cls=Settings,
    appname="example",
    config_files=["settings.py"],  # Paths can also be set via env var
)
print(settings)
# settings.toml
[example]
option_one = "value"
$ EXAMPLE_OPTION_TWO=2 python example.py
Settings(option_one="value", option_two=2)

Indices and tables