MCPcopy
hub / github.com/marimo-team/marimo / edit_cell

Method edit_cell

marimo/_code_mode/_context.py:1116–1240  ·  view source on GitHub ↗

Queue an update to an existing cell's code and/or config. Only the arguments you explicitly pass are changed — the cell's existing config is preserved for any argument left as `None`. Editing a cell does not automatically execute it. Use `run_cell` to queue it for e

(
        self,
        target: str,
        code: str | None = None,
        *,
        hide_code: bool | None = None,
        disabled: bool | None = None,
        column: int | None = None,
        name: str | None = None,
    )

Source from the content-addressed store, hash-verified

1114 return cell_id
1115
1116 def edit_cell(
1117 self,
1118 target: str,
1119 code: str | None = None,
1120 *,
1121 hide_code: bool | None = None,
1122 disabled: bool | None = None,
1123 column: int | None = None,
1124 name: str | None = None,
1125 ) -> None:
1126 """Queue an update to an existing cell's code and/or config.
1127
1128 Only the arguments you explicitly pass are changed — the cell's
1129 existing config is preserved for any argument left as `None`.
1130
1131 Editing a cell does not automatically execute it. Use `run_cell`
1132 to queue it for execution::
1133
1134 ctx.edit_cell("my_cell", "x = 42")
1135 ctx.run_cell("my_cell")
1136
1137 Examples:
1138 ```python
1139 # Update only code (config like hide_code is preserved)
1140 ctx.edit_cell("data_loader", "df = pd.read_parquet('new.parquet')")
1141
1142 # Update only config (code is preserved)
1143 ctx.edit_cell("data_loader", hide_code=False)
1144
1145 # Update both code and config
1146 ctx.edit_cell("data_loader", "df = load()", disabled=True)
1147
1148 # Edit and run
1149 ctx.edit_cell("my_cell", "new_code()")
1150 ctx.run_cell("my_cell")
1151
1152 # Rename a cell
1153 ctx.edit_cell("old_name", name="new_name")
1154 ```
1155
1156 Args:
1157 target (str): Cell ID or cell name.
1158 code (str, optional): New Python source code. None keeps existing.
1159 hide_code (bool, optional): Collapse the code editor. None keeps existing.
1160 disabled (bool, optional): Prevent the cell from executing. None keeps existing.
1161 column (int, optional): Column index for multi-column layouts. None keeps existing.
1162 name (str, optional): New name for the cell. None keeps existing.
1163 """
1164 self._require_entered()
1165 cell_id = self._resolve_target(target)
1166
1167 # Handle cell-id migration when converting to a setup cell.
1168 # Setup is identified by cell_id, not name — clear the name
1169 # and migrate to the well-known setup cell_id.
1170 new_cell_id: CellId_t | None = None
1171 if name == SETUP_CELL_NAME:
1172 setup_id = (
1173 self._cell_manager.setup_cell_id

Calls 11

_require_enteredMethod · 0.95
_resolve_targetMethod · 0.95
CellConfigClass · 0.90
_UpdateOpClass · 0.90
StaleCellErrorClass · 0.85
stripMethod · 0.80
has_readMethod · 0.80
get_stale_cellsMethod · 0.80
getMethod · 0.65
_resolveMethod · 0.45
appendMethod · 0.45