Skip to content

DSPy

A Python framework for building and optimizing language model programs instead of hand-writing prompts.

Stars
38.9k
Forks
3.5k
Licence
MIT
Language
Python
Last update
4 days ago
Type
Library

What it is

DSPy is a Python framework for building AI systems out of modular code rather than long hand-written prompts. You describe what each step should do in Python, and DSPy provides algorithms to optimize the prompts and model weights behind those steps. The README says it is used for simple classifiers, RAG pipelines, and agent loops.

  • Build a text classifier as a composed Python program instead of a single prompt
  • Assemble a retrieval-augmented generation (RAG) pipeline from modular steps
  • Build an agent loop with DSPy modules
  • Optimize prompts and demonstrations for a multi-stage LM program using the included optimizers

Great for

  • Python developers building LM-based pipelines such as RAG or multi-step agents
  • Teams that want to improve prompts with measurable optimization instead of manual tweaking
  • Researchers experimenting with prompt and weight optimization methods
  • People who already have a way to measure output quality and want to tune against it

Not ideal for

  • People who only need a one-off chat prompt; the framework adds structure that is unnecessary for simple use
  • Non-Python users, since the README only shows Python code and pip installation
  • Anyone wanting a no-code tool; the README describes a programming framework
Step-by-step guide: how to use DSPyInstall, first run, examples, tips and FAQs

How to get it

  1. 1

    Install with a package manager

    You'll need: Python

    Install from PyPI

    pip install dspy
  2. 2

    Run it

    • Install the package with pip install dspy
    • Read the DSPy Docs at dspy.ai for a first program
    • Configure a language model provider as described in the docs
    • Write a small DSPy module and run it on a few examples
  3. 3

    Get the most out of it

    • Read the LM migration guide linked in the README if you use custom LMs or embeddings
    • Use the optimization algorithms once you have an evaluation set to score outputs
    • Follow the official docs at dspy.ai for tutorials on modules and optimizers
    • Join the Discord server linked in the README for community help

Downloads

Strengths

  • Declarative Python code instead of brittle, hand-written prompt strings
  • Includes optimization algorithms for prompts and weights, backed by published research
  • Permissive MIT license with a large community (about 38.8k GitHub stars)

Trade-offs

  • The README points to external docs for most details, so the top-level README gives limited hands-on guidance
  • The README notes a recent LM integration change with breaking changes to provider options, so check the migration guide before upgrading
  • Optimization benefits depend on having a sensible evaluation metric, which the README does not explain in detail

How it compares

ProjectStarsTypeLevelUpdatedBest for
dspy (this)38.9kLibraryintermediate4 days agoPython developers building LM-based pipelines such as RAG or multi-step agents
langchain149kFrameworkintermediate4 days agoPython developers building LLM-powered applications
llama_index52.8kLibraryintermediate10 days agoPython developers building retrieval-augmented generation (RAG) apps over private documents
guidance21.8kLibraryintermediate6 months agoPython developers who need model output in a predictable format, such as JSON-like or fixed-choice answers

Stats synced from GitHub. The assessment above was drafted with AI from the project's README on 2026-10-29 and may miss recent changes — check the README before relying on a command. MIT licence: free to use, modify and distribute, including commercially, as long as you keep the copyright notice.