Skip to content
flow

FeaturesNotebooks

Notebooks

Run Python, JavaScript and shell cells in a Notes page's Preview, with sliders and other inputs that re-run them, and inline tables and charts.

View as Markdown
On this page

Notebooks turn a page in the Notes tab into a live, Jupyter-style notebook that is still a plain Markdown file. In the page's Preview, a python, js or sh code fence becomes a cell you can run, with its output under it, and an input fence becomes sliders, fields, menus and switches that re-run the cells using them. Use it for calculators, quick data checks and charts that sit next to your code.

Note: Notebooks is an experiment (ALPHA). Turn it on in Settings › Experiments (features.notebooks).

While the experiment is off, Preview shows every fence as plain code, no kernel starts (turning it off stops the running ones), the palette doesn't offer the notebook actions, and the flow-cli notebook commands refuse. Your pages and their saved outputs are kept.

Run your first cell

  1. Turn on Notebooks in Settings › Experiments.

  2. Open the session's Notes tab and switch the page to Markdown.

  3. Type a cell:

    markdown
    ```python
    sum(range(10))
    ```
    
  4. Switch to Preview and click ▶ Run on the cell. The result, 45, shows under it.

Code runs only when you ask: ▶ Run on a cell, Run all, changing an input, or flow-cli. Opening a page, switching to it, or Flow reloading it never runs anything.

Cells

A fenced block is a cell when its language word (any case) is one of these:

FenceRuns in
python, py, python3One persistent python3 per Notes tab and page
js, javascript, node, mjsOne persistent node per Notes tab and page
sh, shell, bash, zshA fresh shell for each run (shell runs sh)

Every other fence (rust, mermaid…) renders as before. Cells are numbered in page order, counting from 0, including cells inside lists, quotes, alerts and details blocks. Input fences don't count.

Each cell has a header: the language, [n] (the run's execution count; [ ] never run, [*] queued or running), the status (Queued, Running… 1.2s, or the last run's time), a stale tag when you edited the code since its outputs were made, and ▶ Run or ■ Stop. A page with cells or inputs gets a bar on top: Run all · Restart · Clear outputs.

Kernels start on a cell's first run, in the notebook's repository top, with your shell's PATH, so a Homebrew python3 or node is found. They stop when the tab closes, when you turn the experiment off, or when Flow quits.

Python

  • Cells share one namespace, like Jupyter: define x in one cell and use it in the next.
  • The last expression of a cell is shown. Top-level await works.
  • print and sys.stderr stream as they are written. A traceback shows only your cell's frames.
  • If you use matplotlib, every figure open at the end of a run is shown as an image, then closed. Don't call plt.show().
  • A pandas DataFrame you show or display is a table.

JavaScript

  • Top-level let, const, class and function become globals, so later cells see them and a cell can run again.
  • The last expression is shown; a promise is awaited first. Top-level await works.
  • require resolves from the repository top, so its node_modules are available. Use require, not import statements.

Shell

A shell cell is one-shot: nothing carries over between runs. Its working directory is the repository top, and each input is an environment variable ($n).

Stop, Restart and Clear outputs

  • ■ Stop interrupts the running cell and drops the rest of that kernel's queue. Python raises KeyboardInterrupt and keeps its state; if it doesn't stop within 3 seconds, the kernel restarts. A JavaScript kernel is restarted, so its state is lost. A shell cell's whole process group is killed.
  • Restart stops the page's kernels. Outputs stay.
  • Clear outputs forgets every run of the page. Input values stay.

Helpers

Python and JavaScript cells both have three helpers:

python
display(obj, ...)                   # show each object (a string as itself)
table(rows, columns=None)           # a list of dicts or lists, or a DataFrame
chart.line(x, y=None, title=None)   # also chart.scatter and chart.area
chart.bar(labels, values=None, title=None)
js
display(...values)                  // show each value (a string as itself)
table(rows, columns)                // an array of objects or arrays
chart.line(x, y, opts)              // also chart.scatter, chart.area, chart.bar

chart draws a native chart in your theme's colors:

  • y is a list, or a dict (object) of named series: {"a": [...], "b": [...]}.
  • Leave out x for 0, 1, 2…: chart.line([3, 1, 4]).
  • x is all numbers or all strings. A None or null value is a gap.
  • In JavaScript, pass the title as chart.line(x, y, { title: '…' }), or chart.line(y, 'title').
  • A chart takes up to 12 series and 10,000 points in all. A bar chart shows its first 60 bars.

A table shows its first 200 rows and says how many there are in all.

Python's standard library is always there. Other packages (numpy, pandas, matplotlib, npm packages) work only if they're installed for the python3 or node Flow finds.

Inputs

An input fence declares controls, one per line:

markdown
```input
slider n 1..100 step 1 = 20   # Points
number rate 0..1 step 0.01 = 0.05
text title = "Hello"
select color red|green|blue = red
toggle log = false
```
LineControlValue and default
slider NAME MIN..MAX [step S] [= V]A sliderA number; default the minimum
number NAME [MIN..MAX] [step S] [= V]A number fieldA number; default 0, clamped into the range
text NAME [= "quoted" or bare text]A text fieldA string; default empty
select NAME a|b|c [= a]A menuA string; default the first option
toggle NAME [= true|false]A switchA bool; default false
  • A trailing # Label names the control; without one it shows its name. Blank lines and lines starting with # are skipped.
  • step and the range can come in either order. A slider's minimum must be below its maximum, and a default outside a slider's or number's range is an error. Without step, a slider moves by 1 when its ends and default are whole numbers at least 2 apart, else by a hundredth of its range.
  • A quoted text value takes JSON escapes.
  • A bad line shows its error in the card and never breaks the rest of the page.

