Typed Settings

Safe and flexible settings with types

Home | PyPI | Repo | Issues

Typed Settings is a settings loading library. You can use it, e.g., for:

  • server processes

  • containerized apps

  • command line applications

Typed Settings allows you to load settings from various sources (e.g., config files, environment variables or secret vaults) and merge them. You can even generate CLI options for your settings for argparse and Click apps. Loaded settings can be post processed, e.g., to interpolated values from other loaded settings.

Settings are converted to instances of typed classes. You can use attrs, dataclasses, or Pydantic. You have the choice between a built-in converter and the powerful cattrs.

Typed Settings provides good defaults for the common case and is also highly customizable and extendable. It has no mandatory requirements so that it is lightweight by default. You can also vendor it with your application.

See Comprehensive List of Features for details.


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

import attrs
import typed_settings as ts

class Settings:
    option_one: str
    option_two: int

settings = ts.load(
option_one = "value"
$ EXAMPLE_OPTION_TWO=2 python example.py
Settings(option_one='value', option_two=2)


Install and update using pip:

$ python -m pip install typed-settings

Typed Settings as no required dependencies (except for tomli on older Python versions). You can install dependencies for optional features via

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

Available features:

  • typed-settings[attrs]: Enable settings classes via attrs.

  • typed-settings[pydantic]: Enable settings classes via Pydantic.

  • typed-settings[cattrs]: Enable usage of the powerful and fast cattrs converter.

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

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

  • typed-settings[jinja]: Enable support for value interpolation with Jinja templates.

  • typed-settings[all]: Install all optional requirements.



Indices and tables