dlt Source and Destination Credentials via Environment Variables

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 your secrets.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:

  1. Environment Variables — highest priority; if a value is found here, dlt stops searching

  2. secrets.toml — for secrets like API keys and passwords

  3. config.toml — for non-sensitive configuration values

  4. Default values — defined in your pipeline code


Naming Convention

Environment variables follow a specific naming convention that maps directly to the structure of your secrets.toml or config.toml files.

The rules are simple:

  • All letters are capitalized

  • Nested sections (dots . in TOML) are replaced with double underscores __

For example, the following secrets.toml entry:

Translates to these environment variables:

circle-info

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:

Then load it in your pipeline script:

{% hint style="warning" %} Never commit your .env file to version control. Add it to your .gitignore to keep secrets out of your repository. {% endhint %}


Examples

Example 1: Source Credentials (Pipedrive)

The equivalent secrets.toml entry:

As an environment variable:


Example 2: Destination Credentials (BigQuery)

The equivalent secrets.toml entry:

As environment variables:


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 equivalent secrets.toml entry:

As environment variables:


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 a password field is missing for a Postgres destination, dlt will report something like:

Use these messages to confirm the exact environment variable name your pipeline expects.


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.

Last updated

Was this helpful?