Typed Settings¶
Safe and flexible settings with types
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.
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)
[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¶
- Why Typed Settings?
- Getting Started
- Examples
- Guides
- API Reference
- Development
- Changelog
- 24.6.0 (unreleased)
- 24.5.0 (2024-09-02)
- 24.4.0 (2024-07-02)
- 24.3.0 (2024-05-09)
- 24.2.0 (2024-03-12)
- 24.1.0 (2024-02-24)
- 24.0.1 (2024-02-15)
- 24.0.0 (2024-01-17)
- 23.1.1 (2023-11-10)
- 23.1.0 (2023-10-30)
- 23.0.1 (2023-05-23)
- 23.0.0 (2023-03-07)
- 2.0.2 (2023-01-18)
- 2.0.1 (2023-01-14)
- 2.0.0 (2022-11-30)
- 1.1.1 (2022-10-08)
- 1.1.0 (2022-07-09)
- 1.0.1 (2022-04-04)
- 1.0.0 (2022-03-04)
- 0.11.1 (2021-10-03)
- 0.11.0 (2021-10-02)
- 0.10.0 (2021-06-23)
- 0.9.2 (2021-02-10)
- 0.9.1 (2020-12-01)
- 0.9 (2020-11-29)
- 0.8 (2020-11-05)
- 0.7 (2020-10-13)
- 0.6 (2020-10-11)
- 0.5 (2020-09-30)
- 0.4 (2020-09-25)
- 0.3 (2020-09-17)
- 0.2 (2020-09-02)
- 0.1 (2020-08-28)
- Legend
- License