Skip to main content

izana-django

Django backend adapter for the Izana protocol. One decorator on a server function. Typed React client generated. Invalidation automatic.

Install

uv add "izana[channels]"

Setup

# settings.py
INSTALLED_APPS = ["izana", "myapp", ...]

IZANA_CACHE_SECRET   = "..."   # 32-byte HMAC signing key
IZANA_CACHE_REDIS_URL = "redis://localhost:6379/0"
IZANA_MWT_SECRET     = "..."   # MWT signing key (separate from cache + JWT)
# urls.py
from django.urls import include, path

urlpatterns = [
    path("api/izana/", include("izana.urls")),
]
# asgi.py — for WebSocket / Channels support
from django.core.asgi import get_asgi_application
from izana import wrap_asgi

application = wrap_asgi(get_asgi_application())

Define server functions

# myapp/clients.py
from izana.client import client
from izana.setup import register
from pydantic import BaseModel


class EchoOutput(BaseModel):
    message: str


@client
def echo(request, text: str) -> EchoOutput:
    return EchoOutput(message=text)


register(echo, "echo")

Auto-discover clients.py modules from each Django app:

# myapp/apps.py
from django.apps import AppConfig


class MyAppConfig(AppConfig):
    name = "myapp"

    def ready(self) -> None:
        from izana.setup import izana_clients
        izana_clients("myapp")  # imports myapp/clients.py — triggers @client side effects

@client parameters

@client                              # plain RPC function
@client(context="global")            # singleton context — fetched once, SSR-hydrated
@client(context="user")              # named context — fetched per provider mount
@client(affects="user")              # mutation — invalidates the user context
@client(affects=user_profile)        # mutation — invalidates a specific function
@client(websocket=True)              # WebSocket transport (requires channels)
@client(auth=True)                   # requires authentication
@client(auth="staff")                # requires is_staff
@client(auth="superuser")            # requires is_superuser
@client(auth=lambda req: ...)        # custom predicate
@client(route="/profile/<id>/")      # view-path function (returns HttpResponse)
@client(rev=2)                       # cache revision (busts on bump)

Forms

Django Forms become server functions + typed React hooks with Zod validation:

from django import forms
from izana.forms import izanaFormMixin, izanaFormMeta


class ContactForm(izanaFormMixin, forms.Form):
    izana = izanaFormMeta(name="contact", title="Contact Us", submit_label="Send")

    name    = forms.CharField()
    email   = forms.EmailField()
    message = forms.CharField(widget=forms.Textarea)

    def on_submit_success(self, request):
        send_email(self.cleaned_data)
        return {"sent": True}

Auto-registers contact.schema, contact.validate, contact.submit. Frontend gets useContactForm().

Auth-provider forms (django-allauth login, signup, MFA, WebAuthn) live in the dedicated izana-allauth repository, built on this mixin.

Channels

WebSocket-native RPC via a flag flip. The message slots are named from the client's point of view: ClientMessage travels client → server, ServerMessage travels server → client. Declare only the directions the channel uses.

from pydantic import BaseModel
from izana.channels import Channel


class ChatChannel(Channel):
    class Params(BaseModel):
        room: str

    class ClientMessage(BaseModel):
        text: str

    class ServerMessage(BaseModel):
        text: str
        user: str

    def authorize(self, params):
        return self.user.is_authenticated

    def group(self, params):
        return f"chat_{params.room}"

    def receive(self, params, msg):
        return self.ServerMessage(text=msg.text, user=self.user.email)

Frontend gets useChatChannel({ room }).

Server code outside a subscription broadcasts with push():

await ChatChannel.push(room="general", message=ChatChannel.ServerMessage(...))

Generate the frontend

The codegen is the izana-generate Rust binary (source at protocol/izana-codegen/; protocol/izana-generate/ is a thin npm launcher that dispatches to the platform binary). From your frontend project, point a izana.toml at the Django backend and run the CLI:

# frontend/izana.toml
output = "src/api"
targets = ["react"]

[source.django]
manage_path = "../backend/manage.py"
command = ["uv", "run", "python"]    # optional — defaults to ["python"]

[source.django.env]
PYTHONPATH = "../backend"
DJANGO_SETTINGS_MODULE = "myproject.settings"
izana-generate --config izana.toml

The codegen drives Django's management command (export_izana_ir) under the hood, parses the emitted KDL IR, then emits Stage 1 (typed callXxx/fetchXxx over the runtime kernel) + Stage 2 (<IzanaContext> provider, per-context providers, use{Hook}() hooks) into src/api/.

// app.tsx
import { IzanaContext } from "./api"

export default function App({ children }) {
    return <IzanaContext baseUrl="/api/izana">{children}</IzanaContext>
}
// any component
import { useEcho, useCurrentUser } from "./api"

const echo = useEcho()
echo.mutate({ text: "hi" }).then(r => console.log(r.message))

const user = useCurrentUser()  // global context — auto-fetched, auto-refreshed on mutation

Running tests

uv sync --extra dev --extra channels
uv run pytest

Architecture

izana-django is one of two reference backend adapters (the other is backends/izana-fastapi). Both implement the same Izana protocol on top of the shared cores/izana-python core (@client, registry, MWT, HMAC cache keys). See docs/AFI_ARCHITECTURE.md.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_izana-1.0.1.tar.gz (111.1 kB view details)

Uploaded Source

Built Distribution

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

django_izana-1.0.1-py3-none-any.whl (90.2 kB view details)

Uploaded Python 3

File details

Details for the file django_izana-1.0.1.tar.gz.

File metadata

  • Download URL: django_izana-1.0.1.tar.gz
  • Upload date:
  • Size: 111.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"CachyOS Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for django_izana-1.0.1.tar.gz
Algorithm Hash digest
SHA256 a50d2522a3388f851bae21c9d6e3c95de47c214e76d71626f9f59fe7f93e3c67
MD5 75b4692db62b38b48e196f00d5230e9c
BLAKE2b-256 ab84c891a12903f3aec7f488e63c090ace53c32cf1fef9ae3536eb65c17e55bf

See more details on using hashes here.

File details

Details for the file django_izana-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: django_izana-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 90.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"CachyOS Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for django_izana-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3a3fd9be0d05163866f84cbba0c114e369967c5fefd7c92e2fd078e30c3ac951
MD5 a0864d65f37f5b21597110cdf17fdd3c
BLAKE2b-256 4c356671bbcd33df33b41916dd21f9f4a8d002191b590c68039eb9c0f423f407

See more details on using hashes here.

Release history Release notifications | RSS feed

1.1.0

2 files

1.0.4

2 files

1.0.3

2 files

1.0.2

2 files

This release

1.0.1 This release

2 files

0.0.1

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page