Django AI SDK
Build AI agents in Django. Batteries included.
Project status: read this first
This is a beta. Here's what that means for you:
- Watch the repo. Releases come often. Star and watch it to see them.
- Your feedback shapes the SDK. Break things, open issues and tell us what hurts.
Install
pip install django-ai-sdk
Or with uv:
uv add django-ai-sdk
Quick start
1. Add to INSTALLED_APPS
# settings.py
INSTALLED_APPS = [
...
"django_ai_sdk",
]
Then run python manage.py migrate.
2. Define your agent
# agents.py
from django_ai_sdk import Agent
from django_ai_sdk.adapters.base import Stream
from django_ai_sdk.generators import openai_responses_chat
from haystack import Pipeline
class HelpDeskAgent(Agent):
name = "Help Desk"
model = "gpt-5-mini"
instructions = "You are a helpful support agent."
llm = openai_responses_chat
async def get_pipeline_adapter(self, thread_id=None, user=None):
storage_adapter = await self.get_storage_adapter(thread_id)
generator = self.get_llm()
return Stream(
pipeline=Pipeline(),
generator=generator,
storage_adapter=storage_adapter,
)
For non-streaming tasks (title generation, structured output), use Run instead:
from django_ai_sdk.adapters.base import Run
async def get_run_adapter(self, thread_id=None, user=None):
return Run(generator=self.get_llm())
3. Return a streaming response
# views.py
from .agents import HelpDeskAgent
agent = HelpDeskAgent()
@router.post("/chat")
async def chat(request, payload: ChatRequest):
return await agent.as_view(
payload.messages,
thread_id=payload.thread_id,
)
Oversight
Block prompt injection, mask personal data and send risky turns to a person, from one
Python class. Add "django_ai_sdk.oversight" to INSTALLED_APPS and run migrate.
from django_ai_sdk import Agent
from django_ai_sdk.errors import Blocked
from django_ai_sdk.oversight import L, Policy, Queue, Rule, register_policy
@register_policy
class Guard(Policy):
name = "guard"
extends = ["security.injection"] # the pack's injection lens and its blocking rule
rule_mode = "enforce" # rules start in report mode; this makes them act
rules = [
Rule("injection_to_people", when=L("injection_question").is_true, then=Queue("security")),
]
class SupportAgent(Agent):
oversight = Guard
try:
answer = await SupportAgent().run(messages, user=request.user)
except Blocked as blocked:
answer = blocked.message # the policy's own text for the person asking
See the Oversight guide for the rest, and its limitations.
Features
- Agents: A Django
Agentclass you can run from a view, a task, or the API, streaming or not, with tool calling built in. - Workflows: Multi-step, definition-driven runs with persisted steps and run listeners,
so a process can span multiple agent calls with a record of what happened. Runs are
durable on DBOS (
django-ai-sdk[dbos], oneai_sdk_worker): they survive restarts, wait days for an approval, and start from cron or webhook triggers. - Subagents: Agents can delegate to other agents as tools, so one agent can orchestrate specialists instead of doing everything itself.
- Tool calling: MCP, memory and your own functions as tools, declared on the agent.
- Streaming responses: SSE streaming that speaks the Vercel AI SDK protocol.
- Conversation storage: Every message is stored in its thread, with no code of your own.
- RAG pipelines: BM25, ChromaDB and Qdrant hybrid search with query expansion, so an agent can answer from your documents.
- Artifacts: 16 structured UI types, such as tables, plans, approval cards and code blocks, that the model submits through tool calls.
- File processing: Uploads of text, CSV, JSON, DOCX, PPTX and XLSX run through a processing pipeline. Extraction transforms add metadata to the embeddings.
- Integrations: Third-party tools as self-registering Django apps, with caching, circuit breaking and OAuth built in.
- Tracing: Opt-in Haystack tracing persisted to the ORM, with per-thread and per-message token accounting.
- Oversight: A lens asks one typed question about every turn. Code, a classifier or a model judge answers it, as you pick per lens. Rules block, mask or queue the turn for a person, and start in report mode. Every turn of an agent with a policy is checked and recorded, masked by default.
- Reindexing: Rebuild a memory's index on demand, from code, an endpoint or the
reindex_memoriescommand, without a restart.
Demo project
Studio is the demo project. It holds a Django app that uses the SDK's features: chat agents, swarms, deep research, memories, workflows with a worker, oversight, MCP integrations and both the django-ninja and DRF APIs. It also has native clients for macOS, iPhone and iPad.
Documentation
The full documentation is at django-ai-sdk.github.io/django-ai-sdk/docs.
Is it any good?
License
Metadata
Release files for django-ai-sdk 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| django_ai_sdk-0.1.2.tar.gz | 354.2 kB | With provenance | Details for django_ai_sdk-0.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| django_ai_sdk-0.1.2-py3-none-any.whl | Python 3 | none | any | Details for django_ai_sdk-0.1.2-py3-none-any.whl |
Total release size: 819.8 kB
Release files / django_ai_sdk-0.1.2.tar.gz
| Download URL | django_ai_sdk-0.1.2.tar.gz |
|---|---|
| Size | 354.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6923334057155e87be3ece48af3dbc6684b15d3f317d8f92b3d50e5b5189e51e
|
|
BLAKE2b-256 checksum How to use checksums |
242a101abe3c314cacb19440a8f46d415c59a268ce9268ce8a78c882550ea3a4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 1, 2026.
Transparency logRelease files / django_ai_sdk-0.1.2-py3-none-any.whl
| Download URL | django_ai_sdk-0.1.2-py3-none-any.whl |
|---|---|
| Size | 465.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7061946deb64ff73b66b652d12a3b912a5ad8469d9168cdfd4c637a26c761a20
|
|
BLAKE2b-256 checksum How to use checksums |
ad1992e3db5bc222b50c774f085662c74e3671b8c63a37b236357262ca4dd571
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 1, 2026.
Transparency logSecurity for django-ai-sdk 0.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for django_ai_sdk-0.1.2.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 1, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.