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.

Example#

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

example.py#
import attrs
import typed_settings as ts

@attrs.frozen
class Settings:
    option_one: str
    option_two: int

settings = ts.load(
    cls=Settings,
    appname="example",
    config_files=[ts.find("settings.toml")],
)
print(settings)
settings.toml#
[example]
option_one = "value"
$ EXAMPLE_OPTION_TWO=2 python example.py
Settings(option_one='value', option_two=2)

Installation#

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.

Documentation#

Contents:

Indices and tables#