You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When executing a subcommand with an asynchronous cli_cmd, Pydantic settings automatically detects whether the current thread already has an active event loop. If so, the async command is run in a fresh thread to avoid conflicts. Otherwise, it uses asyncio.run() in the current thread. This handling ensures your asynchronous subcommands "just work" without additional manual setup.
1175
1175
1176
+
### Serializing CLI Arguments
1177
+
1178
+
An instantiated Pydantic model can be serialized into its CLI arguments using the `CliApp.serialize` method.
| Secret fields must belong to a top level model. | Secrets can be fields of nested models. |
1873
+
| Secret files can be placed in `secrets_dir`s only. | Secret files can be placed in subdirectories for nested models. |
1874
+
| Secret files discovery is based on the same configuration options that are used by `EnvSettingsSource`: `case_sensitive`, `env_nested_delimiter`, `env_prefix`. | Default options are respected, but can be overridden with `secrets_case_sensitive`, `secrets_nested_delimiter`, `secrets_prefix`. |
1875
+
| When `secrets_dir` is missing on the file system, a warning is generated. | Use `secrets_dir_missing` options to choose whether to issue warning, raise error, or silently ignore. |
1876
+
1877
+
### Use Case: Plain Directory Layout
1878
+
1879
+
```text
1880
+
📂 secrets
1881
+
├── 📄 app_key
1882
+
└── 📄 db_passwd
1883
+
```
1884
+
1885
+
In the example below, secrets nested delimiter `'_'` is different from env nested delimiter `'__'`.
1886
+
Value for `Settings.db.user` can be passed in env variable `MY_DB__USER`.
Path to secrets directory, same as `SecretsSettingsSource.secrets_dir`. If `list`, the last match wins.
2058
+
If `secrets_dir` is passed in both source constructor and model config, values are not merged (constructor wins).
2059
+
2060
+
#### secrets_dir_missing
2061
+
2062
+
If `secrets_dir` does not exist, original `SecretsSettingsSource` issues a warning.
2063
+
However, this may be undesirable, for example if we don't mount Docker Secrets in e.g. dev environment.
2064
+
Use `secrets_dir_missing` to choose:
2065
+
2066
+
*`'ok'` — do nothing if `secrets_dir` does not exist
2067
+
*`'warn'` (default) — print warning, same as `SecretsSettingsSource`
2068
+
*`'error'` — raise `SettingsError`
2069
+
2070
+
If multiple `secrets_dir` passed, the same `secrets_dir_missing` action applies to each of them.
2071
+
2072
+
#### secrets_dir_max_size
2073
+
2074
+
Limit the size of `secrets_dir` for security reasons, defaults to `SECRETS_DIR_MAX_SIZE` equal to 16 MiB.
2075
+
2076
+
`NestedSecretsSettingsSource` is a thin wrapper around `EnvSettingsSource`,
2077
+
which loads all potential secrets on initialization. This could lead to `MemoryError` if we mount
2078
+
a large file under `secrets_dir`.
2079
+
2080
+
If multiple `secrets_dir` passed, the limit applies to each directory independently.
2081
+
2082
+
#### secrets_case_sensitive
2083
+
2084
+
Same as `case_sensitive`, but works for secrets only. If not specified, defaults to `case_sensitive`.
2085
+
2086
+
#### secrets_nested_delimiter
2087
+
2088
+
Same as `env_nested_delimiter`, but works for secrets only. If not specified, defaults to `env_nested_delimiter`.
2089
+
This option is used to implement _nested secrets directory_ layout and allows to do even nasty things
2090
+
like `/run/secrets/model/delim/nested1/delim/nested2`.
2091
+
2092
+
#### secrets_nested_subdir
2093
+
2094
+
Boolean flag to turn on _nested secrets directory_ mode, `False` by default. If `True`, sets `secrets_nested_delimiter`
2095
+
to `os.sep`. Raises `SettingsError` if `secrets_nested_delimiter` is already specified.
2096
+
2097
+
#### secrets_prefix
2098
+
2099
+
Secret path prefix, similar to `env_prefix`, but works for secrets only. Defaults to `env_prefix`
2100
+
if not specified. Works in both plain and nested directory modes, like
2101
+
`'/run/secrets/prefix_model__nested'` and `'/run/secrets/prefix_model/nested'`.
2102
+
2103
+
1839
2104
## AWS Secrets Manager
1840
2105
1841
2106
You must set one parameter:
@@ -1949,6 +2214,45 @@ class AzureKeyVaultSettings(BaseSettings):
1949
2214
)
1950
2215
```
1951
2216
2217
+
### Snake case conversion
2218
+
2219
+
The Azure Key Vault source accepts a `snake_case_convertion` option, disabled by default, to convert Key Vault secret names by mapping them to Python's snake_case field names, without the need to use aliases.
This setup will load Azure Key Vault secrets (e.g., `MySetting`, `mySetting`, `my-secret` or `MY-SECRET`), mapping them to the snake case version (`my_setting` in this case).
2255
+
1952
2256
### Dash to underscore mapping
1953
2257
1954
2258
The Azure Key Vault source accepts a `dash_to_underscore` option, disabled by default, to support Key Vault kebab-case secret names by mapping them to Python's snake_case field names. When enabled, dashes (`-`) in secret names are mapped to underscores (`_`) in field names during validation.
@@ -2400,7 +2704,7 @@ print(Settings())
2400
2704
#> foobar='test'
2401
2705
```
2402
2706
2403
-
#### Accesing the result of previous sources
2707
+
#### Accessing the result of previous sources
2404
2708
2405
2709
Each source of settings can access the output of the previous ones.
0 commit comments