Skip to main content

Claude Code for DSPy: AI-powered interactive development environment for DSPy

Project description

DSPy Code Logo
DSPy Code
DSPy Code

๐Ÿš€ Your AI-Powered DSPy Development & Optimization Assistant

Develop DSPy Applications โ€ข Optimize with GEPA โ€ข Deploy with Confidence. Think of it as Claude Code for DSPy

Python 3.10+ License: MIT PyPI version Beta CI Code style: ruff Pre-commit

๐Ÿ“– Documentation โ€ข ๐Ÿš€ Quick Start โ€ข ๐Ÿ’ก Examples โ€ข ๐Ÿค Contributing


โšก Claude Code for DSPy

๐Ÿš€ Get Started in 30 Seconds

โœจ Always install the latest version for best experience โœจ

pip install --upgrade dspy-code

Develop DSPy Code โ†’ Optimize with GEPA โ†’ Deploy Production-Ready Apps

๐Ÿ’ก Note: DSPy Code is in its initial release and under active development. The quality and effectiveness of generated code depends on several factors: the language model you connect, MCP (Model Context Protocol) servers you integrate, and the context you provide to DSPy Code. We're continuously improving based on community feedback.


โœจ What is DSPy Code?

The Complete DSPy Development & Optimization Platform

DSPy Code is a dual-purpose CLI that empowers you to:

๐Ÿ—๏ธ Develop DSPy Applications

Build, learn, and create DSPy programs with natural language. Generate signatures, modules, and complete applications with AI-powered assistance.

๐Ÿงฌ Optimize with GEPA

Transform your DSPy code into production-ready applications using GEPA (Genetic Pareto). Automatically improve accuracy, evolve prompts, and achieve better performance.

The Complete Workflow:

Develop โ†’ Validate โ†’ Optimize with GEPA โ†’ Deploy

๐Ÿ’ก Learn as you build. Whether you're a complete beginner or a DSPy expert, the CLI adapts to your level and guides you through every step.

๐ŸŽฏ Perfect For:

๐Ÿ—๏ธ Development ๐Ÿงฌ Optimization
๐ŸŽ“ Learning DSPy concepts โšก GEPA optimization workflows
๐Ÿš€ Building new projects ๐Ÿ“Š Automated metric evaluation
๐Ÿ“ Code generation ๐Ÿ”„ Prompt evolution
โœ… Validation & best practices ๐Ÿ“ˆ Performance improvement
๐Ÿ“š Codebase understanding ๐ŸŽฏ Production-ready code

๐ŸŽฏ Why DSPy Code?

"Why not just use Claude Code or Cursor, DeepWiki, CodeWiki with the DSPy repository?" While general AI assistants can help with DSPy, they lack the deep specialization that makes DSPy Code uniquely powerful:

What Makes DSPy Code Special?

Generic AI Assistants DSPy Code
๐Ÿ“– Generic coding help ๐ŸŽ“ DSPy-Native Intelligence - Built-in knowledge of all 10 predictors, 11 optimizers, 4 adapters, and DSPy patterns
๐Ÿ”„ Unaware of your setup ๐Ÿ“ฆ Version-Aware - Indexes YOUR installed DSPy version and generates compatible code
๐Ÿ’ญ Code suggestions only ๐Ÿงฌ Real GEPA Execution - Actually runs optimization workflows, not just code generation
๐Ÿ“ Basic file reading ๐Ÿ“š Codebase RAG - Deeply understands your entire project structure and patterns
โœ๏ธ Syntax checking โœ… DSPy Validation - Enforces signatures, modules, predictors, and best practices
๐Ÿคท Generic workflows โš™๏ธ Complete Automation - End-to-end workflows from /init to /export
๐Ÿ”Œ No tool integration ๐Ÿ”— MCP Client Built-in - Connect to external tools and services seamlessly
๐Ÿ“ Start from scratch ๐Ÿ“‹ 20+ Templates - Pre-built patterns for RAG, QA, classification, and more

Real-World Impact

