Commit 1e5a7bf
Add internal code mode module for programmatic notebook control (marimo-team#8670)
This introduces `marimo._code_mode`, an internal agent-only API that
gives programmatic access to a running marimo notebook. The motivating
use case is letting agents (e.g. from a scratchpad) insert, delete,
replace, and reorder cells without going through the frontend UI. e.g.,
```python
import marimo._code_mode as cm
async with cm.get_context() as ctx:
# Install packages (queued, installed before cell ops)
ctx.install_packages("pandas", "polars>=0.20")
# Cell ops (appends at end by default)
cid = ctx.create_cell("import pandas as pd")
ctx.create_cell("df = pd.DataFrame()", after=cid)
ctx.create_cell("setup()", before=cid, hide_code=True, disabled=True)
ctx.update_cell("my_cell", code="x = 42")
ctx.update_cell("other", hide_code=False, disabled=True)
ctx.delete_cell("old_cell")
ctx.move_cell("my_cell", after="other_cell")
# Set UI element values (batched)
ctx.set_ui_value(slider, 10)
# Dry-run compile check is on by default; disable with:
async with cm.get_context(check=False) as ctx:
...
```
---------
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>1 parent 9dd70d2 commit 1e5a7bf
18 files changed
Lines changed: 2268 additions & 26 deletions
File tree
- marimo
- _code_mode
- _messaging
- _runtime
- dataflow
- _server
- api/endpoints
- _session
- tests
- _code_mode
- _messaging
- _server
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
0 commit comments