Skip to content

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.

feat: add BrowserConfig to UserConfig (#269)

Akshay Agrawalf09be40384ee
diff --git a/marimo/_config/config.py b/marimo/_config/config.py
index 2ebb995470..9d36b18a12 100644
--- a/marimo/_config/config.py
+++ b/marimo/_config/config.py
@@ -83,12 +83,24 @@ class DisplayConfig(TypedDict, total=False):
**Keys.**
- - `theme`: one of `"light"` or `"dark"`
+ - `theme`: `"light"` or `"dark"`
"""
theme: Literal["light", "dark"]
+class ServerConfig(TypedDict, total=False):
+ """Configuration for the server.
+
+ **Keys.**
+
+ - `browser`: the web browser to use. `"default"` or a browser registered
+ with Python's webbrowser module (eg, `"firefox"` or `"chrome"`)
+ """
+
+ browser: Literal["default"] | str
+
+
@mddoc
class MarimoConfig(TypedDict, total=False):
"""Configuration for the marimo editor.
@@ -107,33 +119,28 @@ class MarimoConfig(TypedDict, total=False):
"completion": {"activate_on_typing": True},
}
```
-
- **Keys.**
-
- - `completion`: a `CompletionConfig`
- - `save`: a `SaveConfig`
- - `keymap`: a `KeymapConfig`
- - `experimental`: a `dict` of experimental features
"""
completion: CompletionConfig
- save: SaveConfig
+ display: DisplayConfig
keymap: KeymapConfig
runtime: RuntimeConfig
- display: DisplayConfig
+ save: SaveConfig
+ server: ServerConfig
experimental: Dict[str, Any]
DEFAULT_CONFIG: MarimoConfig = {
"completion": {"activate_on_typing": True, "copilot": False},
+ "display": {"theme": "light"},
+ "keymap": {"preset": "default"},
+ "runtime": {"auto_instantiate": True},
"save": {
"autosave": "after_delay",
"autosave_delay": 1000,
"format_on_save": False,
},
- "keymap": {"preset": "default"},
- "runtime": {"auto_instantiate": True},
- "display": {"theme": "light"},
+ "server": {"browser": "default"},
}
_USER_CONFIG: Optional[MarimoConfig] = None
diff --git a/marimo/_server/server.py b/marimo/_server/server.py
index ed83d0d96f..c98fa613b5 100644
--- a/marimo/_server/server.py
+++ b/marimo/_server/server.py
@@ -318,13 +318,15 @@ async def start_server(
logger.fatal(type(e).__name__ + ": " + str(e))
shutdown(with_error=True)
- if not run and get_configuration()["completion"]["copilot"]:
+ user_config = get_configuration()
+ if not run and user_config["completion"]["copilot"]:
logger.debug("GitHub Copilot is enabled")
session_mgr.start_lsp_server()
url = f"http://localhost:{port}"
if not headless:
- if which("xdg-open") is not None:
+ browser = user_config["server"]["browser"]
+ if which("xdg-open") is not None and browser == "default":
with open(os.devnull, "w") as devnull:
if sys.platform == "win32" or sys.platform == "cygwin":
preexec_fn = None
@@ -339,7 +341,11 @@ async def start_server(
stderr=subprocess.STDOUT,
)
else:
- webbrowser.open(url)
+ controller = (
+ webbrowser if browser == "default" else webbrowser.get(browser)
+ )
+ # type ignore: getting an invalid type error
+ controller.open(url) # type:ignore[attr-defined]
if not session_mgr.quiet:
print()