Key concepts
marimo introduces a new way of thinking about notebooks through reactive execution and dataflow graphs. This guide explains the fundamental concepts that power marimo.Reactivity
Reactivity is marimo’s core feature: when you run a cell, marimo automatically runs all cells that depend on it.How reactivity works
marimo analyzes your code to build a dependency graph:x in Cell 1, marimo automatically re-runs Cell 2. This keeps your notebook state consistent without manual intervention.
References and definitions
marimo tracks two things for each cell:- Definitions (defs) - Global variables the cell creates or modifies
- References (refs) - Global variables the cell reads
The dataflow graph
marimo creates a directed acyclic graph (DAG) where:- Nodes represent cells
- Edges represent dependencies between cells
marimo prevents cycles in the dependency graph. If you try to create circular dependencies, marimo will show an error.
Lazy execution mode
For expensive computations, you can disable automatic execution:- Click the runtime dropdown in the notebook footer
- Change from “autorun” to “lazy”
Cells
A marimo notebook is composed of cells - small blocks of Python code that form the nodes of the dataflow graph.Cell structure
Cells in marimo are Python functions decorated with@app.cell:
- Is a function that returns a tuple of variables to make global
- Takes its dependencies as function parameters
- Can have a descriptive name or use
__for anonymous cells
No hidden state
Unlike Jupyter, marimo prevents hidden state:- Variables only exist if their defining cell has run
- Delete a cell and its variables are removed from memory
- Cells cannot be run out of order
x will error - marimo won’t let you use undefined variables.
Multiple definitions error
You cannot define the same variable in multiple cells:Interactive elements
marimo’s UI elements automatically trigger reactivity when their values change.Creating UI elements
Import frommarimo.ui:
Accessing values
Use.value to get the current value:
Batching UI elements
Combine multiple inputs into a single object:Forms
Prevent UI elements from triggering updates until submitted:Notebooks vs apps vs scripts
marimo notebooks can be used in three modes:Edit mode (notebooks)
Interactive development environment:- Full code editing
- Interactive outputs
- Cell execution controls
- Variable inspector
- Reactive updates
- Data exploration
- Research and analysis
- Prototyping
- Interactive development
Run mode (apps)
Deploy as a web app:- Code is hidden
- Only UI elements and outputs shown
- Still fully reactive
- Professional presentation
- Dashboards
- Internal tools
- Sharing with non-technical users
- Demos and presentations
Script mode
Execute as a Python script:- Runs top to bottom in dependency order
- No browser required
- Can accept command-line arguments
- Outputs to terminal
- Automation
- Batch processing
- CI/CD pipelines
- Scheduled jobs
State management
marimo providesmo.state() for managing mutable state:
Package management
marimo automatically manages dependencies:Auto-install on import
When you import a package that’s not installed:Inline dependencies
Define requirements in the notebook:Sandbox mode
Run notebooks in isolated environments:Dynamic outputs
Markdown with variables
Create markdown that updates with your data:Conditional rendering
Show different outputs based on conditions:Layouts
Organize outputs with flexible layouts:Working with data
SQL cells
Query dataframes and databases directly:Interactive dataframes
Explore dataframes with built-in interactivity:Next steps
Guides
Dive deeper into specific features and workflows
API reference
Explore the complete marimo API documentation