Learning DSPy:

  • Generic AI: Hours of reading docs, piecing together concepts
  • DSPy Code: Ask "What is ChainOfThought?" โ†’ Get comprehensive answer with examples instantly

Building a RAG System:

  • Generic AI: Days of manual setup, configuration, testing
  • DSPy Code: /init โ†’ "Create a RAG system" โ†’ /validate โ†’ /optimize โ†’ Done in hours

Optimizing Code:

  • Generic AI: Manual GEPA setup, metric functions, data formatting
  • DSPy Code: /optimize my_program.py โ†’ Automated workflow with progress tracking

The Bottom Line

DSPy Code is a purpose-built development environment that embeds DSPy expertise into every interaction, automates tedious workflows, and accelerates your development from hours to minutes.

๐Ÿ”„ Two Core Workflows

Workflow 1: Develop DSPy Applications

From idea to working code in minutes:

  1. Start - /init to create or scan your project
  2. Describe - Tell DSPy Code what you want in natural language
  3. Generate - Get working DSPy code (signatures, modules, programs)
  4. Validate - Ensure code follows DSPy best practices
  5. Iterate - Refine and improve with interactive Q&A

Example:

dspy-code
/init
โ†’ "Create a sentiment analyzer for customer reviews"
/validate

Workflow 2: Optimize with GEPA

From working code to production-ready in hours:

  1. Prepare - Have your DSPy program ready
  2. Generate Data - Create training examples with /data
  3. Optimize - Run GEPA optimization with /optimize
  4. Evaluate - Test performance improvements
  5. Deploy - Export optimized, production-ready code

Example:

dspy-code
/data sentiment 20  # Generate 20 training examples
/optimize my_program.py  # Run GEPA optimization
/eval  # Evaluate performance
/export  # Package for deployment

The Complete Journey

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Development Phase                                      โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”            โ”‚
โ”‚  โ”‚   Init   โ”‚โ†’ โ”‚  Generate โ”‚โ†’ โ”‚ Validate โ”‚            โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜            โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                        โ†“
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Optimization Phase                                     โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”            โ”‚
โ”‚  โ”‚   Data   โ”‚โ†’ โ”‚ Optimize  โ”‚โ†’ โ”‚  Deploy  โ”‚            โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜            โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Result: Production-ready DSPy applications with optimized performance

๐ŸŽฏ Key Features

๐Ÿ—๏ธ Development Features

  • ๐Ÿ—ฃ๏ธ Natural Language Interface - Describe your DSPy task in plain English
  • ๐Ÿง  Version-Aware Intelligence - Adapts to your installed DSPy version
  • ๐Ÿ“š Codebase RAG - Understands your project with intelligent indexing
  • โœ… Smart Validation - Ensures code follows DSPy best practices
  • ๐Ÿš€ Code Generation - Generate signatures, modules, and complete programs
  • ๐Ÿ”— Built-in MCP Client - Connect to any MCP server for external tools
  • ๐Ÿ“‹ 20+ Templates - Pre-built patterns for RAG, QA, classification

๐Ÿงฌ Optimization Features

  • ๐Ÿงฌ GEPA Optimization - Real Genetic Pareto integration
  • ๐Ÿ“Š Automated Metrics - Built-in evaluation (Accuracy, F1, ROUGE, BLEU)
  • ๐Ÿ”„ Prompt Evolution - Automatically improve instructions and examples
  • ๐Ÿ“ˆ Performance Tracking - Monitor optimization progress in real-time
  • ๐Ÿ’พ Session Management - Save and resume optimization workflows
  • ๐ŸŽฏ Production Ready - Export optimized code for deployment
  • ๐Ÿ“ฆ Export/Import - Package and share optimized DSPy projects

๐Ÿš€ Quick Start

Installation

โš ๏ธ CRITICAL: Always create your virtual environment INSIDE your project directory!

โœจ Always install the latest version for the best experience! โœจ

๐Ÿ“ Step 1: Create a project directory

mkdir my-dspy-project
cd my-dspy-project

๐Ÿ Step 2: Create virtual environment IN this directory (not elsewhere!)

python -m venv .venv

