Expose djangorestframework-services services and selectors as a Pydantic-AI toolset.
Project description
djangorestframework-pydantic-ai
Expose djangorestframework-services
services and selectors as a Pydantic-AI toolset, so a
plain pydantic_ai.Agent can call them as tools — no MCP server and no AG-UI
bridge in the path.
Every tool call routes through drf-services' transport-neutral surface
(dispatch_spec plus its off-HTTP helpers), so a tool call runs the same input
validation, the same permission_classes — both class-level has_permission
and object-level has_object_permission on the resolved row — and the same
serializer rendering your DRF views apply, just without the HTTP hop.
Install
pip install djangorestframework-pydantic-ai
It depends only on djangorestframework-services and pydantic-ai-slim. A model
provider is pulled in separately, the usual Pydantic-AI way (e.g.
pip install "pydantic-ai-slim[anthropic]").
Quickstart
from pydantic_ai import Agent
from rest_framework_pydantic_ai import AgentDeps, SpecToolset
toolset = SpecToolset({
"list_orders": orders_selector_spec, # SelectorSpec -> read-only tool
"create_order": create_order_spec, # ServiceSpec -> mutation tool
})
agent = Agent("anthropic:claude-opus-4-8", deps_type=AgentDeps, toolsets=[toolset])
result = await agent.run(
"create an order of 3 widgets",
deps=AgentDeps(user=request.user),
)
The agent acts as deps.user: each call builds an off-HTTP request/view context,
enforces the spec's permission_classes (class- and object-level),
dispatches the spec, and renders the result through the spec's serializer. List
selectors gain page / limit / order tool args.
Failures map onto the model loop so the agent self-corrects: invalid input, a bad
page / limit / order value, and unexpected (hallucinated) arguments come
back as ModelRetry; a business error or missing row becomes a readable
{"error": ...}; a denied permission raises PermissionDenied and aborts the
run. Unexpected arguments are rejected by default — pass unknown_arguments=
to SpecToolset (IGNORE / PASSTHROUGH) to change that.
See the documentation for the full reference.
License
MIT
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file djangorestframework_pydantic_ai-0.2.1.tar.gz.
File metadata
- Download URL: djangorestframework_pydantic_ai-0.2.1.tar.gz
- Upload date:
- Size: 108.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6016d636074ad7dd4dce8d1de83e9e9e544666d0dffe394351abe751b47817c6
|
|
| MD5 |
59f2ab528f494aed6386b7b1ff98acfc
|
|
| BLAKE2b-256 |
91ef23c7682d9dda20a60687a131d650d5387c7d8c6ab311a6e00a362daaaccf
|
Provenance
The following attestation bundles were made for djangorestframework_pydantic_ai-0.2.1.tar.gz:
Publisher:
release.yml on Artui/djangorestframework-pydantic-ai
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
djangorestframework_pydantic_ai-0.2.1.tar.gz -
Subject digest:
6016d636074ad7dd4dce8d1de83e9e9e544666d0dffe394351abe751b47817c6 - Sigstore transparency entry: 2047750755
- Sigstore integration time:
-
Permalink:
Artui/djangorestframework-pydantic-ai@6fb8d614aed0189c78decf4e70eaddd8ff603d9b -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Artui
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@6fb8d614aed0189c78decf4e70eaddd8ff603d9b -
Trigger Event:
push
-
Statement type:
File details
Details for the file djangorestframework_pydantic_ai-0.2.1-py3-none-any.whl.
File metadata
- Download URL: djangorestframework_pydantic_ai-0.2.1-py3-none-any.whl
- Upload date:
- Size: 11.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3f1783e26632d8f77a9f8b86b287f3077e8c9848796851a8f8cc0adf9fcb48f8
|
|
| MD5 |
454a0577100736633f08e7bc8e19a578
|
|
| BLAKE2b-256 |
2ff2b2610df9dafa87a867e08c2c04f0d7d1b4373c0c45db4c0042a51045d9b8
|
Provenance
The following attestation bundles were made for djangorestframework_pydantic_ai-0.2.1-py3-none-any.whl:
Publisher:
release.yml on Artui/djangorestframework-pydantic-ai
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
djangorestframework_pydantic_ai-0.2.1-py3-none-any.whl -
Subject digest:
3f1783e26632d8f77a9f8b86b287f3077e8c9848796851a8f8cc0adf9fcb48f8 - Sigstore transparency entry: 2047750768
- Sigstore integration time:
-
Permalink:
Artui/djangorestframework-pydantic-ai@6fb8d614aed0189c78decf4e70eaddd8ff603d9b -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Artui
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@6fb8d614aed0189c78decf4e70eaddd8ff603d9b -
Trigger Event:
push
-
Statement type: