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
+68Lines changed: 68 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2392,6 +2392,74 @@ For nested models, Secret Manager supports the `env_nested_delimiter` setting as
2392
2392
2393
2393
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).
2394
2394
2395
+
### Lazy Loading
2396
+
2397
+
Lazy loading defers field value resolution until fields are actually accessed, rather than eagerly fetching all values during settings initialization. This is particularly useful when working with Google Cloud Secret Manager where each field access triggers an API call, avoiding unnecessary network requests for fields that may never be used.
2398
+
2399
+
2400
+
#### Basic Usage
2401
+
2402
+
You can enable lazy loading for Google Cloud Secret Manager via the `lazy_load` parameter when configuring `GoogleSecretManagerSettingsSource`:
When initializing `Settings()` the secrets will not be fetched. When accessing a secret for the first time, for example `secret1`, an API call will be made to fetch that secret, and will then be catched. Next access to that same secret will not trigger an API call, but accessing another one will. Operations that require all secrets, like `model_dump` triggers the fetching of all secrets.
2442
+
2443
+
#### Behavior and Caching
2444
+
2445
+
When lazy loading is enabled:
2446
+
2447
+
1.**Initialization**: Settings are created with minimal overhead. Sources return empty dictionaries instead of eagerly fetching all values.
2448
+
2449
+
2.**First Access**: When you access a field for the first time (e.g., `settings.api_key`), the value is fetched from the configured source and cached in memory.
2450
+
2451
+
3.**Subsequent Access**: Accessing the same field again returns the cached value without making another API call.
2452
+
2453
+
4.**All Fields**: Iteration over all fields (via `model_dump()`, etc.) will trigger resolution of all fields at once.
2454
+
2455
+
***When to use lazy loading:**
2456
+
2457
+
* Your settings have many fields but your application only uses a subset of them
2458
+
* You want to reduce initialization time and API call costs
2459
+
* Network latency to GCP Secret Manager is significant
2460
+
2461
+
2462
+
2395
2463
## Other settings source
2396
2464
2397
2465
Other settings sources are available for common configuration files:
0 commit comments