Skip to content

Providing only one nested value from environment variable #888

@idmitrievsky

Description

@idmitrievsky

Feature Request

  • OS: macOS
  • Python version import sys; print(sys.version): 3.6.8 (default, Jun 24 2019, 16:49:13) [GCC 4.2.1 Compatible Apple LLVM 10.0.1 (clang-1001.0.46.4)]
  • Pydantic version import pydantic; print(pydantic.VERSION): 1.0b2

Hello, great work on the library! I can't find the reason, why environment variables don't work in nested settings. I have a class

class Credentials(pydantic.BaseModel):
    host: str
    user: str
    database: str
    password: pydantic.SecretStr

class Settings(pydantic.BaseSettings):
    db: Credentials

    class Config:
        env_prefix = 'APP_'

and I want to specify password as an environment variable

export APP_DB='{"password": ""}'

but pass other fields in as values in code. Right now BaseSettings does simple top-level merging of dictionaries that doesn't consider nested values

def _build_values(self, init_kwargs: Dict[str, Any]) -> Dict[str, Any]:
    return {**self._build_environ(), **init_kwargs}

but dictionaries could be merged recursively, so users could provide values for any of their settings in environment variables.

What do you think, would it be useful?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions