.md →
Excalidraw API#
Excalidraw puts the Excalidraw whiteboard in a notebook cell: an infinite canvas with
shapes, arrows, text and freehand strokes. Excalidraw and React are fetched from a CDN
the first time the widget renders, so it needs network access. The drawing lives on the
scene traitlet and nothing is written to disk until you call save(); get_pil()
hands the board to Python as an image — handy for a multimodal model — and
Excalidraw.from_file() loads a saved .excalidraw file back.
See also: Paint for a smaller MS-Paint-style canvas, GridDraw for dots and lines snapped to a grid, and EdgeDraw for node and link diagrams you can compute on.
Bases: AnyWidget
An embedded Excalidraw whiteboard.
Draw shapes, arrows, text, and freehand sketches on an infinite canvas.
The current drawing is kept in memory on the scene traitlet as an
Excalidraw scene dict (elements / appState / files). Like the
other drawing widgets, nothing is written to disk automatically — call
:meth:save when you want to persist, and load with :meth:from_file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scene
|
Optional[dict]
|
Optional Excalidraw scene dict to preload the canvas with. |
None
|
height
|
int
|
Canvas height in pixels. |
DEFAULT_HEIGHT
|
sync_throttle_ms
|
int
|
Minimum delay between syncing edits back to Python. |
1000
|
theme
|
str
|
|
'light'
|
Example
After sketching something:
Source code in wigglystuff/excalidraw.py
from_file
classmethod
#
from_file(path: Union[str, Path], **kwargs) -> Excalidraw
Create an :class:Excalidraw preloaded with the scene at path.
The path is remembered on source_path so you can call
:meth:save with no argument to write edits back to the same file.
Source code in wigglystuff/excalidraw.py
get_image_base64 #
get_pil #
Return the current drawing as a PIL Image, or None if empty.
Handy for passing what you drew forward — e.g. into a multimodal model.
The PNG is rendered in the browser and synced back, so it lags edits by
up to sync_throttle_ms.
Source code in wigglystuff/excalidraw.py
get_scene #
save #
Write the current scene to a .excalidraw JSON file and return where.
Pass path to choose the destination; it is remembered on
source_path, so later calls — and widgets created via
:meth:from_file — can call save() with no argument to write back
to the same file. This widget never writes on its own: in marimo,
putting save() in its own cell makes it effectively autosave,
because marimo (not this method) re-runs that cell whenever the widget
changes, so the file tracks what you draw. The returned absolute path is
shown as the cell output, so it is always clear which file was written.
Source code in wigglystuff/excalidraw.py
Synced traitlets#
| Traitlet | Type | Notes |
|---|---|---|
scene |
dict |
Excalidraw scene (elements / appState / files). |
image_base64 |
str |
PNG data URL of the drawing; read via get_pil(). |
theme |
str |
"light" (default) or "dark"; "" follows the notebook theme. |
height |
int |
Canvas height in pixels. |
sync_throttle_ms |
int |
Minimum delay between syncing edits back to Python. |
Excalidraw itself is loaded from a CDN the first time the widget renders, so the widget needs network access and does not work fully offline.