pydantic-settings

Type-safe application settings management for Python, built on Pydantic models.

Library
PyPI
v2.16.1
1,488 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
89 /100 Excellent
Development Activity 96
Maintenance 96
Community 68
Maturity 56
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
85 /100 Excellent
Architecture 88
Code Quality 90
Innovation 85
Learning Curve 78

Pydantic Settings extends Pydantic’s BaseModel into BaseSettings, a class that automatically reads and validates configuration values from environment variables, .env files, JSON, YAML, TOML, Docker/Kubernetes secrets files, cloud secret managers, and CLI arguments — in a configurable precedence order. Every setting is a typed, validated Pydantic field, so misconfigured environments fail fast at startup with clear error messages instead of surfacing as runtime bugs deep in application code.

Maintained by the Pydantic core team as an official companion package, it is the de facto standard for twelve-factor-app configuration in the Python ecosystem, used across FastAPI services, Django projects, CLI tools, and background workers to centralize environment-driven config into a single validated, IDE-autocompletable class.

What You Get

  • BaseSettings base class that behaves like a normal Pydantic model but auto-populates fields from environment variables and other sources on instantiation
  • Built-in source providers for .env files, JSON, YAML, TOML, pyproject.toml, Docker/Kubernetes-style secrets directories, and CLI argument parsing
  • First-party cloud secret manager integrations for AWS Secrets Manager, Azure Key Vault, and GCP Secret Manager via optional extras
  • Configurable source precedence (init kwargs > env vars > dotenv > file secrets > defaults, fully overridable) and nested-delimiter support for structured env vars like SUB__FIELD=value
  • A full CLI-parsing source (cli_parse_args) that turns any BaseSettings model into an argparse-style command-line interface with kebab-case flags, subcommands, and auto-generated help text
  • AliasChoices and env_prefix support for reading the same field from multiple differently-named environment variables

Common Use Cases

  • Centralizing FastAPI/Django/Flask app configuration (database URLs, API keys, feature flags) into one validated, autocompletable settings object
  • Twelve-factor-app deployments where config must be injected via environment variables in Docker/Kubernetes without code changes
  • Building typed CLI tools where flags, env vars, and config files all need to resolve into the same validated model
  • Pulling secrets from AWS Secrets Manager, Azure Key Vault, or GCP Secret Manager at startup without hand-rolled SDK calls
  • Multi-environment configuration (dev/staging/prod) where different .env files or config layers override a shared set of defaults

Under The Hood

Architecture Configuration resolution flows through a pipeline of PydanticBaseSettingsSource objects assembled in BaseSettings._settings_init_sources (pydantic_settings/main.py): init kwargs, CLI args, environment variables, dotenv files, file secrets, and any user-supplied sources are each wrapped as a source instance, called in a configurable precedence order, and their resulting dicts are deep-merged via Pydantic’s deep_update before being handed to the model constructor for validation — so every value, regardless of origin, passes through the same Pydantic validation path as a normal BaseModel field.

Tech Stack The package is pure Python (99.9% per GitHub’s language breakdown) targeting 3.10-3.14, built on pydantic>=2.7 for the validation core, python-dotenv for .env parsing, and typing-inspection for runtime generic/alias introspection; optional extras (pyyaml, tomli, azure-keyvault-secrets+azure-identity, boto3, google-cloud-secret-manager) are pulled in only when their respective source providers are used, keeping the base install lightweight. Packaging uses hatchling with hatch.version reading the version from pydantic_settings/version.py.

Code Quality Source logic is factored into one file per provider under pydantic_settings/sources/providers/ (env, dotenv, json, yaml, toml, pyproject, secrets, nested_secrets, cli, aws, azure, gcp), sharing common field-resolution and alias-handling helpers in sources/base.py and sources/utils.py — a clean separation that makes each source independently testable. The test suite spans 12,000+ lines across per-provider test files (test_source_cli.py, test_source_aws_secrets_manager.py, etc.) plus dedicated precedence/merging and docs-example tests, and the codebase is typed throughout with a py.typed marker, run under strict mypy and ruff via pre-commit hooks.

