Skip to main content

Cell

Cells are the fundamental building blocks of marimo notebooks. Each cell contains Python code that executes reactively based on variable dependencies.

Overview

Cells in marimo are defined using the @app.cell decorator. Each cell:
  • Contains a Python function
  • Automatically tracks variable dependencies
  • Re-executes when dependencies change
  • Returns variables to make them available to other cells

Basic Usage

Variables returned from a cell are available to cells that depend on them.

Cell Structure

Function Name

Cells can have any function name. Using __() is a convention for cells that don’t need a specific name.

Returns

Variables must be returned in a tuple to be available to other cells:
Variables not returned are local to the cell and won’t be accessible to other cells.

Cell Configuration

The @app.cell decorator accepts configuration options:
bool
default:"False"
Hide the cell code when running in app mode
bool
default:"False"
Disable the cell from executing

Reactive Execution

marimo automatically determines the execution order based on variable dependencies:

Multiple Definitions

marimo prevents multiple definitions of the same variable:
This prevents hidden state and ensures notebook reproducibility.

Variable References

Access all variables defined by a cell:
Access all variables referenced by a cell:

Best Practices

Each cell should perform one logical operation. This makes dependencies clearer and enables better reactivity.
Always return variables that other cells need to access. Forgetting to return a variable is a common mistake.
Minimize side effects in cells (file writes, API calls) as cells may re-execute when dependencies change.
When a cell performs an important operation, give it a descriptive function name instead of __().

Advanced Features

Lazy Execution

Configure the runtime to mark cells as stale instead of auto-executing:

Disabling Cells

Temporarily disable a cell from executing:

App

Learn about marimo Apps

Reactivity

Understanding reactive execution