Skip to main content

A simple CLI to switch between dbt Cloud projects and hosts.

Project description

dbt-switch

This is a simple CLI tool to manage and switch between dbt Cloud projects and hosts. This util was inspired by working in professional services/consulting and running into minor pain points with managing multuple dbt Cloud projects that exist in different accounts. The crux of the issue is documented in this dbt forum post: dbt Cloud CLI - Connect to Mulitple Hosts.

For the dbt_cloud.yml configuration file to work properly with mulitple accounts, the context key needs to be updated with an active project's host and project_id:

context:
  active-host: "cloud.getdbt.com"
  active-project: "12345"

As seen in the dbt Cloud CLI docs, you need to set the correct active host and project ID before using the dbt Cloud CLI with your desired project. Espeacially if you have a custom active-host URL, you have manually swap out the active-host in your dbt_cloud.yml (in addition to swapping the active-project)every time you switch to a new dbt Cloud account's project.

Instead of manually swapping out active-host and active-project in dbt_cloud.yml, this utility allows you to define projects and their associated host/project ID and easily switch between them from the CLI.

Requirements

Installation

uv tool install dbt-switch

Overview

dbt-switch helps you:

  1. Manage project configurations in ~/.dbt/dbt_switch.yml
  2. Switch active projects in your ~/.dbt/dbt_cloud.yml file

Quick Start

# Initialize the configuration file
dbt-switch init

# Add a new project configuration
dbt-switch add

# List all configured projects
dbt-switch list

# Switch to a project
dbt-switch --project alpha-analytics
dbt-switch -p beta-corp

Configuration Files

1. dbt_switch.yml (~/.dbt/dbt_switch.yml)

This file stores your project configurations:

profiles:
  alpha-analytics:
    host: cloud.getdbt.com
    project_id: 12345
  beta-corp:
    host: cloud.getdbt.com  
    project_id: 67890
  gamma-solutions:
    host: xyz123.us1.dbt.com
    project_id: 54321

2. dbt_cloud.yml (~/.dbt/dbt_cloud.yml)

Your standard dbt Cloud configuration file should look something like:

Note: You will have to manually merge the projects from your different dbt Cloud accounts into a single ~/.dbt/dbt_cloud.yml file.

version: "1"
context:
  active-host: "cloud.getdbt.com"
  active-project: "12345"
projects:
  - project-name: "Client Alpha Analytics"
    project-id: "12345"
    account-name: "Alpha Industries"
    account-id: "11111"
    account-host: "cloud.getdbt.com"
    token-name: "cloud-cli-alpha"
    token-value: "dbtu_alpha_token_here"

  - project-name: "Beta Corp Reporting" # Originally from its own dbt_cloud.yml, manually "merged" (paseted) in
    project-id: "67890"
    account-name: "Beta Corporation"
    account-id: "22222"
    account-host: "cloud.getdbt.com"
    token-name: "cloud-cli-beta"
    token-value: "dbtu_beta_token_here"

  - project-name: "Gamma Solutions Data" # Originally from its own dbt_cloud.yml, manually "merged" (paseted) in
    project-id: "54321"
    account-name: "Gamma Solutions (Partner)"
    account-id: "33333"
    account-host: "xyz123.us1.dbt.com"
    token-name: "cloud-cli-gamma"
    token-value: "dbtu_gamma_token_here"

Usage

Project Management

Note: These commands are interactive and trigger a bash prompt!

# Initialize configuration file
dbt-switch init

# Add a new project
dbt-switch add
# Enter project name: my-project
# Enter project host: cloud.getdbt.com
# Enter project id: 123456

# Update project host
dbt-switch update --host

# Update project ID  
dbt-switch update --project-id

# Delete a project
dbt-switch delete

# List all projects
dbt-switch list

Project Switching

# Switch to a project (long form)
dbt-switch --project alpha-analytics

# Switch to a project (short form)
dbt-switch -p beta-corp

# Get help
dbt-switch --help

Example

  1. Initialize and add projects:
$ dbt-switch init
Initialized /Users/username/.dbt/dbt_switch.yml

$ dbt-switch add
Enter the project name: alpha-analytics
Enter the project host: cloud.getdbt.com
Enter the project id: 12345
Added project 'alpha-analytics' with host 'cloud.getdbt.com' and project_id 12345

$ dbt-switch add
Enter the project name: beta-corp  
Enter the project host: cloud.getdbt.com
Enter the project id: 67890
Added project 'beta-corp' with host 'cloud.getdbt.com' and project_id 67890
  1. Switch between projects:
$ dbt-switch -p alpha-analytics
Successfully switched to project 'alpha-analytics' Set active host: cloud.getdbt.com
✓ Set active project: 12345

$ dbt-switch -p beta-corp  
Successfully switched to project 'beta-corp' Set active host: cloud.getdbt.com
✓ Set active project: 67890

$ dbt-switch list
Available projects:
  alpha-analytics (cloud.getdbt.com, ID: 12345)
* beta-corp      (cloud.getdbt.com, ID: 67890) [ACTIVE]

Commands

Command Description
dbt-switch init Initialize the ~/.dbt/dbt_switch.yml file
dbt-switch add Add a new project configuration
dbt-switch list List all configured projects with their details
dbt-switch update --host Update a project's host
dbt-switch update --project-id Update a project's ID
dbt-switch delete Delete a project configuration
dbt-switch -p PROJECT Switch to the specified project
dbt-switch --project PROJECT Switch to the specified project (long form)
dbt-switch --help Show help message

How It Works

  1. Store configurations: dbt-switch maintains your project configurations in ~/.dbt/dbt_switch.yml
  2. Update dbt Cloud config: When you switch projects, it updates the active-host and active-project fields in your ~/.dbt/dbt_cloud.yml
  3. Preserve your data: All other fields in dbt_cloud.yml (like tokens and project lists) are preserved

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dbt_switch-0.2.3.tar.gz (11.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dbt_switch-0.2.3-py3-none-any.whl (13.2 kB view details)

Uploaded Python 3

File details

Details for the file dbt_switch-0.2.3.tar.gz.

File metadata

  • Download URL: dbt_switch-0.2.3.tar.gz
  • Upload date:
  • Size: 11.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.8

File hashes

Hashes for dbt_switch-0.2.3.tar.gz
Algorithm Hash digest
SHA256 db95d2750fec9b0aa81eb15b4e7791dd43f91baed1b541666732b6268bd59dab
MD5 778cf0c79c2ae22a2e11744443d37d81
BLAKE2b-256 2fdcc8543fc3fbb677b410284d5ff14a8c2cfe37882ec61d79fda153d6556ff9

See more details on using hashes here.

File details

Details for the file dbt_switch-0.2.3-py3-none-any.whl.

File metadata

  • Download URL: dbt_switch-0.2.3-py3-none-any.whl
  • Upload date:
  • Size: 13.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.8

File hashes

Hashes for dbt_switch-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 dea541a40057708129212300b973af4872ea5799ee35c9975da690184c0a9ad9
MD5 c168cd1e0fae0ccccf52ee7f97a74925
BLAKE2b-256 80e2225c7acffc6a82ab93b2411b656be49389cc9474bf7a51bc20bad0416d5b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page