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_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_django-0.9.0.tar.gz (11.7 kB view details)

Uploaded Source

Built Distribution

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

genkit_django-0.9.0-py3-none-any.whl (10.9 kB view details)

Uploaded Python 3

File details

Details for the file genkit_django-0.9.0.tar.gz.

File metadata

  • Download URL: genkit_django-0.9.0.tar.gz
  • Upload date:
  • Size: 11.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for genkit_django-0.9.0.tar.gz
Algorithm Hash digest
SHA256 9a18f215086839e2d6f0e7b6f633948763ae79a438ac129c5e54906952e59dd3
MD5 4692043cb4fe71ffd62565874a126d90
BLAKE2b-256 c741ad02e061776b9d9c681d17a32863a885068bf76001479445578d2d63ee2c

See more details on using hashes here.

Provenance

The following attestation bundles were made for genkit_django-0.9.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_django-0.9.0-py3-none-any.whl.

File metadata

  • Download URL: genkit_django-0.9.0-py3-none-any.whl
  • Upload date:
  • Size: 10.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for genkit_django-0.9.0-py3-none-any.whl
Algorithm Hash digest
SHA256 49ed249de00b20f927c2abde08fb97131cce6acf91e05deadc71a9c0e3aaea80
MD5 998c364ff92e9f76e38cc59d308ceac9
BLAKE2b-256 0c9cf301aa0abedba0c3849949cb6a226290931bef48739d8a4ac41162a7039f

See more details on using hashes here.

Provenance

The following attestation bundles were made for genkit_django-0.9.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