Skip to main content

Expose djangorestframework-services services and selectors as a Pydantic-AI toolset.

Project description

djangorestframework-pydantic-ai

CI PyPI Python versions Django versions Docs Coverage Ruff License

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 the same validation, permissions, and serializer rendering your DRF views apply also apply here — 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 drf_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, dispatches the spec, and renders the result through the spec's serializer. List selectors gain page / limit / order tool args.

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

djangorestframework_pydantic_ai-0.1.0.tar.gz (103.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file djangorestframework_pydantic_ai-0.1.0.tar.gz.

File metadata

File hashes

Hashes for djangorestframework_pydantic_ai-0.1.0.tar.gz
Algorithm Hash digest
SHA256 5de1052e4e69fd476fe5bf9724eb9b400bca9586c9453741fe9cc1373eeb2ec7
MD5 670d2945791a4ac7dca065a541deeafe
BLAKE2b-256 a8091aff5e37aafcb339f4016e93c20c8437c05fedafc06a080719f5aea2c98b

See more details on using hashes here.

Provenance

The following attestation bundles were made for djangorestframework_pydantic_ai-0.1.0.tar.gz:

Publisher: release.yml on Artui/djangorestframework-pydantic-ai

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file djangorestframework_pydantic_ai-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for djangorestframework_pydantic_ai-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7df2691867d423f89f399672a162940021a7fdecae3090e3dc90806f1611356c
MD5 bfa1cfb3b3263c38ccd067c90983c00a
BLAKE2b-256 5338810f6dbb5ad49e00cdf873d09fd6cb5bc971db8e05f91f115db6de374a83

See more details on using hashes here.

Provenance

The following attestation bundles were made for djangorestframework_pydantic_ai-0.1.0-py3-none-any.whl:

Publisher: release.yml on Artui/djangorestframework-pydantic-ai

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page