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
feat: show network url when running host=0.0.0.0 (#3128)
Myles Scolnick8dad232adc32
diff --git a/marimo/_cli/sandbox.py b/marimo/_cli/sandbox.pyindex dfe6a5b0bf..b69b3a8360 100644--- a/marimo/_cli/sandbox.py+++ b/marimo/_cli/sandbox.py@@ -183,8 +183,7 @@ def prompt_run_in_sandbox(name: str | None) -> bool:"This notebook has inlined package dependencies.\n"+ green("Run in a sandboxed venv containing this notebook's "- "dependencies?",- bold=True,+ "dependencies?"),default=True,)diff --git a/marimo/_server/api/lifespans.py b/marimo/_server/api/lifespans.pyindex 23abadce18..b781efd002 100644--- a/marimo/_server/api/lifespans.py+++ b/marimo/_server/api/lifespans.py@@ -109,10 +109,11 @@ async def logging(app: Starlette) -> AsyncIterator[None]:if not manager.quiet:file = file_router.maybe_get_single_file()print_startup(- file.name if file else None,- _startup_url(state),- manager.mode == SessionMode.RUN,+ file_name=file.name if file else None,+ url=_startup_url(state),+ run=manager.mode == SessionMode.RUN,new=file_router.get_unique_file_key() == AppFileRouter.NEW_FILE,+ network=state.host == "0.0.0.0",)yielddiff --git a/marimo/_server/print.py b/marimo/_server/print.pyindex 92bc069327..d35bd7ad2b 100644--- a/marimo/_server/print.py+++ b/marimo/_server/print.py@@ -5,6 +5,7 @@ import osimport sysfrom typing import Optional+from marimo._cli.print import bold, green, mutedfrom marimo._server.utils import print_, print_tabbedUTF8_SUPPORTED = False@@ -17,31 +18,31 @@ except Exception:def print_startup(- file_name: Optional[str], url: str, run: bool, new: bool+ *, file_name: Optional[str], url: str, run: bool, new: bool, network: bool) -> None:print_()if file_name is not None and not run:print_tabbed(- f"\033[1;32mEdit {os.path.basename(file_name)} "- "in your browser\033[0m " + _utf8("📝")+ f"{green(f'Edit {os.path.basename(file_name)} in your browser', bold=True)} {_utf8('📝')}")elif file_name is not None and run:print_tabbed(- f"\033[1;32mRunning {os.path.basename(file_name)}"- "\033[0m " + _utf8("⚡")+ f"{green(f'Running {os.path.basename(file_name)}', bold=True)} {_utf8('⚡')}")elif new:print_tabbed(- "\033[1;32mCreate a new notebook in your browser\033[0m "- + _utf8("📝")+ f"{green('Create a new notebook in your browser', bold=True)} {_utf8('📝')}")else:print_tabbed(- "\033[1;32mCreate or edit notebooks in your "- "browser\033[0m " + _utf8("📝")+ f"{green('Create or edit notebooks in your browser', bold=True)} {_utf8('📝')}")print_()- print_tabbed(f"\033[32mURL\033[0m: \033[1m{url}\033[0m")+ print_tabbed(f"➜ {green('URL')}: {_colorized_url(url)}")+ if network:+ print_tabbed(+ f"➜ {green('Network')}: {_colorized_url(_get_network_url(url))}"+ )print_()@@ -51,5 +52,35 @@ def print_shutdown() -> None:print_()+def _get_network_url(url: str) -> str:+ import socket++ hostname = socket.gethostname()+ local_ip = socket.gethostbyname(hostname)++ # Replace the host part of the URL with the local IP+ from urllib.parse import urlparse, urlunparse++ parsed_url = urlparse(url)+ new_netloc = local_ip + (f":{parsed_url.port}" if parsed_url.port else "")+ new_url = urlunparse(parsed_url._replace(netloc=new_netloc))++ return new_url+++def _colorized_url(url_string: str) -> str:+ from urllib.parse import urlparse++ url = urlparse(url_string)+ if url.query:+ query = muted(f"?{url.query}")+ else:+ query = ""++ return bold(+ f"{url.scheme}://{url.hostname}:{url.port}{url.path}{query}",+ )++def _utf8(msg: str) -> str:return msg if UTF8_SUPPORTED else ""