SDK for integrating LLMs as Python functions using decorators
Top 19.9% on sourcepulse
Magentic is a Python library designed to seamlessly integrate Large Language Models (LLMs) as callable Python functions. It targets developers building agentic systems, offering structured outputs, streaming, and LLM-assisted retries for enhanced reliability.
How It Works
Magentic uses decorators like @prompt
and @chatprompt
to define LLM interactions. These decorators transform Python functions into LLM calls, automatically handling prompt templating, argument injection, and response parsing. It supports structured outputs via Pydantic models and integrates with various LLM providers (OpenAI, Anthropic, Ollama) through pluggable backends. The library also facilitates function calling and chaining, enabling complex agentic workflows.
Quick Start & Requirements
pip install magentic
or uv add magentic
.OPENAI_API_KEY
environment variable).Highlighted Details
Maintenance & Community
Licensing & Compatibility
Limitations & Caveats
# type: ignore
comments.1 month ago
1 day