Dagster dg-cli

1.13.0 · active · verified Sat Apr 11

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

Install

Imports

Quickstart

This quickstart demonstrates how to create a new Dagster project using `dg new`. It then provides instructions to launch the local development UI (Dagit) with `dg dev` in a separate terminal to interact with the newly created project. The Python script executes the setup command but provides clear instructions for the long-running `dg dev` command.

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.")

view raw JSON →