A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
FastAPI + marimo: Authentication Middleware
This example shows the recommended pattern for passing user info into marimo
notebooks via mo.app_meta().request.user and mo.app_meta().request.meta.
It includes:
- Login / logout with session cookies
- A pure ASGI middleware that sets
scope["user"]andscope["meta"]for both HTTP and WebSocket connections - A marimo notebook that reads user info via
mo.app_meta().request
Why pure ASGI middleware?
marimo uses WebSocket for real-time communication. Starlette's
BaseHTTPMiddleware only runs for HTTP requests, so scope["user"] set there
is not visible on WebSocket connections. A pure ASGI middleware handles both.
Running the app
- Install
uv - Run the app with
uv run --no-project main.py - Open http://localhost:8000/ and log in with
admin/password123 - The notebook cell will display the authenticated user and meta data