📖 Scenario: You work as a data analyst in a company that uses dbt (data build tool) to manage data transformations. You want to create your own reusable dbt package to organize your SQL models and share them with your team.
🎯 Goal: Build a simple dbt package with a model that selects data from a source table, configure the package, and run it to see the output.
📋 What You'll Learn
Create a dbt package folder structure
Write a simple SQL model file
Add a dbt_project.yml configuration file
Run the dbt model and display the results
💡 Why This Matters
🌍 Real World
Data teams use dbt packages to organize and share data transformation logic efficiently.
💼 Career
Knowing how to create and manage dbt packages is valuable for data analysts and engineers working with modern data stacks.
Progress0 / 4 steps
1
Set up the dbt package folder and model
Create a folder named my_dbt_package. Inside it, create a folder named models. Inside models, create a file named my_first_model.sql with the exact content: select 1 as id, 'dbt package' as description.
dbt
Hint
Remember to create folders my_dbt_package and models inside it. Then create the SQL file with the exact select statement.
2
Add the dbt_project.yml configuration file
Inside the my_dbt_package folder, create a file named dbt_project.yml. Add the exact content: name: 'my_dbt_package'
version: '1.0'
config-version: 2
profile: 'default'
model-paths: ['models']
target-path: 'target'
dbt
Hint
Make sure the dbt_project.yml file is inside my_dbt_package folder and has the exact keys and values.
3
Run the dbt model
Run the dbt command to build the model inside the my_dbt_package folder. Use the command dbt run --project-dir my_dbt_package to execute the model.
dbt
Hint
Use the exact command dbt run --project-dir my_dbt_package to run your model.
4
Display the model output
After running the model, query the built table named my_first_model in your data warehouse or use dbt run-operation to check the output. For this exercise, print the expected output: id | description
1 | dbt package.
dbt
Hint
Print the exact output lines as shown to simulate the model result.
Practice
(1/5)
1. What is the main purpose of creating your own dbt package?
easy
A. To reuse and share data models easily across projects
B. To write SQL queries faster
C. To create dashboards automatically
D. To store raw data files
Solution
Step 1: Understand the role of dbt packages
dbt packages are designed to bundle data models and logic for reuse.
Step 2: Identify the main benefit
Sharing and reusing models saves time and keeps projects consistent.
Final Answer:
To reuse and share data models easily across projects -> Option A
Quick Check:
dbt package purpose = reuse/share models [OK]
Hint: Think: Why share code? To reuse it easily [OK]
Common Mistakes:
Confusing packages with dashboards
Thinking packages store raw data
Believing packages speed up SQL writing only
2. Which file do you edit to add a new dbt package to your main project?
easy
A. models.sql
B. dbt_project.yml
C. profiles.yml
D. packages.yml
Solution
Step 1: Recall where packages are declared
dbt uses packages.yml to list external or local packages.
Step 2: Differentiate from other config files
dbt_project.yml configures the project itself, not packages.
Final Answer:
packages.yml -> Option D
Quick Check:
Package list file = packages.yml [OK]
Hint: Add packages in packages.yml, not dbt_project.yml [OK]
Common Mistakes:
Adding packages in dbt_project.yml
Confusing profiles.yml with packages.yml
Trying to add packages in SQL files
3. Given this packages.yml snippet:
packages:
- local: ../my_dbt_package
What command installs this package into your project?
easy
A. dbt install
B. dbt build
C. dbt deps
D. dbt run
Solution
Step 1: Identify the command for package installation
dbt uses dbt deps to download and install packages listed in packages.yml.
Step 2: Differentiate from other commands
dbt run runs models, dbt install is not a valid command.
Final Answer:
dbt deps -> Option C
Quick Check:
Install packages with dbt deps [OK]
Hint: Use dbt deps to install packages listed in packages.yml [OK]
Common Mistakes:
Using dbt install (not a valid command)
Confusing dbt run with package install
Trying dbt build instead of dbt deps
4. You created a package but when running dbt deps, you get an error: "Could not find package at path '../my_package'". What is the likely cause?
medium
A. The relative path in packages.yml is incorrect or folder missing
B. You forgot to run dbt run first
C. The package name is missing in dbt_project.yml
D. You need to delete the profiles.yml file
Solution
Step 1: Understand the error message
"Could not find package at path" means dbt cannot locate the folder specified.
Step 2: Check the path in packages.yml
Relative paths must be correct and folder must exist for local packages.
Final Answer:
The relative path in packages.yml is incorrect or folder missing -> Option A
Quick Check:
Path error = wrong folder path [OK]
Hint: Check folder path in packages.yml matches actual location [OK]
Common Mistakes:
Running dbt run before dbt deps
Editing dbt_project.yml instead of packages.yml
Deleting unrelated config files
5. You want to use a model named customer_summary from your custom package my_package. Which is the correct way to reference it in your SQL model?
hard
A. select * from {{ ref('my_package', 'customer_summary') }}
B. select * from {{ ref('my_package.customer_summary') }}
C. select * from {{ ref('customer_summary') }}
D. select * from {{ ref('my_package__customer_summary') }}
Solution
Step 1: Recall how to reference models from packages
Use ref('package_name.model_name') to refer to models in packages.
Step 2: Check each option's syntax
select * from {{ ref('my_package.customer_summary') }} uses the correct single-argument ref syntax with dot notation for packages.
Final Answer:
select * from {{ ref('my_package.customer_summary') }} -> Option B
Quick Check:
Package model ref = ref('package.model') [OK]
Hint: Use ref('package.model') to access package models [OK]
Common Mistakes:
Using ref('package', 'model') syntax (that's for sources)
Forgetting the package name in ref
Using double underscore instead of dot
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.