Using pydantic-settings (v2.0.3), I want to manage settings for services service1 and service2, nesting them under the common settings object, so I can address them like settings.service1.secret1 or settings.service2.secret2. Currently, I have this code in my config.py:
from pydantic_settings import BaseSettings
class FirstServiceSettings(BaseSettings):
secret1: str
class SecondServiceSettings(BaseSettings):
secret2: str
class Settings(BaseSettings):
service1: FirstServiceSettings
service2: SecondServiceSettings
class Config:
env_file = ".env"
settings = Settings()
And this is my .env file:
secret1=secret1
secret2=secret2
However, I'm getting pydantic_core._pydantic_core.ValidationError: 4 validation errors for Settings.
The problem can be solved by adding service1__ and service2__ prefixes to keys in .env file and setting env_nested_delimiter = '__', but I wonder is there a way to make this without adding those prefixes in .env file.