Configuration ⚙️¶
Overview 🌟¶
This document explains how to configure pydantic-settings-doppler to retrieve secrets from Doppler.
Environment Variables 🌍¶
To use DopplerSettingsSource, you need to configure the following environment variables:
DOPPLER_TOKEN: Your Doppler access token. This is required to authenticate with the Doppler API.DOPPLER_PROJECT_ID: The ID of your Doppler project. This identifies the project from which secrets will be retrieved.DOPPLER_CONFIG_ID: The ID of your Doppler configuration. This specifies the configuration environment (e.g., development, staging, production).
Example ✅¶
Set the environment variables in your shell:
Alternatively, you can use a .env file:
Direct Initialization 🛠️¶
You can also pass the configuration values directly to DopplerSettingsSource when initializing it:
Error Handling 🚨¶
If a required field is not found in Doppler, a ValidationError will be raised. Ensure all required secrets are present in your Doppler configuration.
If any of config variables are not found either in environment variables on not passed in the constructor, a SettingsError will be raised.
Logging Configuration 📝¶
pydantic-settings-doppler uses Python's logging module to provide debug and warning messages. To enable debug logging, configure the logger:
Advanced Configuration 🔧¶
Customizing Field Names¶
By default, DopplerSettingsSource uses the field name in uppercase as the key to retrieve secrets from Doppler. You can customize this behavior by setting the alias or serialization_alias attribute in your Settings model:
- Maps the
db_urlfield to theDATABASE_URLkey in Doppler. - Uses the default field name
API_KEYin uppercase as the key.