A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
docs: improve AppMeta documentation (#2838)
eugene95169eac86a1
diff --git a/docs/api/app.md b/docs/api/app.mdindex d424db8b82..028a0fe8cd 100644--- a/docs/api/app.md+++ b/docs/api/app.md@@ -5,3 +5,14 @@.. automethod:: marimo.App.embed```++## AppMeta++```{eval-rst}+.. currentmodule:: marimo++.. autoclass:: app_meta()++ .. autofunction:: marimo._runtime.app_meta.AppMeta.theme+ .. autofunction:: marimo._runtime.app_meta.AppMeta.mode+```diff --git a/marimo/_runtime/app_meta.py b/marimo/_runtime/app_meta.pyindex 41cb84e527..3e0b8e87a1 100644--- a/marimo/_runtime/app_meta.py+++ b/marimo/_runtime/app_meta.py@@ -11,8 +11,8 @@ class AppMeta:"""Metadata about the app.- This is used to store metadata about the app- that is not part of the app's code or state.+ This class provides access to runtime metadata about a marimo app, such as+ its display theme and execution mode."""def __init__(self) -> None:@@ -20,7 +20,28 @@ class AppMeta:@propertydef theme(self) -> str:- """The display theme of the app."""+ """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:++ ```python+ 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+ """theme = self.user_config["display"]["theme"] or "light"if theme == "system":# TODO(mscolnick): have frontend tell the backend the system theme@@ -29,5 +50,22 @@ class AppMeta:@propertydef mode(self) -> Optional[Literal["edit", "run", "script"]]:- """The mode of the app (edit/run/script) or None."""+ """The execution mode of the app.++ **Examples**:++ Show content only in edit mode:++ ```python+ # 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+ """return get_mode()diff --git a/marimo/_runtime/runtime.py b/marimo/_runtime/runtime.pyindex 5b84b8f24e..79c5206c9f 100644--- a/marimo/_runtime/runtime.py+++ b/marimo/_runtime/runtime.py@@ -243,10 +243,25 @@ def query_params() -> QueryParams:def app_meta() -> AppMeta:"""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**:- ```python3- theme = mo.app_meta().theme+ Get the current theme and conditionally set a plotting library's theme:++ ```python+ 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:++ ```python+ # Only show this content when editing the notebook+ mo.md("# Developer Notes") if mo.app_meta().mode == "edit" else None```**Returns**: