The @client decorator + ServerFunction base + composition machinery is mostly framework-agnostic. The only Django couplings were typing (HttpRequest in __init__ and submit_handler signatures) and runtime view-path detection (HttpResponseBase isinstance/issubclass checks). Replaced both with backend-extension hooks: - HttpRequest type hints → Any. Type Protocol can be tightened later. - HttpResponseBase view-path detection → set_framework_response_base(cls) hook in mizan_core.client.function. Backends register their framework's response base at import time. is_framework_response(obj_or_cls) handles both instance and subclass checks via the registered base. mizan-django registers HttpResponseBase via mizan/client/__init__.py before any @client-decorated code is loaded. FastAPI would similarly register starlette.responses.Response. Direct consumers updated: - mizan/setup/discovery.py: ServerFunction import path - mizan/forms/__init__.py: ServerFunction + create_form_functions imports mizan/client/__init__.py keeps its public re-export surface stable so 'from mizan.client import client, ServerFunction, …' continues to work for downstream Django consumers. Verified: - mizan-core: 15/15 - mizan-django: 348 pass, 21 skip, 0 fail - mizan-ts edge-compat: 34/34 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
mizan (Python)
Django server functions framework. See the monorepo root for full documentation.
Install
uv add "mizan[channels,allauth] @ git+https://git.impactsoundworks.com/isw/mizan.git#subdirectory=django"
Setup
# settings.py
INSTALLED_APPS = ["mizan", ...]
# urls.py
path("api/mizan/", include("mizan.urls"))
# asgi.py (optional, for WebSocket)
from mizan import wrap_asgi
application = wrap_asgi(get_asgi_application())
Define Functions
from mizan.client import client
from mizan_core.registry import register
from pydantic import BaseModel
class Output(BaseModel):
message: str
@client
def echo(request, text: str) -> Output:
return Output(message=text)
register(echo, "echo")
Register in apps.py:
def ready(self):
import myapp.mizan_clients
Auth
@client(auth=True) # requires authentication
@client(auth='staff') # requires is_staff
@client(auth='superuser') # requires is_superuser
@client(auth=my_callable) # custom check
Contexts
@client(context='global') # fetched once, SSR-hydrated, becomes useCurrentUser()
@client(context='local') # fetched with params, becomes <GreetProvider>
Forms
from mizan.forms import mizanFormMixin, mizanFormMeta
class ContactForm(mizanFormMixin, forms.Form):
mizan = mizanFormMeta(name="contact", title="Contact Us")
name = forms.CharField()
email = forms.EmailField()
def on_submit_success(self, request):
return {"sent": True}
Auto-registers contact.schema, contact.validate, contact.submit. Generates useContactForm() with Zod validation.
Channels
from mizan.channels import ReactChannel
class ChatChannel(ReactChannel):
class Params(BaseModel):
room: str
class DjangoMessage(BaseModel):
text: str
def authorize(self, params):
return self.user.is_authenticated
def group(self, params):
return f"chat_{params.room}"
Generates useChatChannel({ room }).
Running Tests
uv sync --extra dev --extra channels
uv run pytest