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
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:Cell Configuration
The@app.cell decorator accepts configuration options:
Hide the cell code when running in app mode
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:Best Practices
Keep cells focused
Keep cells focused
Each cell should perform one logical operation. This makes dependencies clearer and enables better reactivity.
Return all needed variables
Return all needed variables
Always return variables that other cells need to access. Forgetting to return a variable is a common mistake.
Avoid side effects
Avoid side effects
Minimize side effects in cells (file writes, API calls) as cells may re-execute when dependencies change.
Use descriptive names
Use descriptive names
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:Related
App
Learn about marimo Apps
Reactivity
Understanding reactive execution