Registry / devops / streamlit-drawable-canvas

streamlit-drawable-canvas

JSON →
library0.9.3pypypi✓ verified 84d ago

A Streamlit custom component that provides a free drawing canvas using Fabric.js. Supports drawing shapes, text, images, and exporting as JSON or images. Current version: 0.9.3, updated occasionally.

pip install streamlit-drawable-canvas
INSTALL
IMPORT
SIG · STREAMLIT-DRAWABLE
S
streamlit-drawable-canvas
devopspythonv0.9.3
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

st_canvas
from streamlit_drawable_canvas import st_canvas

Basic canvas that draws freehand and outputs JSON data.

import streamlit as st from streamlit_drawable_canvas import st_canvas # Create a canvas component canvas_result = st_canvas( fill_color="rgba(255, 165, 0, 0.3)", stroke_width=3, stroke_color="#000000", background_color="#FFFFFF", height=400, drawing_mode="freedraw", key="canvas", ) if canvas_result.json_data is not None: st.json(canvas_result.json_data)
Debug
Known issues
breakingIn version 0.9.0, the component was rewritten and the API changed significantly. The old `canvas_result.image_data` (PIL Image) is no longer available; use `canvas_result.image_data` (numpy array) or `canvas_result.json_data`.
fix
Update code to use the new API: canvas_result.image_data returns a numpy array; use canvas_result.json_data for drawing JSON.
affects: >=0.9.0
breakingThe `drawing_mode` parameter values changed. Old modes like 'point', 'line', 'rect', etc. are replaced by 'freedraw', 'line', 'rect', 'circle', 'transform', 'polygon', 'point'. 'polygon' is new; 'point' is now a mode.
fix
Update drawing_mode to one of the new valid modes: 'freedraw', 'line', 'rect', 'circle', 'transform', 'polygon', 'point', 'text', 'image', 'eraser'.
affects: >=0.9.0
deprecatedThe `realtime_update` parameter is deprecated and will be removed in future versions. It now defaults to True and cannot be set to False.
fix
Remove realtime_update from st_canvas calls.
affects: >=0.9.0
gotchaThe canvas result is only updated when the user stops drawing (mouse up). If you need continuous updates, set drawing_mode to 'transform' or use the key parameter to force re-render.
fix
Use key parameter with st.session_state to force updates, or use 'transform' mode which updates on each mouse move.
affects: all
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'streamlit_drawable_canvas'
The library is not installed or installed in a different Python environment.
fix
Run `pip install streamlit-drawable-canvas` in the same environment as your Streamlit app.
TypeError: st_canvas() got an unexpected keyword argument 'realtime_update'
The realtime_update parameter was removed in version 0.9.0.
fix
Remove the realtime_update argument from the st_canvas call.
ValueError: Invalid drawing_mode 'point'. Valid modes are...
Using the old drawing mode names from versions < 0.9.0.
fix
Update drawing_mode to one of: 'freedraw', 'line', 'rect', 'circle', 'transform', 'polygon', 'point', 'text', 'image', 'eraser'.
Upgrade
Version history
0.9.3latest on PyPI · released Jun 5, 2023
Audit
Dependencies
streamlitrequiredRequired core dependency
Agent activity
5 hits · last 30 days
node
4
Resources
streamlit-drawable-canvas — pip install streamlit-drawable-canvas · libregistry