โšก Step 3: Activate it

# For bash/zsh:
source .venv/bin/activate

# For fish shell:
source .venv/bin/activate.fish

# On Windows:
.venv\Scripts\activate

๐Ÿš€ Step 4: Install latest dspy-code (always upgrade to get newest features!)

pip install --upgrade dspy-code

๐ŸŽฏ Step 5: Run dspy-code (everything stays in this directory!)

dspy-code

๐Ÿ’ก Pro Tip: Always use pip install --upgrade dspy-code to get the latest features, bug fixes, and improvements!

Why virtual environment IN your project directory?

  • ๐Ÿ”’ Security: All file scanning stays within your project directory
  • ๐Ÿ“ฆ Isolation: Your project dependencies are self-contained
  • ๐Ÿš€ Portability: Share your project by zipping the entire directory
  • ๐ŸŽฏ Simplicity: Everything in one place - no scattered files
  • ๐Ÿงน Clean: Delete the project folder to remove everything

Project Structure

When you follow this setup, your project will be fully self-contained:

my-dspy-project/          # Your CWD
โ”œโ”€โ”€ .venv/                # Virtual environment (packages installed here)
โ”œโ”€โ”€ .dspy_cache/          # DSPy's LLM response cache
โ”œโ”€โ”€ .dspy_code/           # dspy-code's internal data
โ”‚   โ”œโ”€โ”€ cache/            # RAG index cache
โ”‚   โ”œโ”€โ”€ sessions/         # Session state
โ”‚   โ”œโ”€โ”€ optimization/     # GEPA workflow data
โ”‚   โ””โ”€โ”€ history.txt       # Command history
โ”œโ”€โ”€ generated/            # Your generated code
โ”œโ”€โ”€ modules/              # Your modules
โ”œโ”€โ”€ signatures/           # Your signatures
โ””โ”€โ”€ dspy_config.yaml      # Your config

Everything in one directory! Delete the folder, and it's all gone. Zip it, and share with others.

Never run dspy-code from:

  • โŒ Your home directory (~/)
  • โŒ Desktop, Documents, Downloads, or Pictures folders
  • โŒ System directories
  • โŒ With a virtual environment outside your project

Never do this:

# โŒ DON'T: Virtual env outside project
cd ~/
python -m venv my_global_venv

# โŒ DON'T: System-wide installation
pip install dspy-code

Your First Program (5 minutes)

# From your project directory with activated venv:
dspy-code

# Initialize your project (creates config and scans your environment)
/init

# Connect to a model (example with Ollama)
/connect ollama llama3.1:8b

# Generate your first program using natural language
Create a sentiment analyzer that takes text and outputs positive or negative

# Save the generated code
/save sentiment.py

# Validate and run
/validate
/run

That's it! You just created, validated, and ran your first DSPy program. ๐ŸŽ‰

๐Ÿ“‹ Available Commands

DSPy Code is interactive-only - all commands are slash commands. Here are the main categories:

๐Ÿ Getting Started

  • /init - Initialize or scan your DSPy project
  • /intro - Show introduction and getting started guide
  • /help - Show all available commands
  • /exit - Exit the interactive session

๐Ÿค– Model Connection

  • /connect <provider> <model> - Connect to LLM (ollama, openai, anthropic, gemini)
  • /disconnect - Disconnect current model
  • /models - List available models
  • /status - Show current connection status

๐Ÿ’ป Code Generation & Management

  • /demo - Generate demo DSPy code
  • /save <filename> - Save generated code to file
  • /validate - Validate DSPy code
  • /run - Execute your DSPy program
  • /test - Run tests on your code

๐Ÿงฌ Optimization

  • /optimize - Start optimization workflow
  • /optimize-start - Begin GEPA optimization
  • /optimize-status - Check optimization progress
  • /optimize-cancel - Cancel running optimization
  • /optimize-resume - Resume paused optimization
  • /eval - Evaluate your DSPy program

