YamlBaseSettings#
- pydantic model safir.pydantic.YamlBaseSettings#
Base class for Pydantic settings from a YAML file.
This class is intended to serve as the base class for application settings when the settings are primarily parsed from a YAML configuration file with optional overrides and secrets from environment variables. It enables camel case for validation, allowing all parameters to be specified in the camel-case format that is standard for Helm charts. It also forbids extra settings and disables settings sources other than the constructor (used when reading YAML files) and environment variables.
It is normally used in conjunction with
ConfigDependency.- Parameters:
_nested_model_default_partial_update (
bool|None, default:None)_env_prefix_target (
Literal['variable','alias','all'] |None, default:None)_env_file (
Path|str|Sequence[Path|str] |None, default:PosixPath('.'))_cli_parse_args (
bool|list[str] |tuple[str,...] |None, default:None)_cli_settings_source (
CliSettingsSource[Any] |None, default:None)_cli_implicit_flags (
bool|Literal['dual','toggle'] |None, default:None)_cli_kebab_case (
bool|Literal['all','no_enums'] |None, default:None)_cli_shortcuts (
Mapping[str,str|list[str]] |None, default:None)_secrets_dir (
Path|str|Sequence[Path|str] |None, default:None)_build_sources (
tuple[tuple[PydanticBaseSettingsSource,...],dict[str,Any]] |None, default:None)
- Config:
env_prefix_target: str = all
alias_generator: AliasGenerator = AliasGenerator(alias=None, validation_alias=<function YamlBaseSettings.<lambda> at 0x77d36f716820>, serialization_alias=None)
validate_by_name: bool = True
- classmethod from_file(path)#
Construct a settings object from a configuration file.
- classmethod settings_cached()#
Return the cached default settings instance for this settings class.
The instance is constructed on first use and reused afterwards. Subclasses are cached separately, so caching a class does not affect its parents or children.
- Return type:
- classmethod settings_clear_cache()#
Remove the cached default settings instance for this settings class, if any.
Only the cache entry for this exact class is removed. Subclasses keep their own cached instances and must be cleared individually.
A
settings_cached()call already in flight may still return the instance it was building, so clearing does not retroactively invalidate references other threads hold.- Return type:
- classmethod settings_customise_sources(settings_cls, init_settings, env_settings, dotenv_settings, file_secret_settings)#
Override the sources of settings.
Deactivate
.envand secret file support, since Phalanx doesn’t use them. Allow environment variables to override init parameters, since init parameters come from the YAML configuration file and we want environment variables to take precedent.