.py files. This makes them easy to version control, diff, and integrate into your development workflow.
Creating a New Notebook
Start the editor
Create a new notebook with the If the file doesn’t exist, marimo will create an empty notebook. If it exists, marimo will open it for editing.
marimo edit command:Open in browser
marimo will automatically launch your browser and open the notebook editor at
http://localhost:2718.Use the --headless flag to prevent the browser from opening:Notebook File Structure
marimo notebooks are pure Python files with a specific structure:notebook.py
Each cell is a Python function decorated with
@app.cell. Variables are automatically tracked and cells re-execute when their dependencies change.Understanding Cells
Cell Functions
Each cell is defined as a function:__(mo, pd)) indicate which variables from other cells this cell depends on.
Variable Returns
Variables must be explicitly returned to be used by other cells:Anonymous Cells
Cells use__() as the function name by default. You can also name cells for better debugging:
Organizing Code
Markdown Cells
Usemo.md() to create formatted markdown content:
Code Organization
Follow these best practices:- Import cells first: Place imports at the top
- One responsibility per cell: Keep cells focused on a single task
- Return only what’s needed: Don’t expose internal variables
- Use descriptive names: Name important cells for clarity
Cell Configuration
Hide Code
Hide cell code while showing output:Disable Automatic Execution
Prevent a cell from running automatically:Advanced: Script Metadata (PEP 723)
marimo notebooks can include dependency information using PEP 723 inline script metadata:Creating from Templates
AI-Generated Notebooks
Generate a notebook from a text prompt:Tutorial Notebooks
Open built-in tutorials:Next Steps
Running Notebooks
Learn about different execution modes
Package Management
Manage dependencies in your notebooks