Django AI SDK
A Django SDK for building AI-powered applications with support for multiple LLM providers, RAG (Retrieval-Augmented Generation), and streaming responses.
Project Status: Read This First
This is an early preview. We're actively iterating on the API and learning from real usage. Here's what that means for you:
- Expect breaking changes: APIs will shift as we find better patterns.
- Migrations might be reset: Don't rely on database schema stability between versions.
- Not for production: Use this for experimentation, prototypes, and side projects. Keep critical workloads elsewhere.
- Watch the repo: Things change quickly. Star & watch to stay in the loop.
- Your feedback shapes the SDK: Break things, open issues, tell us what hurts.
We'd love to have you along for the ride, just keep your seatbelt on.
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.conf import settings
from django_ai_sdk import Agent
from django_ai_sdk.adapters.base import Stream
from haystack import Pipeline
from haystack.components.generators.chat import OpenAIChatGenerator
from haystack.utils import Secret
class HelpDeskAgent(Agent):
name = "Help Desk"
model = "gpt-4o"
instructions = "You are a helpful support agent."
async def get_pipeline_adapter(self, thread_id=None, user=None):
storage_adapter = await self.get_storage_adapter(thread_id)
generator = OpenAIChatGenerator(
model=self.get_model(),
api_key=Secret.from_token(settings.OPENAI_API_KEY),
)
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):
generator = OpenAIChatGenerator(
model=self.get_model(),
api_key=Secret.from_token(settings.OPENAI_API_KEY),
)
return Run(generator=generator)
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,
)
Integrations
An integration gives an agent tools from a third party: an MCP server, or an API
you wrap yourself. Each one is a small Django app that registers itself on ready().
Enable a shipped integration by installing its app and naming it on an agent:
# settings.py
INSTALLED_APPS = [
"django_ai_sdk",
"django_ai_sdk.integrations.mcp", # required by any MCP-backed integration
"django_ai_sdk.integrations.github", # also: .linear, .notion, .weather
]
# INSTALLED_APPS decides which integrations exist; this configures them. The same
# shape as DATABASES or CACHES, keyed by integration name.
AI_SDK_INTEGRATIONS = {
"github": {"TOKEN": env("GITHUB_MCP_TOKEN")},
}
class HelpDeskAgent(Agent):
integrations = ["github"]
A missing credential never breaks boot: the integration reports that it needs setup
and contributes no tools. Alongside secrets, each entry accepts URL, TOOLS,
LABEL, SCOPE and AUTH, so a self-hosted server, a narrower tool allow-list, or
per-user OAuth instead of a shared token is a settings change rather than a subclass.
It's an ordinary dict, so pulling values from a vault or an ini file needs no hook. Just call whatever you like inside it.
Adding your own
Three files, no models and no migrations:
# myapp/integrations/zendesk/apps.py
from django_ai_sdk.integrations import IntegrationAppConfig
class ZendeskConfig(IntegrationAppConfig):
default = True # Django needs this to pick your AppConfig over the base
name = "myapp.integrations.zendesk"
integration = "myapp.integrations.zendesk.integration.ZendeskIntegration"
# myapp/integrations/zendesk/integration.py
from django_ai_sdk.integrations import MCPIntegration
class ZendeskIntegration(MCPIntegration):
name = "zendesk" # registry key, and the AI_SDK_INTEGRATIONS key
label = "Zendesk"
url = "https://mcp.zendesk.example/mcp"
auth = "token" # "static" | "token" | "oauth"
default_tools = [] # [] discovers every tool the server offers
Add "myapp.integrations.zendesk" to INSTALLED_APPS, add
"zendesk": {"TOKEN": env("ZENDESK_API_TOKEN")} to AI_SDK_INTEGRATIONS,
and list "zendesk" on an agent. For an API you wrap by hand, subclass
APIIntegration and set tools to @haystack.tools.tool-decorated functions.
django_ai_sdk/integrations/weather/ is a complete, credential-free example, and
github/, linear/ and notion/ cover token and OAuth MCP servers.
Tools are namespaced per integration (zendesk_search_tickets), so two servers
exposing the same tool name don't collide. Tool lists are cached
stale-while-revalidate behind a per-integration circuit breaker, so a slow or dead
server costs one bounded wait and then reports itself as degraded.
HTTP endpoints
The SDK ships no integrations router; it doesn't pick your web framework. Build
list/connect/disconnect/reconnect over IntegrationService
(demo/apps/integrations/views/ninja.py is a working reference), and include
the OAuth callback, which must sit at a fixed URL:
(path("api/integrations/", include("django_ai_sdk.integrations.mcp.urls")),)
Features
- RAG Pipelines: BM25, ChromaDB, and Qdrant hybrid search with query expansion.
- Streaming Responses: Built-in SSE streaming. Works with Vercel AI SDK protocol.
- Conversation Storage: Automatic message persistence. Thread-based history out of the box.
- Tool Calling: MCP, memory, and custom tools, all managed by your Agent.
- Artifacts: 16 structured UI types (tables, plans, approval cards, code blocks, and more) submitted by the LLM via tool calls.
- File Processing: Document upload with pipeline-based processing (text, CSV, JSON, DOCX, PPTX, XLSX. Extraction transforms for metadata embedding.
- Integrations: Third-party tools as self-registering Django apps, with caching, circuit breaking and OAuth built in. See Integrations.
- Reindexing: Hot-reload documents. Cached embeddings with simple refresh API.
Documentation
Full documentation and examples: github.com/django-ai-sdk/django-ai-sdk
Metadata
Release files for django-ai-sdk 0.1.1
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.1.tar.gz | 160.6 kB | Without provenance | Details for django_ai_sdk-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| django_ai_sdk-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for django_ai_sdk-0.1.1-py3-none-any.whl |
Total release size: 363.4 kB
Release files / django_ai_sdk-0.1.1.tar.gz
| Download URL | django_ai_sdk-0.1.1.tar.gz |
|---|---|
| Size | 160.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d8efc3c68cd2a5faaf2d8d18a16300278f113cbfb4e1892296ebeae94138e247
|
|
BLAKE2b-256 checksum How to use checksums |
055cfb71b376157476d45a15e1d19d8b7a4f1e4fbe0af913b463473aa55ba649
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.2 {"installer":{"name":"uv","version":"0.11.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / django_ai_sdk-0.1.1-py3-none-any.whl
| Download URL | django_ai_sdk-0.1.1-py3-none-any.whl |
|---|---|
| Size | 202.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
635bb0c5a1c719fca95332db30dc9a2c3779b96dc99361eb7b4a51eb024f6bd9
|
|
BLAKE2b-256 checksum How to use checksums |
682b10017294380ee0869570ac57c087b22ce9c7b03c461ff5d71395e8cacda3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.2 {"installer":{"name":"uv","version":"0.11.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for django-ai-sdk 0.1.1
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A 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.