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 "django-izana[channels]"

The distribution is django-izana; the importable package is izana.

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", "cart"])    # mutation — invalidates several contexts
@client(merge="cart")                # mutation — its result splices into the cart context's matching slot
@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. The codegen doesn't emit a hook for them; the frontend drives the three through useIzanaFormCore({ name: "contact" }) from @eralyr/izana-react, which binds to that package's IzanaProvider rather than the generated IzanaContext kernel.

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 }). authorize, group, and receive may be plain def and use the ORM freely — the consumer runs them off the event loop, the same way it dispatches RPC — or async def, which it awaits.

Server code outside a subscription broadcasts with push(). It builds a bare channel instance (no user), so group() must be derivable from params alone:

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.3.tar.gz (152.2 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.3-py3-none-any.whl (44.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: django_izana-1.0.3.tar.gz
  • Upload date:
  • Size: 152.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.7 {"installer":{"name":"uv","version":"0.12.7","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.3.tar.gz
Algorithm Hash digest
SHA256 634fbbf863148a7e49de68e77ea7ceecc86b652d9bc24ec6710779f61bfe15cf
MD5 b067d2b2ead3dac7e52ff746b9ce8a6e
BLAKE2b-256 5f0433c36ddf2666234cf4ebd55404c1f8c2eb66f3a558d4b6f4f135e2bf2e06

See more details on using hashes here.

File details

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

File metadata

  • Download URL: django_izana-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 44.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.7 {"installer":{"name":"uv","version":"0.12.7","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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 fb6dc687875b827b0ff0c7020a36f21842a51d4f7438bda71dd3721ec7cd2150
MD5 5fb87f1340b1f761d1dcfbce30702cf0
BLAKE2b-256 568c6b53336f50e67b772f6465f43876badbcf1a8e1e96920bd1b2aefba554f8

See more details on using hashes here.

Release history Release notifications | RSS feed

1.1.0

2 files

1.0.4

2 files

This release

1.0.3 This release

2 files

1.0.2

2 files

1.0.1

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