pydantic / pydantic-settings

Settings management using pydantic
https://docs.pydantic.dev/latest/usage/pydantic_settings/
MIT License
502 stars 47 forks source link

Example from docs doesn't work can't import from pydantic.env_settings import SettingsSourceCallable #289

Closed red8888 closed 1 month ago

red8888 commented 1 month ago

https://docs.pydantic.dev/1.10/usage/settings/#changing-priority

from pydantic import BaseSettings, PostgresDsn
from pydantic.env_settings import SettingsSourceCallable

class Settings(BaseSettings):
    database_dsn: PostgresDsn

    class Config:
        @classmethod
        def customise_sources(
            cls,
            init_settings: SettingsSourceCallable,
            env_settings: SettingsSourceCallable,
            file_secret_settings: SettingsSourceCallable,
        ) -> tuple[SettingsSourceCallable, ...]:
            return env_settings, init_settings, file_secret_settings

print(Settings(database_dsn='postgres://postgres@localhost:5432/kwargs_db'))
#> database_dsn=PostgresDsn('postgres://postgres@localhost:5432/env_db', )

It looks like pydantic.env_settings is empty? I can't import SettingsSourceCallable from it.

red8888 commented 1 month ago

Im dumb was looking at all old docs