Setting Environment Variables in dlt
In this guide, you’ll learn how to configure credentials and secrets for your dlt pipelines using environment variables. By the end of this 5-minute tutorial, you’ll understand the naming convention, how to translate yoursecrets.toml keys into environment variable names, and how to apply this across common use cases.
How dlt Reads Configuration
dlt retrieves configuration and secrets from multiple locations in the following order of priority:- Environment Variables — highest priority; if a value is found here, dlt stops searching
secrets.toml— for secrets like API keys and passwordsconfig.toml— for non-sensitive configuration values- Default values — defined in your pipeline code
Naming Convention
Environment variables follow a specific naming convention that maps directly to the structure of yoursecrets.toml or config.toml files.
The rules are simple:
- All letters are capitalized
- Nested sections (dots
.in TOML) are replaced with double underscores__
secrets.toml entry:
Quick rule: Replace every
. with __ and capitalize everything. sources.pipedrive.pipedrive_api_key becomes SOURCES__PIPEDRIVE__PIPEDRIVE_API_KEY. Setting Environment Variables
On Paradime
In Paradime, navigate to your environment variable settings in your workspace and set the key-value pair for your Code IDE and Bolt sections.On Linux / macOS
Export variables directly in your terminal session:On Windows (Command Prompt)
In a .env File (Local Development)
For local development, create a .env file in your project root and use python-dotenv to load it automatically:
Examples
Example 1: Source Credentials (Pipedrive)
The equivalentsecrets.toml entry:
Example 2: Destination Credentials (BigQuery)
The equivalentsecrets.toml entry:
Example 3: Mixing Environment Variables with Existing Variables
If you already have credentials stored under different environment variable names (for example, from another tool), you can map them to the dlt naming convention in your pipeline script:Example 4: Filesystem Source (AWS S3)
The equivalentsecrets.toml entry:
How dlt Searches for a Value
When a configuration value is missing, dlt logs the exact lookup path it tried. This makes it easy to diagnose issues. For example, if apassword field is missing for a Postgres destination, dlt will report something like:
Best Practices
- Use environment variables in CI/CD and production to avoid storing secrets in files that could be accidentally committed to version control.
- Rely on dlt’s error messages when debugging missing credentials — they show the exact keys and providers that were checked.
- Don’t mix providers unnecessarily — define each credential in one place to avoid confusion over which value dlt is picking up.