Skip to content

Instantly share code, notes, and snippets.

@guenp
Created December 2, 2024 21:22
Show Gist options
  • Save guenp/d7e6a7033cbb2c283c7aee8acc5a8c0d to your computer and use it in GitHub Desktop.
Save guenp/d7e6a7033cbb2c283c7aee8acc5a8c0d to your computer and use it in GitHub Desktop.
Minimal `dbt-duckdb` example with MotherDuck

dbt-example-motherduck

Prerequisites

This example requires Poetry. You can use pipx with pipx install poetry to install it. For further instructions, see docs.

Instructions

To get started with a sample project using dbt and MotherDuck, first create and activate a new Python environment using Poetry.

poetry install
source .venv/bin/activate

To set up your MotherDuck profile, you can copy over the profiles.yml file from this sample into your ~/.dbt folder. Please make sure to replace dbt_example with the name of the project you created in the previous step.

If you want to keep the profiles.yml file in a different location, you can run:

export DBT_PROFILES_DIR=/path/to/folder

Where /path/to/folder is the location of the profiles.yml file in this example.

Edit the dbt.env file and add your MotherDuck token. You can then load it into your environment by running:

set -a; source dbt.env; set +a

Then, create a new dbt project:

dbt init

To run the example dbt project, run:

dbt run

in your new project folder.

motherduck_token=<enter your token here>
dbt_example:
outputs:
dev:
type: duckdb
schema: main
path: md:my_db
threads: 1
local:
type: duckdb
path: test.duckdb
threads: 1
target: dev
[tool.poetry]
name = "dbt-example"
version = "0.1.0"
description = ""
authors = ["MotherDuck team <[email protected]>"]
license = "MIT"
readme = "README.md"
[tool.poetry.dependencies]
python = "^3.12"
dbt-duckdb = "^1.9.0"
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment