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: allow auto download to be configured globally (#5647)
Dylan Madisetti67cad9a06a34
diff --git a/marimo/_ast/app_config.py b/marimo/_ast/app_config.pyindex 89afa38dff..3e4050c659 100644--- a/marimo/_ast/app_config.py+++ b/marimo/_ast/app_config.py@@ -2,10 +2,10 @@import osfrom dataclasses import asdict, dataclass, field-from typing import Any, Literal, Optional+from typing import Any, Optionalfrom marimo import _loggers-from marimo._config.config import SqlOutputType, WidthType+from marimo._config.config import ExportType, SqlOutputType, WidthTypeLOGGER = _loggers.marimo_logger()@@ -32,9 +32,7 @@ class _AppConfig:html_head_file: Optional[str] = None# Whether to automatically download the app as HTML and Markdown- auto_download: list[Literal["html", "markdown", "ipynb"]] = field(- default_factory=list- )+ auto_download: list[ExportType] = field(default_factory=list)# The type of SQL output to displaysql_output: SqlOutputType = "auto"diff --git a/marimo/_config/config.py b/marimo/_config/config.pyindex 352519e19f..b711d8e3cd 100644--- a/marimo/_config/config.py+++ b/marimo/_config/config.py@@ -95,6 +95,14 @@ OnCellChangeType = Literal["lazy", "autorun"]ExecutionType = Literal["relaxed", "strict"]+# TODO(akshayka): remove normal, migrate to compact+# normal == compact+WidthType = Literal["normal", "compact", "medium", "full", "columns"]+Theme = Literal["light", "dark", "system"]+ExportType = Literal["html", "markdown", "ipynb"]+SqlOutputType = Literal["polars", "lazy-polars", "pandas", "native", "auto"]++@mddoc@dataclassclass RuntimeConfig(TypedDict):@@ -133,6 +141,9 @@ class RuntimeConfig(TypedDict):- `default_sql_output`: the default output format for SQL queries. Can be one of:`"auto"`, `"native"`, `"polars"`, `"lazy-polars"`, or `"pandas"`.The default is `"auto"`.+ - `default_auto_download`: an Optional list of export types to automatically snapshot your notebook as:+ `html`, `markdown`, `ipynb`.+ The default is None."""auto_instantiate: bool@@ -145,13 +156,7 @@ class RuntimeConfig(TypedDict):pythonpath: NotRequired[list[str]]dotenv: NotRequired[list[str]]default_sql_output: SqlOutputType---# TODO(akshayka): remove normal, migrate to compact-# normal == compact-WidthType = Literal["normal", "compact", "medium", "full", "columns"]-Theme = Literal["light", "dark", "system"]-SqlOutputType = Literal["polars", "lazy-polars", "pandas", "native", "auto"]+ default_auto_download: NotRequired[list[ExportType]]@mddocdiff --git a/marimo/_config/manager.py b/marimo/_config/manager.pyindex 8bfba5303a..85bb4a01b0 100644--- a/marimo/_config/manager.py+++ b/marimo/_config/manager.py@@ -11,6 +11,7 @@ from marimo import _loggersfrom marimo._config.config import (DEFAULT_CONFIG,CompletionConfig,+ ExportType,LanguageServersConfig,MarimoConfig,PartialMarimoConfig,@@ -79,6 +80,10 @@ class MarimoConfigReader:def default_width(self) -> WidthType:return self._config["display"]["default_width"]+ @property+ def default_auto_download(self) -> list[ExportType]:+ return self._config["runtime"].get("default_auto_download", [])+@propertydef default_sql_output(self) -> SqlOutputType:return self._config["runtime"]["default_sql_output"]diff --git a/marimo/_server/file_manager.py b/marimo/_server/file_manager.pyindex b1c56856bd..08805fbcc6 100644--- a/marimo/_server/file_manager.py+++ b/marimo/_server/file_manager.py@@ -12,7 +12,7 @@ from marimo._ast import codegen, loadfrom marimo._ast.app import App, InternalAppfrom marimo._ast.app_config import overloads_from_envfrom marimo._ast.cell import CellConfig-from marimo._config.config import SqlOutputType, WidthType+from marimo._config.config import ExportType, SqlOutputType, WidthTypefrom marimo._convert.converters import MarimoConvertfrom marimo._runtime.layout.layout import (LayoutConfig,@@ -37,10 +37,14 @@ class AppFileManager:filename: Optional[Union[str, Path]],*,default_width: WidthType | None = None,+ default_auto_download: list[ExportType] | None = None,default_sql_output: SqlOutputType | None = None,) -> None:self.filename = str(filename) if filename else Noneself._default_width: WidthType | None = default_width+ self._default_auto_download: list[ExportType] | None = (+ default_auto_download+ )self._default_sql_output: SqlOutputType | None = default_sql_outputself.app = self._load_app(self.path)@@ -196,6 +200,8 @@ class AppFileManager:# Add defaults if it is a new fileif self._default_width is not None:kwargs["width"] = self._default_width+ if self._default_auto_download is not None:+ kwargs["auto_download"] = self._default_auto_downloadif self._default_sql_output is not None:kwargs["sql_output"] = self._default_sql_outputdiff --git a/marimo/_server/file_router.py b/marimo/_server/file_router.pyindex bc01be2372..3af452cd3c 100644--- a/marimo/_server/file_router.py+++ b/marimo/_server/file_router.py@@ -9,7 +9,7 @@ from contextlib import contextmanagerfrom typing import TYPE_CHECKING, Optionalfrom marimo import _loggers-from marimo._config.config import SqlOutputType, WidthType+from marimo._config.config import ExportType, SqlOutputType, WidthTypefrom marimo._server.api.status import HTTPException, HTTPStatusfrom marimo._server.file_manager import AppFileManagerfrom marimo._server.files.os_file_system import natural_sort_file@@ -77,16 +77,20 @@ class AppFileRouter(abc.ABC):def get_single_app_file_manager(self,default_width: WidthType | None = None,+ default_auto_download: list[ExportType] | None = None,default_sql_output: SqlOutputType | None = None,) -> AppFileManager:key = self.get_unique_file_key()assert key is not None, "Expected a single file"- return self.get_file_manager(key, default_width, default_sql_output)+ return self.get_file_manager(+ key, default_width, default_auto_download, default_sql_output+ )def get_file_manager(self,key: MarimoFileKey,default_width: WidthType | None = None,+ default_auto_download: list[ExportType] | None = None,default_sql_output: SqlOutputType | None = None,) -> AppFileManager:"""@@ -96,6 +100,7 @@ class AppFileRouter(abc.ABC):return AppFileManager(None,default_width=default_width,+ default_auto_download=default_auto_download,default_sql_output=default_sql_output,)@@ -103,6 +108,7 @@ class AppFileRouter(abc.ABC):return AppFileManager(key,default_width=default_width,+ default_auto_download=default_auto_download,default_sql_output=default_sql_output,)diff --git a/marimo/_server/sessions.py b/marimo/_server/sessions.pyindex b3b8c0a0ac..a478abaae4 100644--- a/marimo/_server/sessions.py+++ b/marimo/_server/sessions.py@@ -785,6 +785,7 @@ class SessionManager:def _get_code() -> str:app = file_router.get_single_app_file_manager(default_width=self._config_manager.default_width,+ default_auto_download=self._config_manager.default_auto_download,default_sql_output=self._config_manager.default_sql_output,).appreturn "".join(code for code in app.cell_manager.codes())@@ -818,6 +819,7 @@ class SessionManager:return self.file_router.get_file_manager(key,default_width=self._config_manager.default_width,+ default_auto_download=self._config_manager.default_auto_download,default_sql_output=self._config_manager.default_sql_output,)@@ -834,6 +836,7 @@ class SessionManager:app_file_manager = self.file_router.get_file_manager(file_key,default_width=self._config_manager.default_width,+ default_auto_download=self._config_manager.default_auto_download,default_sql_output=self._config_manager.default_sql_output,)diff --git a/openapi/api.yaml b/openapi/api.yamlindex db774a35ee..f646a98106 100644--- a/openapi/api.yaml+++ b/openapi/api.yaml@@ -1682,6 +1682,14 @@ components:- lazy- autoruntype: string+ default_auto_download:+ items:+ enum:+ - html+ - markdown+ - ipynb+ type: string+ type: arraydefault_sql_output:enum:- polarsdiff --git a/openapi/src/api.ts b/openapi/src/api.tsindex c36cf6936f..fa89af2c25 100644--- a/openapi/src/api.ts+++ b/openapi/src/api.ts@@ -3251,6 +3251,7 @@ export interface components {auto_instantiate: boolean;/** @enum {string} */auto_reload: "off" | "lazy" | "autorun";+ default_auto_download?: ("html" | "markdown" | "ipynb")[];/** @enum {string} */default_sql_output:| "polars"