Implementation:PrefectHQ Prefect Build Dbt Project Task
Appearance
| Metadata | |
|---|---|
| Source | Repo: Prefect |
| Domains | Analytics_Engineering, Orchestration |
| Last Updated | 2026-02-09 00:00 GMT |
Overview
Concrete task for downloading and extracting dbt projects from GitHub archives with caching support.
Description
The build_dbt_project task downloads a dbt project as a ZIP archive from GitHub, extracts it to a local directory, and returns the path. It caches the result by checking if the project directory already exists. Decorated with @task(retries=2, retry_delay_seconds=5) for network resilience.
Code Reference
- Repository: https://github.com/PrefectHQ/prefect
- File: examples/run_dbt_with_prefect.py (L75-116)
- Signature:
@task(retries=2, retry_delay_seconds=5, log_prints=True)
def build_dbt_project(repo_zip_url: str = DEFAULT_REPO_ZIP) -> Path:
"""Download and extract the demo dbt project, returning its local path."""
project_dir = Path(__file__).parent / "prefect_dbt_project"
if project_dir.exists():
print(f"Using cached dbt project at {project_dir}")
return project_dir
# ... download, extract, return project_dir
- Import:
from prefect import task; import urllib.request, zipfile, io, shutil; from pathlib import Path
I/O Contract
| Direction | Name | Type | Description |
|---|---|---|---|
| Input | repo_zip_url | str (optional) | GitHub ZIP archive URL, has default |
| Output | (return) | Path | Local path to extracted dbt project directory |
Usage Example
from pathlib import Path
from prefect import flow, task
@task(retries=2, retry_delay_seconds=5, log_prints=True)
def build_dbt_project(repo_zip_url: str = "https://github.com/...") -> Path:
project_dir = Path(__file__).parent / "prefect_dbt_project"
if project_dir.exists():
return project_dir
# Download and extract ZIP archive
# ... extraction logic ...
return project_dir
@flow(name="dbt_flow", log_prints=True)
def dbt_flow():
project_dir = build_dbt_project()
create_dbt_profiles(project_dir)
run_dbt_commands(["deps"], project_dir)
run_dbt_commands(["run"], project_dir)
Related Pages
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment