dbt-snowflake
dbt-snowflake is the official adapter plugin for dbt (data build tool), enabling users to define, manage, and run data transformations against a Snowflake data warehouse. It extends dbt-core with Snowflake-specific SQL dialect, connection management, and materialization strategies. Current version is 1.11.4, and it is typically released in lockstep with dbt-core major and minor versions, meaning a quarterly or bi-annual cadence.
Warnings
- breaking Breaking changes in `dbt-core`'s adapter interface frequently require corresponding updates in `dbt-snowflake`. Ensure your `dbt-snowflake` version is compatible with your `dbt-core` version (e.g., dbt-core 1.x requires dbt-snowflake 1.x).
- gotcha Incorrect or incomplete Snowflake profile configuration in `profiles.yml` is the most common issue. Pay close attention to `account`, `user`, `password` (or key pair), `role`, `warehouse`, `database`, and `schema`.
- gotcha Python version compatibility. `dbt-core` and its adapters specify minimum Python versions (e.g., 3.8+ for 1.0, 3.10+ for 1.11+). Using an unsupported Python version will lead to installation or runtime errors.
- gotcha Network connectivity issues (firewalls, proxy settings, private link configurations) can prevent dbt-snowflake from connecting to Snowflake, even with correct credentials.
Install
-
pip install dbt-snowflake
Imports
- SnowflakeAdapter
from dbt.adapters.snowflake.impl import SnowflakeAdapter
- SnowflakeConnectionManager
from dbt.adapters.snowflake.connections import SnowflakeConnectionManager
Quickstart
import os
from pathlib import Path
# Define minimal profiles.yml content using environment variables.
# Make sure to set SNOWFLAKE_ACCOUNT, SNOWFLAKE_USER, SNOWFLAKE_PASSWORD,
# SNOWFLAKE_ROLE, SNOWFLAKE_WAREHOUSE, SNOWFLAKE_DATABASE, SNOWFLAKE_SCHEMA
# in your environment before running this, or replace the placeholders directly.
profiles_yml_content = f"""
dbt_snowflake_example:
target: dev
outputs:
dev:
type: snowflake
account: {os.environ.get('SNOWFLAKE_ACCOUNT', 'your_account.snowflakecomputing.com')}
user: {os.environ.get('SNOWFLAKE_USER', 'your_snowflake_user')}
password: {os.environ.get('SNOWFLAKE_PASSWORD', 'your_snowflake_password')}
role: {os.environ.get('SNOWFLAKE_ROLE', 'SYSADMIN')}
warehouse: {os.environ.get('SNOWFLAKE_WAREHOUSE', 'COMPUTE_WH')}
database: {os.environ.get('SNOWFLAKE_DATABASE', 'DBT_DEV_DB')}
schema: {os.environ.get('SNOWFLAKE_SCHEMA', 'PUBLIC')}
threads: 1
client_session_keep_alive: false
"""
# Ensure ~/.dbt directory exists and write profiles.yml
dbt_dir = Path.home() / ".dbt"
dbt_dir.mkdir(parents=True, exist_ok=True)
profiles_yml_path = dbt_dir / "profiles.yml"
with open(profiles_yml_path, "w") as f:
f.write(profiles_yml_content)
print(f"Generated a sample profiles.yml at: {profiles_yml_path}")
print("\nNext steps:")
print("1. Create a dbt project: `dbt init my_snowflake_project`")
print("2. Update `my_snowflake_project/dbt_project.yml` to use `profile: dbt_snowflake_example`")
print("3. Navigate into your project directory: `cd my_snowflake_project`")
print("4. Verify your connection: `dbt debug`")
print(" Ensure you have configured environment variables or replaced placeholders.")
# Uncomment the following to directly run dbt debug if you have dbt-core installed
# import subprocess
# try:
# print("\nAttempting to run 'dbt debug' to verify connection...")
# # This assumes you have created 'my_snowflake_project' and updated its profile
# # For a full quickstart, this requires more setup than a single snippet can provide.
# # subprocess.run(["dbt", "debug", "--profile", "dbt_snowflake_example"], check=True)
# # print("dbt debug completed successfully.")
# except FileNotFoundError:
# print("Error: 'dbt' command not found. Install dbt-core via `pip install dbt-core`.")
# except subprocess.CalledProcessError as e:
# print(f"Error during 'dbt debug': {e}")
# print("Check your profiles.yml and Snowflake credentials.")