pydantic-settings
Settings management for Pydantic apps, loading configuration from environment variables and secrets.
Official Documentation ↗v2. Check the official docs for the latest API surface.Installation
pip install pydantic-settingsMethods
No methods match this filter.
pydantic-settings extends Pydantic models with loaders for env vars, dotenv files, and secret files.
Key Features
- Typed settings from environment variables
- dotenv and secret file sources
- Validation at load time
Usage Notes
Pin a version and check the official docs for the API surface you depend on before upgrading.
Errors
The following points are quoted verbatim from the official documentation. 来源:https://docs.pydantic.dev/latest/concepts/pydantic_settings/ · 取证方式:HTTP GET 官方 README/文档页(HTML 去标签) · 抓取时间:2026-11-07T13:51:54.245Z. Any error type, throw condition or recovery step not stated there is left unspecified; this page does not infer exception classes or return values.
- Logfire can record failed validations and their structured errors, so you can see which setting failed and why. (https://docs.pydantic.dev/latest/concepts/pydantic_settings/)
- If a subcommand is not required, set the is_required flag to False to disable raising an error if no subcommand is found. (https://docs.pydantic.dev/latest/concepts/pydantic_settings/)
- The CLI settings will only raise an error when connecting to the root parser if a parser method is necessary but set to None . (https://docs.pydantic.dev/latest/concepts/pydantic_settings/)
Security notes
Quoted verbatim from the official documentation; this is not a complete threat model. 来源:https://docs.pydantic.dev/latest/concepts/pydantic_settings/ · 取证方式:HTTP GET 官方 README/文档页(HTML 去标签) · 抓取时间:2026-11-07T13:51:54.245Z.
- Secrets Placing secret values in files is a common pattern to provide sensitive configuration to an application. (https://docs.pydantic.dev/latest/concepts/pydantic_settings/)
- A secret file follows the same principal as a dotenv file except it only contains a single value and the file name is used as the key. (https://docs.pydantic.dev/latest/concepts/pydantic_settings/)
- For example, the default implementation does not support secret fields in nested submodels. (https://docs.pydantic.dev/latest/concepts/pydantic_settings/)
FAQ
- How are env var names derived?
- Field names are uppercased by default and can be prefixed or aliased through the model config.
- Can I use nested models?
- Yes. Nested settings read a JSON object from the variable or use a delimiter such as __ for nested keys.
- Where should secrets go?
- Use a secrets directory or your platform secret manager and point the settings model at it, never hardcode them.
Report a problem with this API docOpens a pre-filled issue on GitHub.