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
- uv
- Proper dbt Cloud CLI credentials/config that exist in your
~/.dbt/dbt_cloud.ymlfile
Installation
uv tool install dbt-switch
Overview
dbt-switch helps you:
- Manage project configurations in
~/.dbt/dbt_switch.yml - Switch active projects in your
~/.dbt/dbt_cloud.ymlfile
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
projectsfrom your different dbt Cloud accounts into a single~/.dbt/dbt_cloud.ymlfile.
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
- 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
- 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
- Store configurations:
dbt-switchmaintains your project configurations in~/.dbt/dbt_switch.yml - Update dbt Cloud config: When you switch projects, it updates the
active-hostandactive-projectfields in your~/.dbt/dbt_cloud.yml - Preserve your data: All other fields in
dbt_cloud.yml(like tokens and project lists) are preserved
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dbt_switch-0.2.4.tar.gz.
File metadata
- Download URL: dbt_switch-0.2.4.tar.gz
- Upload date:
- Size: 11.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ce885019a99f74a56414aef951afab162c07b3fbbc47900201e85e013f3ec121
|
|
| MD5 |
8489d50c31a4d9b1a85ce2b3d53d558a
|
|
| BLAKE2b-256 |
105c31f17cf40472bb22faf32425a0e4855586999f47966f10c9ad251f30301d
|
File details
Details for the file dbt_switch-0.2.4-py3-none-any.whl.
File metadata
- Download URL: dbt_switch-0.2.4-py3-none-any.whl
- Upload date:
- Size: 13.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cf9532d2692c7729b66461cb5727553a47aeed5463d897723f205ef51037d557
|
|
| MD5 |
28fcb7702c6d97b91258ec29875e9cb3
|
|
| BLAKE2b-256 |
8d2712708b41f2fb41d6a051758dc08fe5dc591ca50d8211c48038d798fc1fd4
|