Reusable widgets for marimo notebooks
Project description
mowidgets
Reuse marimo notebooks as widgets inside other marimo notebooks! This allows to build libraries of reusable widgets and distribute them.
This uses native marimo features and the standard Python library; no extra dependencies.
Installation
pip install mowidgets
Tutorial
As an example, we create a simple widget that multiplies two numbers and displays the result.
-
Create a marimo notebook to define the widget.
marimo edit multiply.py # widget module name
-
Create a marimo notebook for the main app.
marimo edit app.py
-
From the
multiply(widget module name) Python module, import theappvariable.from multiply import app as multiply_app
-
Use
mowidgets.widgetize()on themarimo.Appinstance to create the widget.multiply_widget = mowidgets.widgetize(multiply_app)
-
Call
awaitin front of the widget instance to render it.await multiply_widget
-
Using
mowidgets.widgetize(..., data_access=True)allows to read values exposed by the widget. You even get autocompletion!
See the
examples/directory to see complete files.
Known limitations
- Using a setup cell cell in the primary notebook seems to create issues where the widget blocks the primary execution loop. Replacing the setup cell by regular cell avoids the problem.
Next steps
- Pass starting values to the
MoWidgetinstance. This would allow to compose widgets together. (Idea well-received by the core dev team) - Have
MoWidgetexpose a reliable input and output schema. Optionally add type coercion via Pydantic. - Simplify the import experience. Currently, the user must import the
marimo.Appinstance in the main namespace for the widget to properly refresh.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mowidgets-0.1.1.tar.gz.
File metadata
- Download URL: mowidgets-0.1.1.tar.gz
- Upload date:
- Size: 260.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4c4e65acbc2a2b35ea9f22fa32ec3e2107756c3faac5c5019e63efa35ffdfb9c
|
|
| MD5 |
8cf0a3323b334584c923aad01874aac2
|
|
| BLAKE2b-256 |
f0dfa81ea808dffa5650d4b8f7bac016ca3c840d013ceb156a9a32241c83aab9
|
File details
Details for the file mowidgets-0.1.1-py3-none-any.whl.
File metadata
- Download URL: mowidgets-0.1.1-py3-none-any.whl
- Upload date:
- Size: 8.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
677f90e4ca9d55f0ad017897d65ba9a707b87d2fe38cca49fc2fcb33acf7ab6f
|
|
| MD5 |
c2fd032c5f45746a147216d406bff378
|
|
| BLAKE2b-256 |
fc78b19e847cafc758268b3b6919fc9e014a86c25f16fc342486e40dc9fe2c63
|