App¶
- class marimo.App(**kwargs: Any)¶
A marimo notebook.
A marimo notebook is a dataflow graph, with each node computing a Python function.
- async embed() AppEmbedResult ¶
Embed a notebook into another notebook.
The
embed
method lets you embed the output of a notebook into another notebook and access the values of its variables.Example.
from my_notebook import app
# execute the notebook result = await app.embed()
# view the notebook's visual output result.output
# access the notebook's defined variables result.defs
Running
await app.embed()
executes the notebook and results an object encapsulating the notebook visual output and its definitions.Embedded notebook outputs are interactive: when you interact with UI elements in an embedded notebook’s output, any cell referring to the
app
object is marked for execution, and its internal state is automatically updated. This lets you use notebooks as building blocks or components to create higher-level notebooks.Multiple levels of nesting are supported: it’s possible to embed a notebook that in turn embeds another notebook, and marimo will do the right thing.
Returns.
An object
result
with two attributes:result.output
(visual output of the notebook) andresult.defs
(a dictionary mapping variable names defined by the notebook to their values).
AppMeta¶
- class marimo.app_meta¶
Get the metadata of a marimo app.
The
AppMeta
class provides access to runtime metadata about a marimo app, such as its display theme and execution mode.Examples:
Get the current theme and conditionally set a plotting library’s theme:
import altair as alt # Enable dark theme for Altair when marimo is in dark mode alt.themes.enable("dark" if mo.app_meta().theme == "dark" else "default")
Show content only in edit mode:
# Only show this content when editing the notebook mo.md("# Developer Notes") if mo.app_meta().mode == "edit" else None
Returns:
An
AppMeta
object containing the app’s metadata.
- theme()¶
The display theme of the app.
Returns either “light” or “dark”. If the user’s configuration is set to “system”, currently returns “light”.
Examples:
Get the current theme and conditionally set a plotting library’s theme:
import altair as alt # Enable dark theme for Altair when marimo is in dark mode alt.themes.enable( "dark" if mo.app_meta().theme == "dark" else "default" )
Returns:
“light” or “dark”, indicating the app’s display theme
- mode()¶
The execution mode of the app.
Examples:
Show content only in edit mode:
# Only show this content when editing the notebook mo.md("# Developer Notes") if mo.app_meta().mode == "edit" else None
Returns:
“edit”: The notebook is being edited in the marimo editor
“run”: The notebook is being run as an app
“script”: The notebook is being run as a script
None: The mode could not be determined