mirror of
https://github.com/kennethreitz/pydantic.git
synced 2026-06-05 23:00:18 +00:00
1155de82b9
* feat: Add the ability to add extra settings sources * doc: Document "customise settings sources" feature * tests: Add missing test and add change file * Update changes/2107-kozlek.md Co-authored-by: Eric Jolibois <em.jolibois@gmail.com> * improve docs for settings customise_sources * fix docs building * fix test :-( Co-authored-by: Thomas Berdy <thomas.berdy@outlook.com> Co-authored-by: Eric Jolibois <em.jolibois@gmail.com> Co-authored-by: Samuel Colvin <s@muelcolvin.com>
23 lines
635 B
Python
23 lines
635 B
Python
from typing import Tuple
|
|
|
|
from pydantic import BaseSettings
|
|
from pydantic.env_settings import SettingsSourceCallable
|
|
|
|
|
|
class Settings(BaseSettings):
|
|
my_api_key: str
|
|
|
|
class Config:
|
|
@classmethod
|
|
def customise_sources(
|
|
cls,
|
|
init_settings: SettingsSourceCallable,
|
|
env_settings: SettingsSourceCallable,
|
|
file_secret_settings: SettingsSourceCallable,
|
|
) -> Tuple[SettingsSourceCallable, ...]:
|
|
# here we choose to ignore arguments from init_settings
|
|
return env_settings, file_secret_settings
|
|
|
|
|
|
print(Settings(my_api_key='this is ignored'))
|