Skip to content

Capture console outputs

You can capture console outputs with marimo utility functions. Learn more in the API reference.

Source code for examples/outputs/capture_console_outputs.py

Tip: paste this code into an empty cell, and the marimo editor will create cells for you

import marimo

__generated_with = "0.12.9"
app = marimo.App()


@app.cell
def _():
    import marimo as mo
    return (mo,)


@app.cell
def _(mo):
    with mo.capture_stdout() as output:
        print("Hello, world")

    mo.md(output.getvalue())
    return (output,)


if __name__ == "__main__":
    app.run()