The fence holds only the default. Moving a slider never rewrites the page; the live value is saved beside it (see Saved outputs). The number and text fields take a value as soon as you type one they accept; a value out of range or not a number turns the field red and keeps your text. ↩ or ⎋ leaves the field.

Input names

A name is letters, digits and _, not starting with a digit. It can't be:

  • a keyword of Python or JavaScript (class, in, let, new…),
  • a helper (display, table, chart) or a name starting with __,
  • a name the kernels and shells need: process, require, module, exports, global, globalThis, console, Buffer, JSON, Math, Object, Array, String, Number, Boolean, Symbol, Promise, Error, Date, Map, Set, crypto, navigator, performance, print, len, range, list, dict, str, int, float, input, open, max, min, sum, sorted, abs, round, zip, map, filter, any, all, set, tuple, bool, PATH, HOME, SHELL, PWD, IFS, USER, TMPDIR, LANG.

A name declared twice on a page is refused on its later line.

How inputs re-run cells

Each input is a variable in every cell: n in Python and JavaScript, $n in a shell cell (a toggle as true or false). A whole number arrives as an integer, so range(n) works with a whole-number slider.

Changing an input re-runs, in page order, every cell that uses it, then every later cell of the same language that uses a name those cells define. Dragging a slider doesn't queue a run per step: a re-run still waiting is replaced by one with the newest values. If a kernel hasn't run yet, or was restarted, its earlier cells run first so the dependent cell finds what they define.

Keep slow setup in its own cell that doesn't mention any input, so it doesn't re-run on every change. A kernel runs one cell at a time, so a slow cell holds up everything queued behind it.

Example

markdown
```input
slider n 2..60 = 12   # Points
toggle squared = false
```

```python
import math
xs = list(range(n))
ys = [math.sin(x / 3) ** (2 if squared else 1) for x in xs]
chart.line(xs, {"sin": ys}, title=f"{n} points")
```

Drag the slider and the chart redraws.

Saved outputs

Outputs and input values are saved beside the page, in .outputs/PAGE.json in the notebook folder (notes.md → .outputs/notes.md.json). The file holds the live input values and each cell's last run: its outputs, execution count, time, and a hash of the code it ran.

  • Reopening the tab shows them again. A cell whose code changed since shows its old outputs with the stale tag.
  • Renaming the page moves its outputs file.
  • .outputs/ is hidden: it is never listed as a page, and a notebook never writes the page file itself.
  • Each cell keeps at most 256 KB of text (an error is always kept), 16 images of up to 4 MB each, and 16 charts. Preview shows up to 300 lines of each output.

Warning: Outputs are saved in plain text. Don't print tokens, keys or environment variables in a cell.

Palette and keyboard

The command palette (⇧⌘P) lists Run all cells, Restart kernel and Clear outputs. They act on the shown page of the focused Notes tab, in Preview. They are unbound by default; bind them in Settings › Keyboard as keyboard.run_all_cells, keyboard.restart_kernel and keyboard.clear_outputs (see Keybindings).

From the command line

These act on the shown page of the session's Notes tab (its focused one, else its first). Add --group NAME for another session.

sh
# Run cell 0 (cells count from 0, in page order)
flow-cli notes-run-cell 0

# Set an input as its control would; dependent cells re-run
flow-cli notes-set-input n 40
flow-cli notes-set-input title hello world

# The page's cells, inputs and kernels as JSON
flow-cli read notebook

# The palette actions, on the focused Notes tab
flow-cli action run_all_cells

notes-set-input reads the value as a JSON literal when it is one (40, true), else as text. read notebook returns each cell's ordinal, language, status (idle, queued or running), execution count, stale, ok, time and a summary of its outputs, plus the inputs with their current values, any bad input lines, the kernels and the outputs file. All of these refuse while the experiment is off or the session has no Notes tab. See flow-cli.

The Flow agent has a built-in notebooks skill that knows the helpers, the input syntax and this loop, so you can ask it to build an interactive page. See Agent skills.

Security and privacy

Code runs as you, in your repository, with your environment and network access. A notebook is as trusted as any script you run in a terminal. Flow never logs a cell's code, its outputs or an input's value.

Limits

  • Cells run only in Preview, and only in the Notes tab. Notes cards in a Files tab show fences as code.
  • Cells don't run on a page of a notebook that lives on another Mac (see Notes).
  • No package is guaranteed: cells use whatever python3 and node your PATH finds, with the packages installed for them.
Sources

Written from these files in the Flow app repo

  • docs/notebooks.md
  • src/notebook.rs
  • src/notebook_kernel.rs
  • src/notebook_ui.rs
  • src/notebook/kernel.py
  • src/notebook/kernel.js
  • agent-skills/notebooks/SKILL.md
  • src/features.rs
  • src/notes_ui.rs
  • src/pages.rs
  • src/bus.rs
  • src/bin/flow-cli.rs