Registry / serialization / pydantic-settings

pydantic-settings

JSON →
library2.13.1pypypi✓ verified 33d ago

Settings management using Pydantic. Provides BaseSettings for loading config from environment variables, .env files, and secrets files with full type validation. Extracted from pydantic core into a separate package in V2. Current version is 2.13.1 (Feb 2026).

serializationauth-security
Install & Compatibility
Where this runs
tested against v2.14.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.975 runs
installs and imports cleanly · install 0.0s · import 0.611s · 30.6MB
glibc
py 3.103.975 runs
installs and imports cleanly · install 3.4s · import 0.546s · 31MB
29MB installed
● package 29MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

from pydantic_settings import BaseSettings
from pydantic_settings import SettingsConfigDict

Minimal BaseSettings loading from .env file with pydantic-settings 2.x.

from pydantic_settings import BaseSettings, SettingsConfigDict class Settings(BaseSettings): model_config = SettingsConfigDict( env_file='.env', env_file_encoding='utf-8', extra='ignore' # ignore unknown env vars ) api_key: str debug: bool = False port: int = 8000 # reads from env vars and .env file settings = Settings() print(settings.api_key)
Debug
Known footguns
breaking'from pydantic import BaseSettings' raises ImportError in pydantic V2. BaseSettings moved to separate pydantic-settings package.
gotchaIf env_file path does not exist, pydantic-settings silently ignores it with no error. Fields fall back to environment variables or defaults. Wrong .env path causes silent misconfiguration.
gotchaEnvironment variables take precedence over .env file values. If the same variable is set in both the shell environment and .env, the shell value wins.
gotchaenv_file in 2.13.x has a regression where .env files are not loaded when using CliApp.run() without debugger attached. Known issue, tracked in pydantic-settings #795.
gotchaNested settings via env_nested_delimiter require sub-models to inherit from pydantic.BaseModel, not BaseSettings.
gotchaInner class Config: is V1 style and deprecated. Use model_config = SettingsConfigDict(...) at class level.
deprecatedPassing settings config as constructor underscore kwargs (_env_file, _env_prefix) is deprecated. Use model_config = SettingsConfigDict(...) instead.
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
411 hits · last 30 days
amazonbot
4
claudebot
4
gptbot
3
ahrefsbot
3
chatgpt-user
2
oai-searchbot
2
perplexity-user
2
bytedance
1
commoncrawl
1
Resources