A Python framework for building LLM-powered applications and agents, with standard interfaces for models, embeddings, vector stores and third-party integrations.
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
Install DSPy from PyPI
pip install dspy - 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
A Python framework for building RAG, agent and document-processing applications that connect LLMs to your own data.
A visual platform for building, testing and deploying AI agents and workflows, with built-in API and MCP server exposure.
A memory layer for AI agents and apps that stores and retrieves user, session, and agent context across conversations.
A lightweight Python framework for building multi-agent workflows with tools, handoffs, guardrails, sessions and tracing, provider-agnostic across OpenAI and 100+ LLMs.
Open-source Python framework for building production-ready LLM applications with modular pipelines and agent workflows for RAG, search and agents.