Repolode
stanfordnlp

stanfordnlp/dspy

A Python framework for programming language models with modular code and algorithms that optimize prompts and weights, instead of hand-writing prompts.

Stars
38,705
Forks
3,437
Open issues
814
Last commit
15 hours ago

What is it?

DSPy is a Python framework for building AI systems by writing compositional code rather than hand-crafted prompts. You declare the inputs and outputs of each language model call as modules, then compose them into pipelines for tasks such as classifiers, retrieval-augmented generation (RAG) pipelines, or agent loops.

On top of this programming model, DSPy provides optimizers that tune the prompts and, where applicable, the weights of a program against a metric you define. The goal is to make LM output quality a property you can improve systematically, instead of something adjusted by trial and error on prompt text. The project is installed with pip and documented at dspy.ai.

Key features

  • 01Declare LM calls as Python modules and compose them into programs.
  • 02Optimize prompts and instructions against a user-defined metric.
  • 03Supports building RAG pipelines and agent loops.
  • 04Installable via pip, with the latest main branch available from GitHub.

Use cases

  • Building text classifiers that are improved from labeled examples.
  • Creating retrieval-augmented question answering pipelines.
  • Replacing hand-maintained prompt strings with versioned, testable Python code.

Quick start

  1. 1

    Install DSPy from PyPI

    pip install dspy
  2. 2

    Read the documentation at dspy.ai to get started

Things to know

  • The README points to external docs for usage, so the quick start here is minimal.

Topics

FAQ

What is dspy?
A Python framework for programming language models with modular code and algorithms that optimize prompts and weights, instead of hand-writing prompts. DSPy is a Python framework for building AI systems by writing compositional code rather than hand-crafted prompts. You declare the inputs and outputs of each language model call as modules, then compose them into pipelines for tasks such as classifiers, retrieval-augmented generation (RAG) pipelines, or agent loops.
Is dspy free to use? What license does it have?
dspy is open source under the MIT license. Check the license terms before using it in commercial products.
Is dspy still maintained?
Actively maintained. The last commit to dspy was on Oct 19, 2026.
What can I use dspy for?
Building text classifiers that are improved from labeled examples. Creating retrieval-augmented question answering pipelines. Replacing hand-maintained prompt strings with versioned, testable Python code.
How do I install dspy?
Install DSPy from PyPI: pip install dspy Read the documentation at dspy.ai to get started
Where can I get dspy?
The source code and installation instructions are on GitHub: https://github.com/stanfordnlp/dspy

Summary generated by AI from the project's README. GitHub stats refresh daily.

Related projects