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
Copy file name to clipboardExpand all lines: docs/index.md
+56Lines changed: 56 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2457,6 +2457,62 @@ For nested models, Secret Manager supports the `env_nested_delimiter` setting as
2457
2457
2458
2458
For more details on creating and managing secrets in Google Cloud Secret Manager, see the [official Google Cloud documentation](https://cloud.google.com/secret-manager/docs).
2459
2459
2460
+
## Keyring
2461
+
2462
+
This integration allows you to securely load sensitive values such as passwords, API tokens, and other secrets directly from the system keyring. Instead of storing secrets in .env files or configuration files, you can fetch them at runtime using the operating system's secure credential store.
2463
+
2464
+
The Keyring integration requires additional dependencies:
2465
+
2466
+
```bash
2467
+
pip install "pydantic-settings[keyring]"
2468
+
```
2469
+
2470
+
There is one mandatory parameter:
2471
+
-`keyring_service`: keyring service name
2472
+
2473
+
Add `KeyringConfigSettingsSource` to your settings sources:
2474
+
2475
+
```python
2476
+
from pydantic import SecretStr
2477
+
from pydantic_settings import (
2478
+
BaseSettings,
2479
+
KeyringConfigSettingsSource,
2480
+
PydanticBaseSettingsSource,
2481
+
SettingsConfigDict,
2482
+
)
2483
+
2484
+
classSettings(BaseSettings):
2485
+
secret_key: SecretStr
2486
+
2487
+
@classmethod
2488
+
defsettings_customise_sources(
2489
+
cls,
2490
+
settings_cls: type[BaseSettings],
2491
+
init_settings: PydanticBaseSettingsSource,
2492
+
env_settings: PydanticBaseSettingsSource,
2493
+
dotenv_settings: PydanticBaseSettingsSource,
2494
+
file_secret_settings: PydanticBaseSettingsSource,
2495
+
) -> tuple[PydanticBaseSettingsSource, ...]:
2496
+
keyring_settings = KeyringConfigSettingsSource(
2497
+
settings_cls,
2498
+
keyring_service=os.environ["KEYRING_SERVICE"],
2499
+
)
2500
+
2501
+
return (
2502
+
init_settings,
2503
+
env_settings,
2504
+
dotenv_settings,
2505
+
file_secret_settings,
2506
+
keyring_settings,
2507
+
)
2508
+
```
2509
+
2510
+
To set a secret, you can use `keyring set <keyring_service> <field_name>` in your terminal:
2511
+
2512
+
```bash
2513
+
$ keyring set myapp secret_key
2514
+
```
2515
+
2460
2516
## Other settings source
2461
2517
2462
2518
Other settings sources are available for common configuration files:
0 commit comments