The Blazr-critical surface for FastAPI. Forms, Channels, Shapes, SSR,
and MWT are out of scope (Ryth's call: defer until Blazr exercises
them; FastAPI projects use native equivalents anyway).
What ships:
- POST /api/mizan/call/ RPC dispatch with Pydantic input validation
- GET /api/mizan/ctx/{name}/ bundled context fetch (all functions in
the named context, parallel-evaluated, single
JSON response)
- JSON-body invalidation transport (the 'invalidate' field on mutation
responses, with auto-scoping when mutation arg names match context params)
- Auth check infrastructure expecting request.state.user populated by
FastAPI middleware/deps (matches FastAPI idioms)
- Cache-Control: no-store on all responses
Built on existing mizan-core: registry (function lookup, context groups,
invalidation metadata), client.function (the @client decorator + ServerFunction
+ _FunctionWrapper). No code copied or duplicated from mizan-django — the
shared substrate is genuinely shared.
Package layout:
backends/mizan-fastapi/
pyproject.toml distribution=mizan-fastapi, module=mizan_fastapi
src/mizan_fastapi/
executor.py dispatch + auth + invalidation
router.py FastAPI APIRouter with the two endpoints
tests/test_dispatch.py 11 e2e tests against TestClient
Test fixture establishes the registration pattern: explicit
register(fn_class, "name") after each @client. mizan-fastapi doesn't
ship discovery — apps register their functions explicitly. (mizan-django
keeps its DjangoAppVisitor discovery; FastAPI's lack of an app system
makes auto-discovery less natural.)
Makefile: install + test targets now include mizan-fastapi alongside
the other packages. New test-core / test-fastapi targets added for
symmetry.
Verified:
- mizan-core: 15/15
- mizan-django: 348 pass, 21 skip, 0 fail
- mizan-fastapi: 11/11
- mizan-ts edge-compat: 34/34
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
31 lines
891 B
Python
31 lines
891 B
Python
"""
|
|
mizan-fastapi — FastAPI backend adapter for the Mizan protocol.
|
|
|
|
Provides HTTP RPC dispatch and context bundling on top of mizan-core's
|
|
function registry. Channels, Forms, Shapes, SSR are out of scope for
|
|
the FastAPI adapter — FastAPI projects use native equivalents (WebSocket,
|
|
Pydantic models, ORM-of-choice, server-side rendering frameworks).
|
|
|
|
Usage:
|
|
from fastapi import FastAPI
|
|
from mizan_fastapi import router as mizan_router
|
|
|
|
app = FastAPI()
|
|
app.include_router(mizan_router, prefix="/api/mizan")
|
|
|
|
# Register your @client-decorated functions
|
|
from mizan_core.client.function import client
|
|
from .my_functions import * # noqa
|
|
"""
|
|
|
|
from .router import router
|
|
from .executor import execute_function, ErrorCode, FunctionError, FunctionResult
|
|
|
|
__all__ = [
|
|
"router",
|
|
"execute_function",
|
|
"ErrorCode",
|
|
"FunctionError",
|
|
"FunctionResult",
|
|
]
|