@@ -186,6 +186,16 @@ def configure(self, update: dict[str, Any] | CellConfig) -> CellImpl:
186
186
187
187
@property
188
188
def runtime_state (self ) -> Optional [RuntimeStateType ]:
189
+ """Gets the current runtime state of the cell.
190
+
191
+ Returns:
192
+ Optional[RuntimeStateType]: The current state, one of:
193
+ - "idle": cell has run with latest inputs
194
+ - "queued": cell is queued to run
195
+ - "running": cell is running
196
+ - "disabled-transitively": cell is disabled because a parent is disabled
197
+ - None: state not set
198
+ """
189
199
return self ._status .state
190
200
191
201
@property
@@ -194,7 +204,11 @@ def run_result_status(self) -> Optional[RunResultStatusType]:
194
204
195
205
@property
196
206
def sqls (self ) -> list [str ]:
197
- """Return a list of SQL statements for this cell."""
207
+ """Returns parsed SQL statements from this cell.
208
+
209
+ Returns:
210
+ list[str]: List of SQL statement strings parsed from the cell code.
211
+ """
198
212
if self ._sqls .parsed is not None :
199
213
return self ._sqls .parsed
200
214
@@ -257,7 +271,12 @@ def is_coroutine(self) -> bool:
257
271
def set_runtime_state (
258
272
self , status : RuntimeStateType , stream : Stream | None = None
259
273
) -> None :
260
- """Set execution status and broadcast to frontends."""
274
+ """Sets the cell's execution status and broadcasts to frontends.
275
+
276
+ Args:
277
+ status (RuntimeStateType): New runtime state to set
278
+ stream (Stream | None, optional): Stream to broadcast on. Defaults to None.
279
+ """
261
280
from marimo ._messaging .ops import CellOp
262
281
from marimo ._runtime .context import (
263
282
ContextNotInitializedError ,
@@ -405,103 +424,104 @@ def run(
405
424
tuple [Any , Mapping [str , Any ]]
406
425
| Awaitable [tuple [Any , Mapping [str , Any ]]]
407
426
):
408
- """Run this cell and return its visual output and definitions
427
+ """
428
+ Run this cell and return its visual output and definitions.
409
429
410
430
Use this method to run **named cells** and retrieve their output and
411
- definitions.
412
-
413
- This lets you use reuse cells defined in one notebook in another
431
+ definitions. This lets you reuse cells defined in one notebook in another
414
432
notebook or Python file. It also makes it possible to write and execute
415
433
unit tests for notebook cells using a test framework like `pytest`.
416
434
417
- **Example.** marimo cells can be given names either through the
418
- editor cell menu or by manually changing the function name in the
419
- notebook file. For example, consider a notebook `notebook.py`:
420
-
421
- ```python
422
- import marimo
435
+ Examples:
436
+ marimo cells can be given names either through the editor cell menu
437
+ or by manually changing the function name in the notebook file. For
438
+ example, consider a notebook `notebook.py`:
423
439
424
- app = marimo.App()
440
+ ```python
441
+ import marimo
425
442
443
+ app = marimo.App()
426
444
427
- @app.cell
428
- def __():
429
- import marimo as mo
430
445
431
- return (mo,)
446
+ @app.cell
447
+ def __():
448
+ import marimo as mo
432
449
450
+ return (mo,)
433
451
434
- @app.cell
435
- def __():
436
- x = 0
437
- y = 1
438
- return (x, y)
439
452
453
+ @app.cell
454
+ def __():
455
+ x = 0
456
+ y = 1
457
+ return (x, y)
440
458
441
- @app.cell
442
- def add(mo, x, y):
443
- z = x + y
444
- mo.md(f"The value of z is {z}")
445
- return (z,)
446
459
460
+ @app.cell
461
+ def add(mo, x, y):
462
+ z = x + y
463
+ mo.md(f"The value of z is {z}")
464
+ return (z,)
447
465
448
- if __name__ == "__main__":
449
- app.run()
450
- ```
451
466
452
- To reuse the `add` cell in another notebook, you'd simply write
467
+ if __name__ == "__main__":
468
+ app.run()
469
+ ```
453
470
454
- ```python
455
- from notebook import add
471
+ To reuse the `add` cell in another notebook, you'd simply write:
456
472
457
- # `output` is the markdown rendered by `add`
458
- # defs["z"] == `1`
459
- output, defs = add.run()
460
- ```
473
+ ```python
474
+ from notebook import add
461
475
462
- When `run ` is called without arguments, it automatically computes the
463
- values that the cell depends on (in this case, `mo`, `x`, and `y`). You
464
- can override these values by providing any subset of them as keyword
465
- arguments. For example,
476
+ # `output ` is the markdown rendered by `add`
477
+ # defs["z"] == `1`
478
+ output, defs = add.run()
479
+ ```
466
480
467
- ```python
468
- # defs["z"] == 4
469
- output, defs = add.run(x=2, y=2)
470
- ```
481
+ When `run` is called without arguments, it automatically computes
482
+ the values that the cell depends on (in this case, `mo`, `x`, and
483
+ `y`). You can override these values by providing any subset of them
484
+ as keyword arguments. For example,
471
485
472
- **Defined UI Elements.** If the cell's `output` has UI elements
473
- that are in `defs`, interacting with the output in the frontend will
474
- trigger reactive execution of cells that reference the `defs` object.
475
- For example, if `output` has a slider defined by the cell, then
476
- scrubbing the slider will cause cells that reference `defs` to run.
486
+ ```python
487
+ # defs["z"] == 4
488
+ output, defs = add.run(x=2, y=2)
489
+ ```
477
490
478
- **Async cells.** If this cell is a coroutine function (starting with
479
- `async`), or if any of its ancestors are coroutine functions, then
480
- you'll need to `await` the result: `output, defs = await cell.run()`.
481
- You can check whether the result is an awaitable using:
491
+ Defined UI Elements:
492
+ If the cell's `output` has UI elements that are in `defs`, interacting
493
+ with the output in the frontend will trigger reactive execution of
494
+ cells that reference the `defs` object. For example, if `output` has
495
+ a slider defined by the cell, then scrubbing the slider will cause
496
+ cells that reference `defs` to run.
482
497
483
- ```python
484
- from collections.abc import Awaitable
485
-
486
- ret = cell.run()
487
- if isinstance(ret, Awaitable):
488
- output, defs = await ret
489
- else:
490
- output, defs = ret
491
- ```
498
+ Async cells:
499
+ If this cell is a coroutine function (starting with `async`), or if
500
+ any of its ancestors are coroutine functions, then you'll need to
501
+ `await` the result: `output, defs = await cell.run()`. You can check
502
+ whether the result is an awaitable using:
492
503
493
- **Arguments**:
504
+ ```python
505
+ from collections.abc import Awaitable
494
506
495
- - You may pass values for any of this cell's references as keyword
496
- arguments. marimo will automatically compute values for any refs
497
- that are not provided by executing the parent cells that compute
498
- them.
507
+ ret = cell.run()
508
+ if isinstance(ret, Awaitable):
509
+ output, defs = await ret
510
+ else:
511
+ output, defs = ret
512
+ ```
499
513
500
- **Returns**:
514
+ Args:
515
+ **kwargs (Any):
516
+ You may pass values for any of this cell's references as keyword
517
+ arguments. marimo will automatically compute values for any refs
518
+ that are not provided by executing the parent cells that compute
519
+ them.
501
520
502
- - a tuple `(output, defs)`, or an awaitable of the same, where `output`
503
- is the cell's last expression and `defs` is a `Mapping` from the
504
- cell's defined names to their values.
521
+ Returns:
522
+ tuple `(output, defs)`, or an awaitable of the same:
523
+ `output` is the cell's last expression and `defs` is a `Mapping`
524
+ from the cell's defined names to their values.
505
525
"""
506
526
assert self ._app is not None
507
527
if self ._is_coroutine ():
0 commit comments