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

Function get_context

marimo/_code_mode/_context.py:201–238  ·  view source on GitHub ↗

Return an `AsyncCodeModeContext` for the running kernel. Use as an async context manager:: async with cm.get_context() as ctx: ctx.create_cell("x = 1") Parameters ---------- skip_validation : bool, default False When False (the default), a dry-run compi

(
    *,
    skip_validation: bool = False,
    skip_staleness_check: bool = False,
)

Source from the content-addressed store, hash-verified

199
200
201def get_context(
202 *,
203 skip_validation: bool = False,
204 skip_staleness_check: bool = False,
205) -> AsyncCodeModeContext:
206 """Return an `AsyncCodeModeContext` for the running kernel.
207
208 Use as an async context manager::
209
210 async with cm.get_context() as ctx:
211 ctx.create_cell("x = 1")
212
213 Parameters
214 ----------
215 skip_validation : bool, default False
216 When False (the default), a dry-run compile check runs on exit
217 to catch syntax errors, multiply-defined names, and cycles
218 *before* any graph mutations are applied. The check is cheap
219 and should almost never be disabled. Only set to True when you
220 intentionally need to insert code that would fail validation
221 (e.g. incomplete stubs the user plans to fix by hand).
222 skip_staleness_check : bool, default False
223 When False (the default), `edit_cell` raises
224 :class:`StaleCellError` if the agent tries to overwrite a cell
225 whose code has changed since the agent last read it (e.g. via
226 `ctx.cells[cell_id].code`). Set to True to overwrite blindly —
227 useful when the agent intentionally discards prior content.
228 """
229 runtime_ctx = _get_runtime_context()
230 if not isinstance(runtime_ctx, KernelRuntimeContext):
231 raise RuntimeError("code mode requires a running kernel context")
232 cell_manager = runtime_ctx._app.cell_manager if runtime_ctx._app else None
233 return AsyncCodeModeContext(
234 runtime_ctx._kernel,
235 cell_manager=cell_manager,
236 skip_validation=skip_validation,
237 skip_staleness_check=skip_staleness_check,
238 )
239
240
241class StaleCellError(RuntimeError):

Callers 15

traceMethod · 0.90
__exit__Method · 0.90
_cell_filenameMethod · 0.90
contextual_defsMethod · 0.90
create_or_reconfigureMethod · 0.90
__init__Method · 0.90
_load_filenameMethod · 0.90
_hypertext_cleanupFunction · 0.90
__init__Method · 0.90
show_codeFunction · 0.90
get_formatterFunction · 0.90

Calls 1

Used in the wild real call sites across dependent graphs

searching dependent graphs…