Skip to content

Commit 8419aaa

Browse files
committed
feat: add support for lazy load in providers
1 parent ef63672 commit 8419aaa

File tree

8 files changed

+16
-3
lines changed

8 files changed

+16
-3
lines changed

pydantic_settings/sources/providers/aws.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ def __init__(
4444
env_parse_none_str: str | None = None,
4545
env_parse_enums: bool | None = None,
4646
version_id: str | None = None,
47+
lazy_load: bool | None = None,
4748
) -> None:
4849
import_aws_secrets_manager()
4950
self._secretsmanager_client = boto3_client('secretsmanager', region_name=region_name, endpoint_url=endpoint_url) # type: ignore
@@ -57,6 +58,7 @@ def __init__(
5758
env_ignore_empty=False,
5859
env_parse_none_str=env_parse_none_str,
5960
env_parse_enums=env_parse_enums,
61+
lazy_load=lazy_load,
6062
)
6163

6264
def _load_env_vars(self) -> Mapping[str, str | None]:

pydantic_settings/sources/providers/azure.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ def __init__(
105105
env_prefix: str | None = None,
106106
env_parse_none_str: str | None = None,
107107
env_parse_enums: bool | None = None,
108+
lazy_load: bool | None = None,
108109
) -> None:
109110
import_azure_key_vault()
110111
self._url = url
@@ -119,6 +120,7 @@ def __init__(
119120
env_ignore_empty=False,
120121
env_parse_none_str=env_parse_none_str,
121122
env_parse_enums=env_parse_enums,
123+
lazy_load=lazy_load,
122124
)
123125

124126
def _load_env_vars(self) -> Mapping[str, str | None]:

pydantic_settings/sources/providers/cli.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ def __init__(
308308
cli_kebab_case: bool | Literal['all', 'no_enums'] | None = None,
309309
cli_shortcuts: Mapping[str, str | list[str]] | None = None,
310310
case_sensitive: bool | None = True,
311+
lazy_load: bool | None = None,
311312
root_parser: Any = None,
312313
parse_args_method: Callable[..., Any] | None = None,
313314
add_argument_method: Callable[..., Any] | None = ArgumentParser.add_argument,
@@ -384,6 +385,7 @@ def __init__(
384385
env_parse_enums=True,
385386
env_prefix=self.cli_prefix,
386387
case_sensitive=case_sensitive,
388+
lazy_load=lazy_load,
387389
)
388390

389391
root_parser = (

pydantic_settings/sources/providers/dotenv.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ def __init__(
4343
env_ignore_empty: bool | None = None,
4444
env_parse_none_str: str | None = None,
4545
env_parse_enums: bool | None = None,
46+
lazy_load: bool | None = None,
4647
) -> None:
4748
self.env_file = env_file if env_file != ENV_FILE_SENTINEL else settings_cls.model_config.get('env_file')
4849
self.env_file_encoding = (
@@ -57,6 +58,7 @@ def __init__(
5758
env_ignore_empty,
5859
env_parse_none_str,
5960
env_parse_enums,
61+
lazy_load,
6062
)
6163

6264
def _load_env_vars(self) -> Mapping[str, str | None]:

pydantic_settings/sources/providers/env.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,10 @@ def __init__(
4545
env_ignore_empty: bool | None = None,
4646
env_parse_none_str: str | None = None,
4747
env_parse_enums: bool | None = None,
48+
lazy_load: bool | None = None,
4849
) -> None:
4950
super().__init__(
50-
settings_cls, case_sensitive, env_prefix, env_ignore_empty, env_parse_none_str, env_parse_enums
51+
settings_cls, case_sensitive, env_prefix, env_ignore_empty, env_parse_none_str, env_parse_enums, lazy_load
5152
)
5253
self.env_nested_delimiter = (
5354
env_nested_delimiter if env_nested_delimiter is not None else self.config.get('env_nested_delimiter')

pydantic_settings/sources/providers/gcp.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ def __init__(
102102
env_parse_enums: bool | None = None,
103103
secret_client: SecretManagerServiceClient | None = None,
104104
case_sensitive: bool | None = True,
105+
lazy_load: bool | None = None,
105106
) -> None:
106107
# Import Google Packages if they haven't already been imported
107108
if SecretManagerServiceClient is None or Credentials is None or google_auth_default is None:
@@ -131,14 +132,14 @@ def __init__(
131132
self._secret_client = secret_client
132133
else:
133134
self._secret_client = SecretManagerServiceClient(credentials=self._credentials)
134-
135135
super().__init__(
136136
settings_cls,
137137
case_sensitive=case_sensitive,
138138
env_prefix=env_prefix,
139139
env_ignore_empty=False,
140140
env_parse_none_str=env_parse_none_str,
141141
env_parse_enums=env_parse_enums,
142+
lazy_load=lazy_load,
142143
)
143144

144145
def _load_env_vars(self) -> Mapping[str, str | None]:

pydantic_settings/sources/providers/nested_secrets.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ def __init__(
3131
secrets_prefix: str | None = None,
3232
secrets_nested_delimiter: str | None = None,
3333
secrets_nested_subdir: bool | None = None,
34+
lazy_load: bool | None = None,
3435
# args for compatibility with SecretsSettingsSource, don't use directly
3536
case_sensitive: bool | None = None,
3637
env_prefix: str | None = None,
@@ -115,6 +116,7 @@ def __init__(
115116
env_ignore_empty=False, # match SecretsSettingsSource behaviour
116117
env_parse_enums=True, # we can pass everything here, it will still behave as "True"
117118
env_parse_none_str=None, # match SecretsSettingsSource behaviour
119+
lazy_load=lazy_load,
118120
)
119121
self.env_parse_none_str = None # update manually because of None
120122

pydantic_settings/sources/providers/secrets.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,10 @@ def __init__(
3636
env_ignore_empty: bool | None = None,
3737
env_parse_none_str: str | None = None,
3838
env_parse_enums: bool | None = None,
39+
lazy_load: bool | None = None,
3940
) -> None:
4041
super().__init__(
41-
settings_cls, case_sensitive, env_prefix, env_ignore_empty, env_parse_none_str, env_parse_enums
42+
settings_cls, case_sensitive, env_prefix, env_ignore_empty, env_parse_none_str, env_parse_enums, lazy_load
4243
)
4344
self.secrets_dir = secrets_dir if secrets_dir is not None else self.config.get('secrets_dir')
4445

0 commit comments

Comments
 (0)