.md →
Excalidraw API#
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.
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 #
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.