talira

pydantic-settings

Typed Python app settings from environment variables, .env files and secret stores

open sourceMITfree

pydantic-settings adds settings management to Pydantic: a class that inherits from BaseSettings fills its fields from environment variables, .env files and secrets files, and validates them against their types, so a bad value fails with a validation error naming the setting. It also reads from the command line, pyproject.toml and, with optional extras, AWS Secrets Manager, AWS Systems Manager Parameter Store, Azure Key Vault and Google Cloud Secret Manager, and the order of these sources can be changed or extended.

Problems it solves

  • load my Python app's configuration from environment variables with types checked
  • read settings from a .env file and Docker secrets into one typed config object
  • pull secrets from AWS Secrets Manager or Azure Key Vault into my Python settings

Features

  • BaseSettings classes filled from environment variables
  • .env file support
  • secrets files and directories (Docker secrets)
  • command-line parsing with subcommands
  • AWS Secrets Manager, AWS Systems Manager Parameter Store, Azure Key Vault and Google Cloud Secret Manager sources
  • YAML, TOML and pyproject.toml sources
  • custom source order and custom sources

Alternatives

The same job

These do what pydantic-settings does.

  1. python-dotenv Read key-value pairs from a .env file and set them as environment variables

Compare pydantic-settings with the top 3