Skip to main content

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

Project description

DSPy Code

Claude Code for DSPy: AI-Powered Interactive Development Environment for DSPy

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

An interactive CLI tool for building, optimizing, and deploying DSPy applications

๐Ÿ“– Documentation


โœจ What is DSPy Code?

DSPy Code is an interactive development environment that transforms how you learn and build with DSPy. Built as an intelligent CLI tool, it provides natural language interactions, code generation, optimization workflows, and comprehensive validation, all designed specifically for DSPy development.

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.

๐ŸŽฏ 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.

๐ŸŽฏ Key Features

  • ๐Ÿ—ฃ๏ธ Natural Language Interface - Describe your DSPy task in plain English
  • ๐Ÿ”— Built-in MCP Client - Connect to any MCP server for external tools and services
  • ๐Ÿง  Version-Aware Intelligence - Adapts to your installed DSPy version
  • ๐Ÿงฌ GEPA Optimization - Real Genetic Prompt Evolution Algorithm integration
  • ๐Ÿ“š Codebase RAG - Understands your project with intelligent indexing
  • โœ… Smart Validation - Ensures code follows DSPy best practices
  • ๐Ÿš€ Code Generation - Generate signatures, modules, and complete programs
  • ๐Ÿ’พ Session Management - Save and resume your work across sessions
  • ๐Ÿ“ฆ Export/Import - Package and share your DSPy projects

๐Ÿš€ Quick Start

Installation

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

# 1. Create a project directory
mkdir my-dspy-project
cd my-dspy-project

# 2. Create virtual environment IN this directory (not elsewhere!)
python -m venv .venv

# 3. Activate it
source .venv/bin/activate  # On Windows: .venv\Scripts\activate

# 4. Install dspy-code (installs into .venv/ in your project)
pip install dspy-code

# 5. Run dspy-code (everything stays in this directory!)
dspy-code

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

๐Ÿ’ก Use Cases

๐Ÿ†• Starting a New DSPy Project

dspy-code
/init
/connect ollama llama3.1:8b
Create a RAG system for document Q&A
/save rag_system.py

๐Ÿ”ง Optimizing Existing Code

dspy-code
/init
/optimize-start my_module.py training_data.jsonl
/optimize-status

๐Ÿ”— Using MCP for External Tools

dspy-code
/mcp-connect filesystem
/mcp-tools
/mcp-call read_file {"path": "data.json"}

๐Ÿ“– Learning DSPy

dspy-code
/intro
/examples
/explain ChainOfThought
/predictors

๐Ÿ”Œ Model Connection

Connect to any LLM provider:

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

# OpenAI
/connect openai gpt-4

# Anthropic
/connect anthropic claude-3-5-sonnet-20241022

# Google Gemini
/connect gemini gemini-2.0-flash-exp

๐Ÿงฌ GEPA Optimization

DSPy Code includes real Genetic Prompt Evolution Algorithm 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)

pip install dspy-code

From Source

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

With uv (Faster)

uv pip install 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
uv pip install -e ".[dev,test,docs]"
pre-commit install

# Or using pip
python -m venv .venv
source .venv/bin/activate
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

Built with โค๏ธ by Superagentic AI

Special thanks to the DSPy community and all contributors!


๐Ÿ“– Full Documentation

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.2.tar.gz (296.5 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.2-py3-none-any.whl (321.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: dspy_code-0.0.2.tar.gz
  • Upload date:
  • Size: 296.5 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.2.tar.gz
Algorithm Hash digest
SHA256 59fce419ff65c8c9da620a38d4236f9c2d8bb947ae1de8112da7f81c3c5a7711
MD5 6b2e4cd240da17d8b48a7c65ee0412ec
BLAKE2b-256 88ec1b6f0022cf382cef246836882a235ac27d584594436673ebd167fb1c088a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: dspy_code-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 321.6 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 a77b07e33c5767169c1ca68bbb2f1d1347cae28bb096c680669fa230a3ef0159
MD5 3f1c175de21d4fe69967533600e37442
BLAKE2b-256 7fb86d497c901e677e6d415e083fd8da658de52410370cf37c35eea1d7562aa3

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