๐Ÿ”— MCP Integration

  • /mcp-connect <server> - Connect to MCP server
  • /mcp-disconnect <server> - Disconnect MCP server
  • /mcp-servers - List configured MCP servers
  • /mcp-tools - Show available MCP tools
  • /mcp-call <tool> <args> - Call an MCP tool
  • /mcp-resources - List MCP resources
  • /mcp-read <resource> - Read MCP resource
  • /mcp-prompts - List MCP prompts
  • /mcp-prompt <name> - Get MCP prompt

๐Ÿ’พ Session Management

  • /sessions - List all saved sessions
  • /session <name> - Load or switch session

๐Ÿ“ฆ Export & Import

  • /export <path> - Export project as package
  • /import <path> - Import project package

๐Ÿ“š Reference & Examples

  • /reference <topic> - Get DSPy reference documentation
  • /examples - Show example DSPy programs
  • /predictors - Show available DSPy predictors
  • /adapters - Show DSPy adapters
  • /retrievers - Show DSPy retrievers
  • /async - Show async patterns
  • /streaming - Show streaming examples
  • /data - Show data handling examples
  • /explain <concept> - Explain DSPy concepts

๐Ÿ”ง Project Management

  • /project - Show project information
  • /refresh-index - Rebuild codebase index
  • /index-status - Show index status
  • /save-data - Save training/evaluation data

๐Ÿ—‚๏ธ History & Context

  • /history - Show conversation history
  • /clear - Clear current context

๐Ÿ’ก Primary Use Cases

1. ๐Ÿ—๏ธ Developing New DSPy Applications

Perfect for:

  • Building new AI applications from scratch
  • Prototyping ideas quickly
  • Learning DSPy fundamentals
dspy-code
/init
/connect ollama llama3.1:8b
Create a RAG system for document Q&A
/save rag_system.py
/validate

โœ… Complete project structure
โœ… Code generation with natural language
โœ… Validation & best practices
โœ… Ready to code in minutes

2. ๐Ÿงฌ Optimizing Existing DSPy Programs with GEPA

Perfect for:

  • Improving accuracy of existing programs
  • Automatic prompt engineering
  • Production optimization
dspy-code
/init
/data sentiment 20  # Generate training examples
/optimize my_program.py training_data.jsonl
/optimize-status
/eval

โœ… Real GEPA execution (not just code generation)
โœ… Automated metric functions
โœ… Progress tracking & resumption
โœ… Production-ready optimized code
โœ… Performance improvements documented

Real results: 75% โ†’ 92% accuracy automatically!

3. ๐Ÿ“š Learning DSPy (No Docs Required!)

Perfect for:

  • First time using DSPy
  • Understanding DSPy concepts
  • Exploring different patterns
dspy-code
/intro
/examples
/explain ChainOfThought
/predictors

Just ask questions in natural language - the CLI answers using YOUR installed DSPy version!

4. ๐Ÿ”— Using MCP for External Tools

Perfect for:

  • Connecting to external APIs and services
  • Building powerful, connected AI applications
dspy-code
/mcp-connect filesystem
/mcp-tools
/mcp-call read_file {"path": "data.json"}

๐Ÿ”Œ Model Connection

Connect to any LLM provider:

# Ollama (local, free)
/connect ollama llama3.1:8b

# OpenAI (example small model)
/connect openai gpt-5-nano

# Anthropic (paid key required)
/connect anthropic claude-3-5-sonnet-20241022

# Google Gemini (example model)
/connect gemini gemini-2.5-flash

๐Ÿ’ก Tip: These are just starting points. Check your provider docs for the latest models (for example gpt-4o / gptโ€‘5 family, Gemini 2.5, latest Claude Sonnet/Opus) and plug them into /connect.

๐Ÿงฌ GEPA Optimization

DSPy Code includes real GEPA (Genetic Pareto) optimization:

# Start optimization workflow
/optimize my_program.py training_data.jsonl

# Or use step-by-step optimization
/optimize-start my_program.py training_data.jsonl
/optimize-status
/optimize-resume

๐Ÿ“‹ Requirements

  • Python: 3.10 or higher
  • DSPy: 3.0.4 or higher (automatically installed)
  • Dependencies: All dependencies are automatically installed

