dspy
DSPy
What it is and what it does
DSPy is a framework for composing language model systems as Python code rather than writing and tweaking prompts manually. It treats language model calls as declarative building blocks that can be combined into modular pipelines—from simple classifiers to complex retrieval-augmented generation (RAG) systems and agent loops. The core innovation is that DSPy includes algorithms to automatically optimize both the prompts and weights of these systems, teaching models to produce higher-quality outputs without hand-crafting every prompt.
The framework depends on a suite of utilities: openai and litellm for LLM access, pydantic for data validation, requests and anyio for HTTP operations, tenacity for retry logic, diskcache for caching, and several text-processing libraries (regex, orjson, json-repair) for robustness. It's actively maintained and has substantial adoption, with no known security vulnerabilities.
Use it for:
- Build modular RAG pipelines where retrieval and generation steps are composed as Python functions and automatically optimized.
- Create multi-stage language model programs where prompts and in-context examples are learned from data rather than hand-written.
- Develop agent loops with self-refining constraints that enforce output quality and correctness.
- Optimize classifier systems by letting DSPy tune prompts and demonstrations for your specific task and data.
- Experiment rapidly with different LLM architectures and providers without rewriting prompt logic.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
DSPy is a framework for building and optimizing modular language model systems through Python code rather than manual prompt engineering, with built-in algorithms for teaching models to produce high-quality outputs.
Yes. DSPy is actively maintained, has no security vulnerabilities, uses a permissive MIT license, and offers low install friction. It's well-suited for teams building production language model systems who want to move beyond manual prompt engineering. Start with it if you're composing multiple LLM calls into a pipeline or need systematic prompt optimization; skip it if you're only making single, one-off LLM requests.
Install
dspy on PyPI
pip
pip install dspyuv
uv add dspypoetry
poetry add dspyInstalling dspy
Before you install
Low install friction with a pure Python wheel. Active maintenance with a recent release and strong community signal (37189 GitHub stars). Requires Python 3.10 or later but supports current versions.
License in practice
MIT License permits free use, modification, and distribution with minimal restrictions, making it suitable for both open-source and commercial projects.
Quickstart
pip install dspy
import dspy
# Create a simple DSPy module
class SimpleQA(dspy.ChainOfThought):
pass
qa = SimpleQA()
Requires Python 3.10 or later. Most functionality depends on configuring an LLM provider (e.g., via openai or litellm dependencies).
Verify before relying
- Whether the framework's optimization algorithms work equally well across different LLM providers or have provider-specific limitations.
- Performance characteristics and scalability limits for large-scale RAG pipelines or agent loops.
- Compatibility and integration details with specific retrieval backends or vector stores.
Package facts
| License | MIT License Copyright (c) 2023 Stanford Future Data Systems Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the… (full text in the JSON record) (permissive) |
| Python support | supports the current Python release (<3.15,>=3.10) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 14 — openai, regex, orjson, tqdm, requests, pydantic, litellm, diskcache, json-repair, tenacity, anyio, cachetools, cloudpickle, gepa |
| Maintenance | actively maintained — 11 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 6,445,272/month — #1,909 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: dspy-3.3.0-py3-none-any.whl
Tags
More Artificial Intelligence packages
LiteLLM provides a unified Python interface to…
permissive · top 100 on PyPI
huggingface-hubClient library and CLI tool for downloading,…
permissive · top 100 on PyPI
langchainLangChain provides a framework for building…
permissive · top 1,000 on PyPI
hf-xethf-xet provides chunk-based deduplication and…
permissive · top 1,000 on PyPI
tokenizersTokenizers converts raw text into token…
permissive · top 1,000 on PyPI
transformersTransformers provides a unified framework for…
permissive · top 1,000 on PyPI
dspy-aiDSPy is a framework for building and optimizing…
permissive · top 5,000 on PyPI
ell-aiell-ai is a functional prompt engineering…
permissive · top 15,000 on PyPI
TTSTTS is a deep learning library for…
copyleft · top 15,000 on PyPI
gepaGEPA optimizes textual system…
permissive · top 5,000 on PyPI
google-tunixTunix is a JAX-based library for post-training…
permissive · top 15,000 on PyPI
modelscopeModelScope provides unified Python interfaces…
permissive · top 5,000 on PyPI
openinference-instrumentation-dspyAuto-instruments DSPy applications to generate…
permissive · top 15,000 on PyPI
autogluon.tabularAutomates machine learning model training and…
permissive · top 15,000 on PyPI
autogluonAutoGluon automates machine learning model…
permissive · top 15,000 on PyPI
adam-atan2-pytorchProvides an Adam optimizer variant using atan2…
permissive · top 15,000 on PyPI