API Design The core API surface is a single subclassing pattern (class Settings(BaseSettings): ...) that developers already know from Pydantic’s BaseModel, so the learning curve for basic usage is close to zero for anyone using Pydantic elsewhere; configuration of behavior (env prefix, nested delimiter, secrets dir, CLI parsing) is done declaratively via SettingsConfigDict, keeping field declarations free of source-specific noise, though the surface grows large once CLI parsing and multiple file sources are combined — the docs run to 3,400+ lines covering the full option matrix.

Used by 27 apps in this directory

Python
39%
Apache 2.0

OpenSandbox

Developer Tools · Security

16,116

Secure, fast, and extensible sandbox runtime for AI agents with multi-language SDKs and Docker/Kubernetes runtimes.

View details
85
Repo Health
81
Technical
70
Dependency
Built with
Python 39%
Go 36%
Updated 6 days ago
Python
73%
AGPL 3.0

OpenViking

AI Development · AI Memory · Databases

40,705

An open-source context database that gives AI agents a unified filesystem for memory, resources, and skills with hierarchical tiered retrieval.

View details
85
Repo Health
75
Technical
64
Dependency
Built with
Python 73%
TypeScript 12%
Rust 11%
Updated 6 days ago
Python
68%
Apache 2.0

otari

AI Development · Developer Tools

733

A self-hosted, OpenAI-compatible LLM gateway that puts one endpoint in front of 40+ providers, with virtual API keys, per-user budgets enforced before spend, and full usage tracking.

View details
82
Repo Health
88
Technical
74
Dependency
Built with
Python 68%
TypeScript 31%
Updated 1 weeks ago
Python
62%
Apache 2.0

Polar

Developer Tools · Ecommerce · Invoicing Finance

10,410

Open source payments infrastructure that turns software into a business — subscriptions, usage-based billing, digital products, and merchant-of-record compliance in one platform.

View details
90
Repo Health
82
Technical
66
Dependency
Built with
Python 62%
TypeScript 31%
Updated 1 weeks ago
Python
55%
Other

PostHog

Ab Testing Experimentation · Analytics · Developer Tools

40,397

The all-in-one open source product platform combining analytics, session replay, feature flags, error tracking, AI observability, and a built-in data warehouse in a single self-hostable stack.

View details
92
Repo Health
80
Technical
65
Dependency
Built with
Python 55%
TypeScript 36%
Updated 6 days ago
JavaScript
50%
AGPL 3.0

QRev

AI Agents · CRM

364

Open source AI-first sales platform that replaces Salesforce with autonomous agents handling prospecting, outreach, and lead management at scale.

View details
39
Repo Health
68
Technical
64
Dependency
Built with
JavaScript 50%
Python 28%
TypeScript 14%
Updated 8 months ago
Python
64%
AGPL 3.0

Shadowbroker

Analytics · Monitoring · Security

11,358

Self-hosted OSINT dashboard that fuses 60+ live intelligence feeds — flight tracking, ship AIS, satellites, CCTV, seismic and radio networks — into one real-time map, with an agent-ready command channel for AI co-analysts.

View details
85
Repo Health
83
Technical
71
Dependency
Built with
Python 64%
TypeScript 32%
Updated 1 weeks ago
Python
79%
AGPL 3.0

Skyvern

AI Agents · Automation

23,257

Skyvern (YC S2023) automates browser-based workflows by pairing LLMs with computer vision, letting agents click, fill, and extract data on sites they've never seen, without brittle XPath selectors that break on every layout change.

View details
89
Repo Health
82
Technical
70
Dependency
Built with
Python 79%
TypeScript 19%
Updated 6 days ago
TypeScript
47%
Other

Stirling PDF

Digital Signiture · Productivity

94,824

The open-source PDF platform you can run anywhere — edit, convert, sign, and automate PDFs without sending files to external servers.

View details
92
Repo Health
86
Technical
68
Dependency
Built with
TypeScript 47%
Java 44%
Updated 6 days ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers