Here is my example code:
from pathlib import Path
from pydantic_settings import BaseSettings, SettingsConfigDict
class Settings(BaseSettings):
model_config = SettingsConfigDict(
yaml_file=Path('c.yaml'),
yaml_config_section='blah',
)
port: int
s = Settings()
and my c.yaml stored in the same directory:
blah:
port: 123
When I'm running Python file I'm getting message:
pydantic_core._pydantic_core.ValidationError: 1 validation error for Settings
port
Field required [type=missing, input_value={}, input_type=dict]
For further information visit https://errors.pydantic.dev/2.11/v/missing
That means that Pydantic isn't even trying to read YAML file. I found multiple answers how to read YAML and most of it is about how to read YAML, convert it to dict and pass the dict as constructor arguments. But I could not find any information why this yaml_file and yaml_config_section exists and what it does.
Is here a simple way to read YAML using these arguments?