DEV Community

Sospeter Mong'are
Sospeter Mong'are

Posted on

Getting Started with Dagster: A Beginner's Guide

Welcome! Let's create a simple Dagster project step by step. 🎉


Step 1: Scaffold a New Dagster Project

Open your WSL terminal and run:

pip install create-dagster
create-dagster project my-first-dagster-project
Enter fullscreen mode Exit fullscreen mode

Then navigate into your project:

cd my-first-dagster-project
Enter fullscreen mode Exit fullscreen mode

1


Step 2: Set Up Your Virtual Environment

python -m venv .venv
source .venv/bin/activate
pip install --editable .
Enter fullscreen mode Exit fullscreen mode

2


Step 3: Your Project Structure

Your project should look like this:

.
├── pyproject.toml
├── README.md
├── src
│   └── my_first_dagster_project
│       ├── __init__.py
│       ├── definitions.py
│       └── defs
│           └── __init__.py
└── tests
    └── __init__.py
Enter fullscreen mode Exit fullscreen mode

3


Step 4: Create Your First Asset

Inside src/my_first_dagster_project/defs/, create a file called assets.py and add this simple code:

import dagster as dg

@dg.asset
def my_first_asset():
    print("Hello from my first Dagster asset!")
    return [1, 2, 3, 4, 5]

@dg.asset
def my_second_asset(my_first_asset):
    total = sum(my_first_asset)
    print(f"The sum is: {total}")
    return total
Enter fullscreen mode Exit fullscreen mode

Step 5: Register Your Assets in definitions.py

Open src/my_first_dagster_project/definitions.py and update it:

import dagster as dg
from my_first_dagster_project.defs.assets import my_first_asset, my_second_asset

defs = dg.Definitions(
    assets=[my_first_asset, my_second_asset],
)
Enter fullscreen mode Exit fullscreen mode

Step 6: Launch the Dagster UI

Run the following command:

dg dev
Enter fullscreen mode Exit fullscreen mode

Then open your browser and go to:
👉 http://127.0.0.1:3000

4


Step 7: Materialize Your Assets

  1. In the Dagster UI, click on Assets in the top navigation
  2. You should see my_first_asset and my_second_asset
  3. Click Materialize All to run them
  4. Watch them execute and check the logs! ✅

What Just Happened? 🤔

  • my_first_asset runs first and returns a list of numbers
  • my_second_asset depends on my_first_asset and calculates the sum
  • Dagster automatically figures out the execution order based on dependencies!

Question: Should I be running this everytime, Even though I installed Dagster?

Great question! No, you don't need to run those commands every time. Here's what each command does and when you need it:


One-Time Commands (Run Only Once)

These are setup commands you only run when creating a new project:

pip install create-dagster                        # Installs the create-dagster tool
create-dagster project my-first-dagster-project   # Creates your project folder
Enter fullscreen mode Exit fullscreen mode

Think of it like creating a new folder/workspace — you only do it once! 1


Every Time You Work on Your Project

These are the commands you run each time you open a new terminal session:

# 1. Navigate to your project
cd my-first-dagster-project

# 2. Activate your virtual environment (REQUIRED every new terminal session)
source .venv/bin/activate

# 3. Start the Dagster UI
dg dev
Enter fullscreen mode Exit fullscreen mode

2


Quick Summary Table

Command When to Run
pip install create-dagster ✅ Once ever
create-dagster project my-project ✅ Once per new project
python -m venv .venv ✅ Once per new project
source .venv/bin/activate 🔁 Every new terminal session
dg dev 🔁 Every time you want to use the UI

Pro Tip 💡

Since you're on WSL (Windows), every time you open a new terminal, just run:

cd my-first-dagster-project
source .venv/bin/activate
dg dev
Enter fullscreen mode Exit fullscreen mode

And you're good to go! 🚀

You're now running your first Dagster pipeline! Feel free to ask if you have any questions. 🚀

Top comments (0)