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.
pip install mowidgets
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.
- 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.
- 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.


