Closed voodoo11 closed 2 months ago
Couple of points:
pydantic.BaseModel
env_nested_delimiter
on parent modelHere is the working example:
from pydantic import BaseModel
from pydantic_settings import BaseSettings, SettingsConfigDict
class NestedConfig(BaseModel):
foo: str = ""
class Config(BaseSettings):
nested: NestedConfig = NestedConfig()
bar: str = ""
model_config = SettingsConfigDict(
env_file=".env", env_file_encoding="utf-8", extra="ignore", case_sensitive=False, env_nested_delimiter="__"
)
print(Config())
@hramezani Thanks, that makes sense. Is it possible then to override model config for submodels somehow?
pydantic-settigns
only loads the config for the models you are initializing(Config
in your example) and collect values for the model fields. so it only consider the parent model configs
How to reproduce:
Given .env:
results in:
Setting env variable by hand e.g.
NESTED_FOO=foo python test.py
works fine.