This release is a pre-release and may not be stable for production use.
pip install django-pydantic-ai Copy PIP instructions
Use Django as a persistent backend for Pydantic AI agent memory. The package provides an asynchronous memory store for Pydantic AI Harness, backed by Django models and your configured database.
pip install django-pydantic-ai The package depends on Pydantic AI and Pydantic AI Harness; pip installs them along with Django.
INSTALLED_APPS = [ # Your other Django apps... "django_pydantic_ai.memory", ] Configure a database as usual, then create the memory tables:
python manage.py migrate Use With An Agent Create a Directory for each isolation boundary you need, such as a user, tenant, or agent. A DjangoModelStore is bound to one directory. The following async factory creates or retrieves that directory and attaches its store to the Harness Memory capability:
from pydantic_ai import Agent from pydantic_ai_harness.memory import Memory from django_pydantic_ai.memory.models import Directory from django_pydantic_ai.memory.store import DjangoModelStore async def create_agent(model: str, user_id: int) -> Agent: directory, _ = await Directory.objects.aget_or_create(name=f"user:{user_id}") store = DjangoModelStore(directory) return Agent(model, capabilities=[Memory(store=store)]) Use the resulting agent through Pydantic AI's async API:
agent = await create_agent("your-model", user_id=42) result = await agent.run("Remember that my preferred language is Portuguese.") The Memory capability injects the main memory notebook into agent context and provides tools for writing, reading, deleting, and searching memory files. Its default in-memory store is process-local; pass DjangoModelStore to persist data in Django's database across runs.
hatch run pytest License django-pydantic-ai is distributed under the terms of the MIT license.
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
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 verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 12, 2026.