๐Ÿ› ๏ธ Installation Options

From PyPI (Recommended)

โœจ Always install the latest version! โœจ

pip install --upgrade dspy-code

๐Ÿ’ก Why upgrade? We're actively developing and releasing new features, bug fixes, and improvements regularly. Always use --upgrade to get the best experience!

From Source

git clone https://github.com/SuperagenticAI/dspy-code.git
cd dspy-code
pip install -e .

With uv (Faster)

# Always get the latest version
uv pip install --upgrade dspy-code

๐Ÿ—๏ธ Architecture

DSPy Code is built with a modular architecture:

  • Commands - Interactive slash commands
  • Models - LLM connection and code generation
  • MCP - Model Context Protocol client
  • Optimization - GEPA workflow management
  • Validation - Code quality and best practices
  • RAG - Codebase indexing and search
  • Execution - Sandboxed code execution
  • Session - State management
  • Export - Project packaging

๐Ÿ“š Documentation

Full documentation available at: https://superagenticai.github.io/dspy-code/

Quick Links

๐Ÿค Contributing

Contributions are welcome! We follow modern Python best practices:

  • Code Quality: Ruff for linting and formatting
  • Testing: pytest with coverage
  • CI/CD: GitHub Actions
  • Pre-commit: Automated quality checks

See CONTRIBUTING.md for detailed guidelines.

Quick Development Setup

git clone https://github.com/SuperagenticAI/dspy-code.git
cd dspy-code

# Using uv (recommended)
uv venv
source .venv/bin/activate  # For fish: source .venv/bin/activate.fish
uv pip install -e ".[dev,test,docs]"
pre-commit install

# Or using pip
python -m venv .venv
source .venv/bin/activate  # For fish: source .venv/bin/activate.fish
pip install -e ".[dev,test,docs]"
pre-commit install

# Run tests
pytest

# Run linting
ruff check .

# Format code
ruff format .

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

โš ๏ธ Development Status

DSPy Code is currently in Beta and under active development. While it's functional and ready for experimentation, it's not yet production-ready. We're actively adding features to make it production-worthy so you can use it in real projects to enhance your workflow.

We'd love your feedback! Try it out, share your experience, and help us shape the future of DSPy development:

๐Ÿ™ Acknowledgments

Brought to you by Superagentic AI

Special thanks to the DSPy community and all contributors!


๐Ÿ“š Resources

๐Ÿ“– Documentation โ€ข ๐Ÿ› Issues โ€ข ๐Ÿค Contributing


โญ Show Your Support

If DSPy Code helps your workflow, give us a star! โญ

It helps others discover the project and motivates us to keep improving it.


DSPy Code

Made for the DSPy community

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_code-0.0.5.tar.gz (297.7 kB view details)

Uploaded Source

Built Distribution

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

dspy_code-0.0.5-py3-none-any.whl (325.0 kB view details)

Uploaded Python 3

File details

Details for the file dspy_code-0.0.5.tar.gz.

File metadata

  • Download URL: dspy_code-0.0.5.tar.gz
  • Upload date:
  • Size: 297.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.7

File hashes

Hashes for dspy_code-0.0.5.tar.gz
Algorithm Hash digest
SHA256 f00016383d0323a3d714f0923145fe1745763eb70a16c3095c9618b12f881621
MD5 0367b6d5281493b47b9a4c68b61392a8
BLAKE2b-256 98548d8cd3a8f43b6a3bbb99638824555020c01deefe78e285b9f06ec10ad8a8

See more details on using hashes here.

File details

Details for the file dspy_code-0.0.5-py3-none-any.whl.

File metadata

  • Download URL: dspy_code-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 325.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.7

File hashes

Hashes for dspy_code-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 e5ad0baf9787a5329204b27e1fa209188596766e5ddeaa6bfacb6ef822a13f81
MD5 57c30382d01e6db48896b17a6e1aa282
BLAKE2b-256 60a40016083edffe2e58d0f75892f9d5d982d8a2eafc35bfc7ea5f40ac0b644a

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