pydantic_settings.load
¶
Module Contents¶
-
pydantic_settings.load.
SettingsM
¶
-
pydantic_settings.load.
load_settings
(cls: Type[SettingsM], any_content: Union[None, TextIO, str, Path] = None, *, type_hint: str = None, load_env: bool = False, env_prefix: str = 'APP', environ: Mapping[str, str] = None, _content_reader: Callable[[Path], str] = Path.read_text) → SettingsM¶ Load setting from any_content and optionally merge with environment variables. Content loaded from file path, from file-like source or from plain text.
You could omit any_content argument in case you want to load settings only from environment variables.
- Parameters
cls – either
BaseSettingsModel
orpydantic.BaseModel
subclass type. The result will be instance of a given type.any_content – content from which settings will be loaded
type_hint – determines content decoder. Required, if content isn’t provided as a file path. Takes precedence over actual file suffix.
load_env – determines whether load environment variables or not
env_prefix – determines prefix used to match model field with appropriate environment variable. NOTE if cls argument is subclass of
BaseSettingsModel
then env_prefix argument will be ignored.environ – environment to use instead of os.environ.
- Raises
LoadingError – in case if any error occurred while loading settings
- Returns
instance of settings model, provided by cls argument