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.3.tar.gz (31.4 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.3-py3-none-any.whl (34.8 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for dspy_cli-0.1.3.tar.gz
Algorithm Hash digest
SHA256 8a990aa77e2d0dc48f1ba31304b24fef86c00c3b5a9225c52d10c6d38107d4a2
MD5 15048693bd483aad3d2434a8c78a0ff0
BLAKE2b-256 92df78f8bb817a5e3849faf1f1ef7b1fb85bb720b77d47fbbff1a462d258a311

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for dspy_cli-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 dbee97519e5c50de10c7a18a5a8df75ce133a8cec87d92490f93430307c8d4a7
MD5 e7f2fe51bf37c798136e5368d1e0bdbd
BLAKE2b-256 72a8db4c5bcdfa4b68c93a9451bab66c7b94bb5b12a8e8e203dcd0f7a36266a4

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