Skip to main content

A CLI tool for creating and serving DSPy projects

Project description

dspy-cli

A command-line interface tool for creating and serving DSPy projects, inspired by Ruby on Rails.

Installation

uv add dspy-cli

Installing for Development/Testing

If you're testing or developing dspy-cli itself:

# Clone or navigate to the dspy-cli repository
cd /path/to/dspy-cli

# Sync dependencies
uv sync --extra dev

# Now the dspy-cli command is available
dspy-cli --help

Quick Start

Create a new DSPy project

dspy-cli new my-project
cd my-project

Create a project with a custom program name

dspy-cli new my-project -p custom_program

Create a project with a custom signature

dspy-cli new blog-tagger -s "post -> tags: list[str]"

Serve your DSPy programs as an API

dspy-cli serve --port 8000 --host 0.0.0.0

Features

  • Project scaffolding: Generate a complete DSPy project structure with boilerplate code
  • Code generation: Quickly scaffold new DSPy programs with signatures and modules using Rails-style generators
  • Convention over configuration: Organized directory structure for modules, signatures, optimizers, and metrics
  • HTTP API server: Automatically serve your DSPy programs as REST endpoints
  • Flexible configuration: YAML-based model configuration with environment variable support
  • Logging: Request logging to both STDOUT and per-module log files

Project Structure

When you create a new project, dspy-cli generates the following structure:

my-project/
├── pyproject.toml
├── dspy.config.yaml       # Model registry and configuration
├── .env                   # API keys and secrets
├── README.md
├── src/
│   └── dspy_project/      # Importable package
│       ├── __init__.py
│       ├── modules/       # DSPy program implementations
│       ├── signatures/    # Reusable signatures
│       ├── optimizers/    # Optimizer configurations
│       ├── metrics/       # Evaluation metrics
│       └── utils/         # Shared helpers
├── data/
├── logs/
└── tests/

Commands

new

Create a new DSPy project with boilerplate structure.

dspy-cli new [PROJECT_NAME] [OPTIONS]

Options:

  • -p, --program-name TEXT: Name of the initial program (default: converts project name)
  • -s, --signature TEXT: Inline signature string (e.g., "question -> answer" or "post -> tags: list[str]")

Examples:

# Basic project
dspy-cli new my-project

# With custom program name
dspy-cli new my-project -p custom_program

# With custom signature
dspy-cli new blog-tagger -s "post -> tags: list[str]"

# With both program name and signature
dspy-cli new analyzer -p text_analyzer -s "text, context: list[str] -> summary, sentiment: bool"

generate (alias: g)

Generate new components in an existing DSPy project.

dspy-cli generate scaffold PROGRAM_NAME [OPTIONS]
dspy-cli g scaffold PROGRAM_NAME [OPTIONS]

Options:

  • -m, --module TEXT: DSPy module type to use (default: Predict)
    • Available: Predict, ChainOfThought (or CoT), ProgramOfThought (or PoT), ReAct, MultiChainComparison, Refine
  • -s, --signature TEXT: Inline signature string (e.g., "question -> answer")

Examples:

# Basic scaffold with default Predict module
dspy-cli g scaffold categorizer

# Scaffold with ChainOfThought
dspy-cli g scaffold categorizer -m CoT

# Scaffold with custom signature
dspy-cli g scaffold qa -m CoT -s "question -> answer"

# Complex signature with types
dspy-cli g scaffold search -s "query, context: list[str] -> answer, confidence: float"

serve

Start an HTTP API server that exposes your DSPy programs.

dspy-cli serve [OPTIONS]

Options:

  • --port INTEGER: Port to run the server on (default: 8000)
  • --host TEXT: Host to bind to (default: 0.0.0.0)

Endpoints:

  • GET /programs: List all discovered programs with their schemas
  • POST /{program}: Execute a program with JSON payload

Configuration

dspy.config.yaml

Configure your language models and routing:

models:
  default: openai:gpt-4o-mini
  registry:
    openai:gpt-4o-mini:
      model: openai/gpt-4o-mini
      env: OPENAI_API_KEY
      max_tokens: 16000
      temperature: 1.0
      model_type: chat
    anthropic:sonnet-4-5:
      model: anthropic/claude-sonnet-4-5
      env: ANTHROPIC_API_KEY
      model_type: chat

# Optional: per-program model overrides
program_models:
  MySpecialProgram: anthropic:sonnet-4-5

.env

Store your API keys and secrets:

OPENAI_API_KEY=sk-...
ANTHROPIC_API_KEY=sk-ant-...

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dspy_cli-0.1.4.tar.gz (43.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dspy_cli-0.1.4-py3-none-any.whl (51.1 kB view details)

Uploaded Python 3

File details

Details for the file dspy_cli-0.1.4.tar.gz.

File metadata

  • Download URL: dspy_cli-0.1.4.tar.gz
  • Upload date:
  • Size: 43.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.7

File hashes

Hashes for dspy_cli-0.1.4.tar.gz
Algorithm Hash digest
SHA256 c6195623c61594013373255a889935e56bf85b8182335191446edf6af053a5c5
MD5 c6889bc9e5155e1b334308f5d85db709
BLAKE2b-256 ce1c2efb628e9d427be0091c3ba9a8f135b0f57cb360498bdd7f72b74d0b911c

See more details on using hashes here.

File details

Details for the file dspy_cli-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: dspy_cli-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 51.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.7

File hashes

Hashes for dspy_cli-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 0899820da978671f90d1e993d70b3540b5aae728fffac42d9096a270142d9b94
MD5 ec3e720d0df0ed0382a8aa35fb2a4f7f
BLAKE2b-256 b007eef44253920968f767e6599b6396f08e0f07bd9f59ca70bec35315cf9065

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page