North Bay Python 2024

marimo: an open-source reactive notebook for Python
2024-06-29, 15:45–16:10 (US/Pacific), Barn

We introduce marimo, an open-source reactive notebook for Python that addresses several common complaints about first-generation notebooks.

marimo notebooks are reproducible, with a reactive runtime that eliminates hidden state; interactive, with UI elements that are automatically synchronized with Python (no callbacks); expressive, supporting markdown that can be parametrized by arbitrary Python values; stored as pure Python files, so they are Git-friendly; executable as scripts; and shareable as web apps or WASM-powered static HTML.

marimo is used today by scientists and developers at several companies and research institutions, including SLAC and Stanford.

A reactive programming environment

marimo keeps code, outputs, and program state consistent. Run a cell and marimo reacts by automatically running the cells that reference its declared variables. Delete a cell and marimo scrubs its variables from program memory, eliminating hidden state.

Our reactive runtime is based on static analysis, forming a dataflow graph based on variable declarations and references. To ensure the dataflow graph is well-formed, marimo imposes two constraints on user code: variables can be defined in at most one cell, and cyclic references across cells are disallowed.

The marimo library

marimo is both a notebook and a library — importing the marimo library provides the user with utilities for authoring dynamic markdown; creating interactive UI elements; rendering progress bars; and more.

marimo's interactive elements feed into reactivity: interacting with elements such as sliders or selectable plots automatically sends their values to Python and triggers execution of cells referencing variables bound to the interacted-with elements. We extend this rule to support higher-order elements such as submittable forms, dictionaries, and arrays of constituent elements.

A pure Python file format

marimo notebooks are stored as pure Python files, designed so that small changes in notebook code yield small diffs. These files are also executable, with cells run in a topologically sorted order. We discuss the design of this file format, as well as trade-offs made.

Shareability

marimo is easily shared: notebooks can be run as read-only apps from the command line, and exported as interactive WASM-powered static HTML.

Akshay is both a researcher, focusing on machine learning and optimization, and an engineer, having contributed to several open source projects, including TensorFlow and CVXPY. He has a PhD from Stanford University, where he was advised by Stephen Boyd. He also holds a BS and MS in computer science from Stanford.

Akshay is currently building marimo, a new kind of reactive notebook for Python that's reproducible, git-friendly (stored as Python files), executable as a script, and deployable as an app.