Intro

Welcome to marimo! ๐ŸŒŠ๐Ÿƒ

marimo is a reactive Python notebook. This means that unlike traditional notebooks, marimo notebooks run automatically when you modify them or interact with UI elements, like this slider: .

๐Ÿƒ

1. Reactive execution

A marimo notebook is made up of small blocks of Python code called cells.

marimo reads your cells and models the dependencies among them: whenever a cell that defines a global variable is run, marimo automatically runs all cells that reference that variable.

Reactivity keeps your program state and outputs in sync with your code, making for a dynamic programming environment that prevents bugs before they happen.

๐ŸŒŠ See it in action. In the next cell, change the value of the variable changed to True, then click the run button.
The order of cells on the page has no bearing on the order in which cells are executed: marimo knows that a cell reading a variable must run after the cell that defines it. This frees you to organize your code in the way that makes the most sense for you.

Global names must be unique. To enable reactivity, marimo imposes a constraint on how names appear in cells: no two cells may define the same variable.

By encapsulating logic in functions, classes, or Python modules, you can minimize the number of global variables in your notebook.
Variables prefixed with an underscore are "private" to a cell, so they can be defined by multiple cells.

2. UI elements

Cells can output interactive UI elements. Interacting with a UI element automatically triggers notebook execution: when you interact with a UI element, its value is sent back to Python, and every cell that references that element is re-run.

marimo provides a library of UI elements to choose from under marimo.ui. ๐ŸŒŠ Some UI elements. Try interacting with the below elements.

๐Ÿƒ

3. marimo is just Python

marimo cells parse Python (and only Python), and marimo notebooks are stored as pure Python files โ€” outputs are not included. Thereโ€™s no magical syntax.

The Python files generated by marimo are:

  • easily versioned with git, yielding minimal diffs
  • legible for both humans and machines
  • formattable using your tool of choice,
  • usable as Python scripts, with UI elements taking their default values, and
  • importable by other modules (more on that in the future). ## 4. Running notebooks as apps

marimo notebooks can double as apps. Click the app window icon in the bottom-left to see this notebook in โ€œapp view.โ€

Serve a notebook as an app with marimo run at the command-line. Of course, you can use marimo just to level-up your notebooking, without ever making apps. ## 5. The marimo command-line tool

Creating and editing notebooks. Use

marimo edit

in a terminal to start the marimo notebook server. From here you can create a new notebook or edit existing ones.

Running as apps. Use

marimo run notebook.py

to start a webserver that serves your notebook as an app in read-only mode, with code cells hidden.

Convert a Jupyter notebook. Convert a Jupyter notebook to a marimo notebook using marimo convert:

marimo convert your_notebook.ipynb > your_app.py

Tutorials. marimo comes packaged with tutorials:

  • dataflow: more on marimoโ€™s automatic execution
  • ui: how to use UI elements
  • markdown: how to write markdown, with interpolated values and LaTeX
  • plots: how plotting works in marimo
  • fileformat: how marimoโ€™s file format works

Start a tutorial with marimo tutorial; for example,

marimo tutorial dataflow

In addition to tutorials, we have examples in our our GitHub repo. ## 6. The marimo editor

Here are some tips to help you get started with the marimo editor.

Saving
  • Name your app using the box at the top of the screen, or with Ctrl/Cmd+s. You can also create a named app at the command line, e.g., marimo edit app_name.py.
  • Save by clicking the save icon on the bottom left, or by inputting Ctrl/Cmd+s. By default marimo is configured to autosave.
  1. Run a cell by clicking the play ( โ–ท ) button on the bottom right of a cell, or by inputting Ctrl/Cmd+Enter.
  2. Run a stale cell by clicking the yellow run button to the right of the cell, or by inputting Ctrl/Cmd+Enter. A cell is stale when its code has been modified but not run.
  3. Run all stale cells by clicking the play ( โ–ท ) button on the bottom right of the screen, or input Ctrl/Cmd+Shift+r.
Console output (e.g., print() statements) is shown below a cell.
  1. Create a new cell above or below a given one by clicking the plus button to the left of the cell, which appears on mouse hover.
  2. Move a cell up or down by dragging on the handle to the right of the cell, which appears on mouse hover.
  3. Delete a cell by clicking the trash bin icon. Bring it back by clicking the undo button on the bottom right of the screen, or with Ctrl/Cmd+Shift+z.
You can disable a cell via the cell context menu (open it by clicking the icon to the right of a cell). marimo will never run a disabled cell or any cells that depend on it. This can help prevent accidental execution of expensive computations when editing a notebook.
You can collapse or fold the code in a cell by clicking the arrow icons in the line number column to the left, or by using keyboard shortcuts. Use the command palette (Ctrl/Cmd+k) or a keyboard shortcut to quickly fold or unfold all cells.
If you have black installed, you can format a cell with the keyboard shortcut Ctrl/Cmd+b.
Use Ctrl/Cmd+k to open the command palette.
Click the keyboard button on the bottom left of the screen (or input Ctrl/Cmd+Shift+h) to view a list of all keyboard shortcuts.
Configure the editor by clicking the gears icon near the top-right of the screen.

Finally, a fun fact

The name โ€œmarimoโ€ is a reference to a type of algae that, under the right conditions, clumps together to form a small sphere called a โ€œmarimo moss ballโ€. Made of just strands of algae, these beloved assemblages are greater than the sum of their parts.

Back to top