Typed Settings#

Safe and flexible settings with types

Home | PyPI | Repo | Issues

Typed Settings allows you to cleanly structure and validate your settings with attrs classes. Type annotations will be used to automatically convert values to the proper type (using cattrs). 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


Install and update using pip:

$ python -m pip install typed-settings

You can install install dependencies for optional features via

$ python -m pip install typed-settings[<feature>]

Available features:

  • typed-settings[click]: Enable support for Click options

  • typed-settings[option-groups]: Enable support for Click and Click option groups


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

import typed_settings as ts

class Settings:
    option_one: str
    option_two: int

settings = ts.load(
    config_files=(ts.find("settings.toml"),),  # Paths can also be set via env var
option_one = "value"
$ EXAMPLE_OPTION_TWO=2 python example.py
Settings(option_one='value', option_two=2)


Indices and tables#