MCPcopy
hub / github.com/marimo-team/marimo / preview

Function preview

marimo/_cli/development/commands.py:731–874  ·  view source on GitHub ↗

Preview a marimo file as static HTML. Creates a static HTML export of the marimo file and serves it on a simple HTTP server for preview purposes. Example usage: marimo development preview my_notebook.py marimo development preview my_notebook.py --port 8000

(file_path: Path, port: int, host: str, headless: bool)

Source from the content-addressed store, hash-verified

729 help="Don't automatically open the browser",
730)
731def preview(file_path: Path, port: int, host: str, headless: bool) -> None:
732 """
733 Preview a marimo file as static HTML.
734
735 Creates a static HTML export of the marimo file and serves it
736 on a simple HTTP server for preview purposes.
737
738 Example usage:
739 marimo development preview my_notebook.py
740 marimo development preview my_notebook.py --port 8000
741 """
742 import threading
743 import webbrowser
744
745 import uvicorn
746 from starlette.applications import Starlette
747 from starlette.responses import HTMLResponse
748 from starlette.routing import Route
749 from starlette.staticfiles import StaticFiles
750
751 from marimo._ast.app_config import _AppConfig
752 from marimo._config.config import DEFAULT_CONFIG
753 from marimo._server.templates.templates import static_notebook_template
754 from marimo._server.tokens import SkewProtectionToken
755 from marimo._utils.paths import marimo_package_path
756
757 if TYPE_CHECKING:
758 from starlette.requests import Request
759
760 try:
761 # Run the notebook to get actual outputs
762 click.echo(f"Running notebook {file_path.name}...")
763 from marimo._server.export import run_app_until_completion
764 from marimo._server.utils import asyncio_run
765 from marimo._session.notebook import load_notebook
766 from marimo._session.state.serialize import (
767 serialize_notebook,
768 serialize_session_view,
769 )
770 from marimo._utils.code import hash_code
771
772 # Create file manager for the notebook
773 file_manager = load_notebook(file_path)
774
775 # Run the notebook to completion and get session view
776 session_view, did_error = asyncio_run(
777 run_app_until_completion(
778 file_manager,
779 cli_args={},
780 argv=None,
781 )
782 )
783 if did_error:
784 click.echo(
785 "Warning: Some cells had errors during execution", err=True
786 )
787
788 # Create session snapshot from the executed session

Callers

nothing calls this directly

Calls 15

load_notebookFunction · 0.90
asyncio_runFunction · 0.90
run_app_until_completionFunction · 0.90
serialize_session_viewFunction · 0.90
serialize_notebookFunction · 0.90
marimo_package_pathFunction · 0.90
static_notebook_templateFunction · 0.90
SkewProtectionTokenClass · 0.90
_AppConfigClass · 0.90
hash_codeFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…