Cell outputs#

Cell outputs

Every cell in a marimo notebook can have a visual output. When editing, outputs are displayed above cells. When running a notebook as an app, its UI is an arrangement of outputs.

A cell’s output is by default its last expression. You can also create outputs programmatically, using mo.output.replace() and mo.output.append().

marimo.output.replace(value: object) None#

Replace a cell’s output with a new one.

Call mo.output.replace() to write to a cell’s output area, replacing the existing output, if any.


  • value: object to output

marimo.output.append(value: object) None#

Append a new object to a cell’s output.

Call this function to incrementally build a cell’s output. Appended outputs are stacked vertically.


  • value: object to output

marimo.output.clear() None#

Clear a cell’s output.

Last expression replaces existing output

Ending a cell with a non-None expression is the same as calling mo.output.replace() on it: the last expression replaces any output you may have already written. Wrap the last expression in mo.output.append if you want to add to an existing output instead of replacing it.

Console outputs#

Console outputs

Text written to stdout/stderr, including print statements and logs, shows up in a console output area below a cell.

By default, these console outputs don’t appear when running a marimo notebook as an app. If you do want them to appear in apps, marimo provides utility functions for capturing console outputs and redirecting them to cell outputs.

marimo.redirect_stdout() Iterator[None]#

Redirect stdout to a cell’s output area.

with mo.redirect_stdout():
    # These print statements will show up in the cell's output area
marimo.redirect_stderr() Iterator[None]#

Redirect stderr to a cell’s output area.

with mo.redirect_stderr():
    # These messages will show up in the cell's output area
marimo.capture_stdout() Iterator[StringIO]#

Capture standard output.

Use this context manager to capture print statements and other output sent to standard output.


with mo.capture_stdout() as buffer:
output = buffer.getvalue()
marimo.capture_stderr() Iterator[StringIO]#

Capture standard error.

Use this context manager to capture output sent to standard error.


with mo.capture_stderr() as buffer:
output = buffer.getvalue()