dspy README

The project's README from github.com/stanfordnlp/dspy. As one markdown file: README.md.

DSPy: Programming—not prompting—Foundation Models

Documentation: DSPy Docs

PyPI Downloads


DSPy is the framework for programming—rather than prompting—language models. It allows you to iterate fast on building modular AI systems and offers algorithms for optimizing their prompts and weights, whether you're building simple classifiers, sophisticated RAG pipelines, or Agent loops.

DSPy stands for Declarative Self-improving Python. Instead of brittle prompts, you write compositional Python code and use DSPy to teach your LM to deliver high-quality outputs. Learn more via our official documentation site or meet the community, seek help, or start contributing via this GitHub repo and our Discord server.

Documentation: dspy.ai

Please go to the DSPy Docs at dspy.ai

Installation

pip install dspy

To install the very latest from main:

pip install git+https://github.com/stanfordnlp/dspy.git

📜 Citation & Reading More

If you're looking to understand the framework, please go to the DSPy Docs at dspy.ai.

If you're looking to understand the underlying research, this is a set of our papers:

[Jul'25] GEPA: Reflective Prompt Evolution Can Outperform Reinforcement Learning
[Jun'24] Optimizing Instructions and Demonstrations for Multi-Stage Language Model Programs
[Oct'23] DSPy: Compiling Declarative Language Model Calls into Self-Improving Pipelines
[Jul'24] Fine-Tuning and Prompt Optimization: Two Great Steps that Work Better Together
[Jun'24] Prompts as Auto-Optimized Training Hyperparameters
[Feb'24] Assisting in Writing Wikipedia-like Articles From Scratch with Large Language Models
[Jan'24] In-Context Learning for Extreme Multi-Label Classification
[Dec'23] DSPy Assertions: Computational Constraints for Self-Refining Language Model Pipelines
[Dec'22] Demonstrate-Search-Predict: Composing Retrieval & Language Models for Knowledge-Intensive NLP

To stay up to date or learn more, follow @DSPyOSS on Twitter or the DSPy page on LinkedIn.

The DSPy logo is designed by Chuyi Zhang.

If you use DSPy or DSP in a research paper, please cite our work as follows:

@inproceedings{khattab2024dspy,
  title={DSPy: Compiling Declarative Language Model Calls into Self-Improving Pipelines},
  author={Khattab, Omar and Singhvi, Arnav and Maheshwari, Paridhi and Zhang, Zhiyuan and Santhanam, Keshav and Vardhamanan, Sri and Haq, Saiful and Sharma, Ashutosh and Joshi, Thomas T. and Moazam, Hanna and Miller, Heather and Zaharia, Matei and Potts, Christopher},
  journal={The Twelfth International Conference on Learning Representations},
  year={2024}
}
@article{khattab2022demonstrate,
  title={Demonstrate-Search-Predict: Composing Retrieval and Language Models for Knowledge-Intensive {NLP}},
  author={Khattab, Omar and Santhanam, Keshav and Li, Xiang Lisa and Hall, David and Liang, Percy and Potts, Christopher and Zaharia, Matei},
  journal={arXiv preprint arXiv:2212.14024},
  year={2022}
}

dspy (stanfordnlp/dspy)

Searching Database…

38.7K ·GitHub
这是什么?DSPy 是一个 Python 框架,用来用编程的方式——而不是靠写提示词——来驾驭语言模型:你用代码搭建模块化的 AI 系统,它的算法会自动优化提示词和模型权重。
这和我自己手写提示词有什么不同?你不用再去反复调那些脆弱的提示词字符串,而是写可组合的 Python 代码,DSPy 会借助这些代码教语言模型输出高质量的结果。
适合谁用?我需要是机器学习研究人员吗?适合用 Python 构建语言模型系统的开发者,从简单的分类器到复杂的 RAG 流水线和智能体循环都可以。研究人员也是它的核心用户——这个框架是伴随一系列论文一起推出的。
我可以用它做什么?作者提到的例子包括简单的分类器、复杂的 RAG 流水线和智能体循环——基本上任何调用语言模型的模块化系统都行。
DSPy 这个名字是什么意思?Declarative Self-improving Python(声明式自我改进的 Python):你用 Python 代码声明你的系统,框架的优化器会自动改进它的提示词和权重。
它背后有发表的研究吗?有——一系列论文,从前身的 DSP(Demonstrate-Search-Predict,2022 年 12 月),到最初的 DSPy 论文(2023 年 10 月),再到 GEPA(2025 年 7 月),后者提出的反思式提示词进化方法的效果超过了强化学习。
Size
183.4 MB
Stars
38.7K
Age
3y
Commits · 90 Days