Skip to main content

Genkit Django Plugin

Project description

Genkit Django Plugin

genkit-plugin-django exposes Genkit flows as HTTP endpoints in a Django application. It mirrors genkit-plugin-flask and genkit-plugin-fastapi: one decorator turns a @ai.flow() into a Django view that speaks the Genkit HTTP protocol (JSON envelope, optional SSE streaming, structured error responses).

Install

pip install genkit-plugin-django

Usage

# myapp/views.py
from genkit import Genkit
from genkit.plugins.django import genkit_django_handler

ai = Genkit(plugins=[...])


@genkit_django_handler(ai)
@ai.flow()
async def chat(prompt: str) -> str:
    response = await ai.generate(prompt=prompt)
    return response.text
# myproject/urls.py
from django.urls import path
from myapp.views import chat

urlpatterns = [
    path('chat/', chat),
]

The view requires Django's ASGI server (Django 4.1+):

uvicorn myproject.asgi:application

Wire protocol

  • Body: {"data": <flow_input>}. Missing data → 400.
  • Streaming: Accept: text/event-stream or ?stream=true. Each chunk emits data: {"message": ...}\n\n; completion emits data: {"result": ...}\n\n; on exception error: {"error": ...}.
  • Non-stream: {"result": <flow_output>} on success; 500 with HttpErrorWireFormat JSON on exception.

Context provider

async def auth(request_data):
    return {'username': request_data.headers.get('authorization')}


@genkit_django_handler(ai, context_provider=auth)
@ai.flow()
async def chat(prompt, ctx):
    user = ctx.context.get('username')
    ...

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

genkit_plugin_django-0.7.0.tar.gz (11.6 kB view details)

Uploaded Source

Built Distribution

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

genkit_plugin_django-0.7.0-py3-none-any.whl (10.9 kB view details)

Uploaded Python 3

File details

Details for the file genkit_plugin_django-0.7.0.tar.gz.

File metadata

  • Download URL: genkit_plugin_django-0.7.0.tar.gz
  • Upload date:
  • Size: 11.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for genkit_plugin_django-0.7.0.tar.gz
Algorithm Hash digest
SHA256 f58b7e20d8c6477ecaaa39e5d7c82e8fc3ec7ca5998f85aff0dab238ce409c81
MD5 3725afca7e96918dab9a785d467ad2c5
BLAKE2b-256 0c696e70ecf0b78570beed9be0b020f4e92bcebe6d369c968ef268baec4999b9

See more details on using hashes here.

Provenance

The following attestation bundles were made for genkit_plugin_django-0.7.0.tar.gz:

Publisher: publish_python.yml on genkit-ai/genkit

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

File details

Details for the file genkit_plugin_django-0.7.0-py3-none-any.whl.

File metadata

File hashes

Hashes for genkit_plugin_django-0.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1d46084d9754abfb8134ca602eb91bb8c256a3d85cf2a157a5537d12b5f8a95f
MD5 1e36db1a558f68cd44026c156d6cd348
BLAKE2b-256 5af343d5494fc72b45e70bf5e4d363ae99e9d33a8709d7b133a38ca4e8a27a11

See more details on using hashes here.

Provenance

The following attestation bundles were made for genkit_plugin_django-0.7.0-py3-none-any.whl:

Publisher: publish_python.yml on genkit-ai/genkit

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