Back to tutorials

dbt init Command: Creating a New dbt Project

Introduction

dbt is a command-line tool that enables data analysts and engineers to transform data in their warehouses more effectively. One of the key commands in dbt is dbt init, which helps you create a new dbt project. This tutorial will guide you through the process of installing dbt, creating a new project, setting up a connection profile, and more.

Installation

Before we start, make sure you have Python and pip installed on your machine. If not, you can download Python from the official website and pip is included in the package.

To install dbt and dbt-init, open your terminal and type:

pip install dbt dbt-init

Creating a New Project

To create a new dbt project, you can use the dbt init command. For example, if you want to create a new project for a client named “acme_corp” using Snowflake as the warehouse, and you want the project to be located in the ~/clients/ directory, you would run:

dbt-init --client acme_corp --warehouse snowflake --target-dir ~/clients/

This command will create a new project in the ~/clients/ directory.

Setting Up the Connection Profile

After creating a new project, you need to set up a connection profile. This is done in the profiles.yml file, which is located in the ~/.dbt/ directory.

Open the sample.profile.yml file in your project directory and update it with the correct details for your client. Replace the placeholders below with your actual details:

acme_corp:
  target: dev  
  outputs:    
    dev:      
    type: snowflake      
    account: <account>      
    user: <user>
    role: <role>
    database: <database>      
    warehouse: <warehouse>      
    schema: <schema>      
    threads: <threads>      
    private_key: <private_key>

Understanding the Project Structure

After running the dbt init command, you’ll notice several files and directories in your project directory. The most important one is dbt_project.yml, which is the main configuration file for your dbt project.

Building Out the Starter Project

In your starter project, there are several variables you can use to customize your project. For example, {{ project.name }} refers to the name of your project, {{ project.warehouse }} refers to the warehouse that your client is using, and so on. You can use these variables in your dbt_project.yml file to customize your project.

Testing the Changes

To test the changes you’ve made to your project, you can run the dbt run command. This command will execute all models in your project. Here’s an example:

dbt run

Conclusion

Congratulations! You’ve just created a new dbt project, set up a connection profile, and learned how to customize your project. As next steps, you can start creating models in your project and transforming your data.

database icon
The first SQL editor with built-in dbt Core ™
Simplified dbt development - Create and manage your dbt models and macros all in one place with PopSQL