Skip to content

DAAF-Contribution-Community/daaf / .claude/skills/marimo

marimo

Verified

Reactive Python notebook system with cell reactivity, UI elements, SQL cells, plotting, and app deployment. DAAF's standard notebook format — stored as Git-friendly .py files, not .ipynb. For DAAF pipelines, Stage 9 literally archives existing executed scripts in bounded comment/pass cells paired with real execution logs; optional display-only cells may preview existing Parquet data or show already-created figures, but may not analyze data or generate figures. Use when assembling Stage 9 research notebooks, building standalone interactive data apps, or converting Jupyter notebooks to marimo format. R equivalent: quarto — when execution language is R, use quarto instead.

references/reactivity.md

View on GitHub
# Reactivity & Cell Execution

## Core Concept

marimo notebooks are **reactive**: when you run a cell, marimo automatically runs all cells that depend on variables it defines. This eliminates hidden state and ensures outputs always match code.

## How It Works

### Static Analysis

marimo analyzes each cell to determine:
- **Definitions**: Global variables the cell defines
- **References**: Global variables the cell reads

This creates a **directed acyclic graph (DAG)** of dependencies.

### Execution Rule

> When a cell runs, marimo automatically runs all cells that **reference** any global variables it **defines**.

```python
# Cell 1
x = 10  # Defines 'x'

# Cell 2 (runs automatically when Cell 1 runs)
y = x * 2  # References 'x', defines 'y'

# Cell 3 (runs automatically when Cell 2 runs)
y + 5  # References 'y'
```

### Execution Order

Order is determined by **variable dependencies**, not cell position on the page. You can organize cells however makes sense for your story.

## No Hidden State

### Delete = Scrub

When you delete a cell, marimo **removes its variables from memory**. Cells that referenced those variables are invalidated.

This prevents the classic Jupyter problem: running cells out of order, then being unable to reproduce results.

### Consistent State

Code, outputs, and program state are always synchronized. What you see is what you get.

## Variable Rules

### Unique Global Names

Each global variable must be defined by **exactly one cell**.

```python
# WRONG: Two cells defining 'x'
# Cell 1
x = 10

# Cell 2 (ERROR: multiple definitions)
x = 20
```

Solutions:
1. Use different variable names
2. Use local variables (underscore prefix)
3. Combine into one cell

### Local Variables (Underscore Prefix)

Variables starting with `_` are **local** to a cell:

```python
# Cell 1
_temp = compute_something()
result1 = process(_temp)

# Cell 2 (OK: _temp is local, can reuse name)
_temp = compute_other()
result2 = process(_temp)
```

### Encapsulating with Functions

For many temporary variables, wrap in a function:

```python
def _():
    import matplotlib.pyplot as plt
    fig, ax = plt.subplots()
    ax.plot([1, 2, 3])
    return ax

_()  # Call and display
```

Variables `plt`, `fig`, `ax` stay local to the function.

## Mutations Are Not Tracked

marimo does **not** track mutations to objects.

```python
# Cell 1
my_list = [1, 2, 3]

# Cell 2 (mutation - won't trigger re-runs!)
my_list.append(4)  # Other cells won't see this
```

### Solution: Mutate in Same Cell

```python
# Cell 1: Define AND mutate together
df = pd.DataFrame({"a": [1, 2]})
df["b"] = df["a"] * 2  # Same cell, OK
```

### Solution: Create New Variables

```python
# Cell 1
df = pd.DataFrame({"a": [1, 2]})

# Cell 2
df_with_b = df.assign(b=df["a"] * 2)  # New variable
```

## Runtime Configuration

### Disable Automatic Execution

In notebook settings, you can set runtime to **lazy** mode:
- Cells are marked **stale** instead of auto-running
- You control when to run
- Useful for expensive computations

### On-Startup Behavior

Configure whether to auto-run all cells when opening a notebook.

## Controlling Execution

### Disable Cells

Right-click a cell to disable it. Disabled cells (and their descendants) won't run.

Use case: Temporarily skip expensive computation while iterating.

### Stop Execution

Use `mo.stop()` to conditionally halt execution:

```python
mo.stop(not data_loaded, mo.md("Please load data first"))
# Code below only runs if data_loaded is True
process(data)
```

`mo.stop()` also skips every cell that reads a name the stopped cell defines, directly or through other cells; those cells show "This cell wasn't run because an ancestor was stopped with `mo.stop`". Cells that do not depend on the stopped cell still run. Since marimo 0.20, a cell that depends on several stopped cells runs only once all of them are unblocked. See `validation-patterns.md` for using this as a gate.

### Caching

For expensive operations:

```python
@mo.cache
def expensive_function(x):
    # Result cached based on arguments
    return heavy_computation(x)
```

Persistent cache (survives restarts):

```python
with mo.persistent_cache("my_cache"):
    result = expensive_operation()
```

## Type Annotations

Type annotations **are** tracked as references (for Pydantic, etc.):

```python
# Cell 1
class MyModel: pass

# Cell 2 (references MyModel)
def process(x: MyModel): pass
```

To exclude from dataflow, use string annotations:

```python
def process(x: "MyModel"): pass  # Not tracked
```

## Visualizing Dataflow

Use the **dependency graph** view in the editor to see how cells connect:
- Sidebar > Variables panel
- Click a variable to see its flow
- Helps debug unexpected behavior

## Summary

| Concept | Behavior |
|---------|----------|
| Run a cell | Dependent cells auto-run |
| Delete a cell | Variables scrubbed from memory |
| Global variables | Must be unique across cells |
| `_variable` | Local to cell, can be reused |
| Mutations | Not tracked, keep in same cell |
| Lazy mode | Cells marked stale, manual run |
| `mo.stop()` | Halt this cell and the cells that depend on it |
| `@mo.cache` | Cache expensive results |
writing-skillsobra/superpowersUse when creating new skills, editing existing skills, or verifying skills work before deploymentStars: 322kUpdated Claude CodeCodexVerifiedInstall
xlsxanthropics/skillsUse this skill any time a spreadsheet file is the primary input or output. This means any task where the user wants to: open, read, edit, or fix an existing .xlsx, .xlsm, .xltx, .csv, or .tsv file (e.g., adding columns, computing formulas, formatting, charting, cleaning messy data); create a new spreadsheet from scratch or from other data sources; or convert between tabular file formats. Trigger especially when the user references a spreadsheet file by name or path — even casually (like "the xlsx in my downloads") — and wants something done to it or produced from it. Also trigger for cleaning or restructuring messy tabular data files (malformed rows, misplaced headers, junk data) into proper spreadsheets. The deliverable must be a spreadsheet file. Do NOT trigger when the primary deliverable is a Word document, HTML report, standalone Python script, database pipeline, or Google Sheets API integration, even if tabular data is involved.Stars: 198kUpdated Claude CodeCodexVerifiedInstall
shipping-and-launchaddyosmani/agent-skillsPrepares production launches. Use when preparing to deploy to production, or when asking what needs to be in place before shipping. Use when you need a pre-launch checklist, when setting up monitoring, when planning a staged rollout, or when you need a rollback strategy.Stars: 119kUpdated Claude CodeCodexVerifiedInstall
childhoodthedotmack/claude-memBabysit a shipped release after merge, publication, or deployment. Verify published packages, production behavior, installed plugins, and late CI or user reports until the observation window is clean; use babysit for PR readiness before release.Stars: 118kUpdated Claude CodeCodexVerifiedInstall