Dagster dg-cli
The `dagster-dg-cli` package provides the command-line interface (CLI) for interacting with Dagster, a Python-native data orchestrator. It allows users to create projects, launch the Dagit UI, deploy to Dagster Cloud, and manage assets, jobs, and runs. The library frequently updates, often on a weekly cadence, in sync with the broader Dagster ecosystem. The current version is 1.13.0.
Warnings
- gotcha The `dagster-dg-cli` package is primarily for providing the `dg` command-line executable. It is not typically imported as a Python library into user code. Most Dagster functionality is accessed via the `dagster` core package and its sub-packages.
- gotcha The `dg api` commands for programmatic inspection (e.g., `dg api job list`, `dg api asset-check list`) are rapidly evolving. Scripts relying on specific output formats or command availability should be version-aware.
- gotcha Using `dg plus deploy` requires the `dagster-cloud` package to be installed and proper configuration (e.g., `agent_queue`, `image`) within your project's `pyproject.toml` file to generate the `dagster_cloud.yaml`.
Install
-
pip install dagster-dg-cli
Imports
- main
from dagster_dg_cli.cli import main
Quickstart
import subprocess
import os
import time
project_name = "my-dagster-quickstart"
# 1. Create a new Dagster project
print(f"Attempting to create a new Dagster project '{project_name}'...")
try:
# `dg new` automatically creates the directory if it doesn't exist
result = subprocess.run(["dg", "new", project_name], check=True, capture_output=True, text=True, timeout=30)
print(f"Project '{project_name}' created successfully:\n{result.stdout}")
except subprocess.CalledProcessError as e:
# Handle case where project already exists
if "already exists" in e.stderr:
print(f"Project '{project_name}' already exists. Skipping creation.")
else:
print(f"Error creating project: {e.stderr}")
raise
except subprocess.TimeoutExpired:
print(f"Error: 'dg new' command timed out after 30 seconds.")
raise
except FileNotFoundError:
print("Error: 'dg' command not found. Ensure dagster-dg-cli is installed and in your PATH.")
raise
# Change into the new project directory
if os.path.exists(project_name):
print(f"Changing directory to '{project_name}'...")
os.chdir(project_name)
else:
print(f"Could not find project directory '{project_name}' to change into. Exiting.")
exit(1)
# 2. Launch the Dagster UI (Dagit)
print("\nTo launch the Dagster UI (Dagit), open a new terminal in this directory and run:")
print(" dg dev")
print("\nThen navigate your browser to http://localhost:3000 to see your project.")
print("This `dg dev` command will keep running. Press Ctrl+C in that terminal to stop it.")
print("\nDemonstration complete. You can now explore 'my-dagster-quickstart' directory.")