danvas: interactive browser canvases from Python
Open source · AGPL-3.0
An open-source library, published on PyPI, that turns any Python script into a live, multi-user browser UI: sliders, plots, tables, video, 3D models and custom React panels, all wired to ordinary Python functions.
- Python
- Rust
- WebSockets
- React
- Open source
Research and hardware work keeps needing small interfaces: a slider for a servo, a live plot of a sensor, a table of results to share with a supervisor. Building each one in HTML and JavaScript takes longer than the experiment. danvas lets you build them in a few lines of Python instead.
import danvas
canvas = danvas.Canvas()
servo = canvas.slider("servo_1", min=0, max=180, default=90)
status = canvas.label("status", "idle")
@servo.on_change
def handle(value):
status.update(f"servo at {value}")
canvas.serve(port=8000)
Panels appear on a zoomable browser canvas. Clicking or editing one calls a normal Python function in your process, with full access to your code, hardware and files.
What it does
- Panels for most things: controls, sortable tables, Plotly charts, streaming plots, heatmaps, video and audio feeds, file upload and download, chat, and a 3D viewer with volume rendering. Anything else can be your own React or HTML.
- Multi-user by default: any number of browsers share one live canvas, with a viewer roster, live cursors, shared drawing and role-based logins.
- Sharing built in: on the local network, behind a password, or through a public HTTPS tunnel.
- Resilient: the interface survives the script crashing and recovers on restart, saves values and layout across runs, and hot-reloads edited functions.
- Any language: a documented wire protocol, with Python, Rust and Node SDKs and an Arduino serial bridge.
How it’s built
A Rust broker serves the canvas and relays state over a single WebSocket. Python owns the state; the browser renders it and reports what the user did. The base install needs only two small Python dependencies, with heavier features (video, audio, tunnelling, desktop apps) as optional extras.