Skip to main content

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.

screenshot of a mowidget

  1. Create a marimo notebook to define the widget.

    marimo edit multiply.py  # widget module name
    

screenshot of a mowidget

  1. Create a marimo notebook for the main app.

    marimo edit app.py
    
  2. From the multiply (widget module name) Python module, import the app variable.

    from multiply import app as multiply_app
    
  3. Use mowidgets.widgetize() on the marimo.App instance to create the widget.

    multiply_widget = mowidgets.widgetize(multiply_app)
    
  4. Call await in front of the widget instance to render it.

    await multiply_widget
    
  5. Using mowidgets.widgetize(..., data_access=True) allows to read values exposed by the widget. You even get autocompletion!

screenshot of a mowidget

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 MoWidget instance. This would allow to compose widgets together. (Idea well-received by the core dev team)
  • Have MoWidget expose a reliable input and output schema. Optionally add type coercion via Pydantic.
  • Simplify the import experience. Currently, the user must import the marimo.App instance 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

mowidgets-0.1.2.tar.gz (9.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mowidgets-0.1.2-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

File details

Details for the file mowidgets-0.1.2.tar.gz.

File metadata

  • Download URL: mowidgets-0.1.2.tar.gz
  • Upload date:
  • Size: 9.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.11

File hashes

Hashes for mowidgets-0.1.2.tar.gz
Algorithm Hash digest
SHA256 db282cfe421c8b64e236ea2a2b1e50615757134d23f396715964e6f9a89f6493
MD5 c636e57d90a1bef80506eb0b21a5a630
BLAKE2b-256 10788bcf171a0f7e99ac61a0043b3b244bb1cf4e4728034b3f86ef0dd602a8ec

See more details on using hashes here.

File details

Details for the file mowidgets-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: mowidgets-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 9.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.11

File hashes

Hashes for mowidgets-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 4d17f5aa63f2cd6602cfc0a65bff4b9a0fb2b8d079750dfe623f321027df4288
MD5 64a185edea8f151f8071cafdc95e967f
BLAKE2b-256 537cd8dbcd796ce169d48634d9e64e796a5818b92e90e159989499ca8fc2a5c3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page