Reuse dbt™ Connection Credentials in dlt Pipelines - BigQuery

In this guide, you'll learn how to reuse your existing BigQuery connection credentials from profiles.yml to authenticate dlt pipelines — without duplicating credentials or managing separate config files.


What the Script Expects from profiles.yml

The loader reads your active target directly from dbt_project.yml and looks it up in profiles.yml. A typical BigQuery profile looks like this:

my_project:
  target: prod
  outputs:
    dev:
      type: bigquery
      method: service-account
      project: my-gcp-project
      dataset: my_dataset
      location: US
      keyfile_json:
        type: service_account
        project_id: my-gcp-project
        private_key_id: abc123
        private_key: "-----BEGIN RSA PRIVATE KEY-----\n..."
        client_email: [email protected]

The script will load whichever target is set as target: in your profile — in this case prod.

circle-info

ingestion target is optional.

The get_credentials_by_environment() method uses an ingestion target as a fallback when your default target is prod, to avoid accidentally running pipelines against production. This is only relevant if you call that specific method — the rest of this guide uses get_active_credentials(), which works with any target name.


1. Set Up the Credentials Loader

Create a dlthub folder at the root of your dbt™ project and add the profile_connection_credentials.py script inside it.


2. Use the Credentials in Your dlt Pipeline

In your dlt pipeline file (e.g., my_pipeline.py), import the loader and pass the credentials to your BigQuery destination.

circle-info

Note

The loader automatically detects your dbt_project.yml and profiles.yml paths, as long as profile_connection_credentials.py is placed inside a dlthub folder at the root of your dbt™ project as shown above. If you place it elsewhere, pass project_dir and profiles_dir explicitly to ProfileConnectionCredentialsLoader()


Appendix: Profile Connection Credentials Loader Script

Add the following script as profile_connection_credentials.py in your dlthub folder.

Last updated

Was this helpful?