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
tidy: remove python 3.9 support (#6866)
Dylan Madisettida509ea8b34c
diff --git a/marimo/_ast/app.py b/marimo/_ast/app.pyindex 6e40333dc5..d702cc6733 100644--- a/marimo/_ast/app.py+++ b/marimo/_ast/app.py@@ -6,7 +6,12 @@ import inspectimport osimport sysimport threading-from collections.abc import Iterable, Iterator, Mapping+from collections.abc import (+ Iterable,+ Iterator,+ Mapping,+ Sequence, # noqa: TC003+)from dataclasses import dataclassfrom pathlib import Pathfrom textwrap import dedent@@ -16,33 +21,18 @@ from typing import (Callable,Literal,Optional,+ ParamSpec,+ TypeAlias,TypeVar,Union,cast,overload,)-from marimo._ast.app_config import _AppConfig-from marimo._ast.cell_id import external_prefix-from marimo._ast.parse import ast_parse-from marimo._ast.variables import BUILTINS-from marimo._convert.converters import MarimoConvert-from marimo._schemas.serialization import (- AppInstantiation,- CellDef,- NotebookSerializationV1,-)-from marimo._types.ids import CellId_t--if sys.version_info < (3, 10):- from typing_extensions import ParamSpec, TypeAlias-else:- from typing import ParamSpec, TypeAlias--from collections.abc import Sequence # noqa: TC003-from marimo import _loggers+from marimo._ast.app_config import _AppConfigfrom marimo._ast.cell import Cell, CellConfig, CellImpl+from marimo._ast.cell_id import external_prefixfrom marimo._ast.cell_manager import CellManagerfrom marimo._ast.errors import (CycleError,@@ -50,6 +40,9 @@ from marimo._ast.errors import (SetupRootError,UnparsableError,)+from marimo._ast.parse import ast_parse+from marimo._ast.variables import BUILTINS+from marimo._convert.converters import MarimoConvertfrom marimo._messaging.mimetypes import KnownMimeTypefrom marimo._output.hypertext import Htmlfrom marimo._output.rich_help import mddoc@@ -65,6 +58,12 @@ from marimo._runtime.requests import (FunctionCallRequest,SetUIElementValueRequest,)+from marimo._schemas.serialization import (+ AppInstantiation,+ CellDef,+ NotebookSerializationV1,+)+from marimo._types.ids import CellId_tif TYPE_CHECKING:from collections.abc import Sequencediff --git a/marimo/_ast/cell_manager.py b/marimo/_ast/cell_manager.pyindex ddb2c7c862..778fd22abf 100644--- a/marimo/_ast/cell_manager.py+++ b/marimo/_ast/cell_manager.py@@ -2,19 +2,15 @@from __future__ import annotationsimport os-import sysfrom typing import (TYPE_CHECKING,Callable,Optional,+ ParamSpec,+ TypeAlias,TypeVar,)-if sys.version_info < (3, 10):- from typing_extensions import ParamSpec, TypeAlias-else:- from typing import ParamSpec, TypeAlias-from marimo import _loggersfrom marimo._ast.cell import Cell, CellConfigfrom marimo._ast.cell_id import CellIdGenerator@@ -44,7 +40,7 @@ P = ParamSpec("P")R = TypeVar("R")Fn: TypeAlias = Callable[P, R]Cls: TypeAlias = type-Obj: TypeAlias = "Cls | Fn[P, R]"+Obj: TypeAlias = Cls | Fn[P, R]LOGGER = _loggers.marimo_logger()diff --git a/marimo/_ast/codegen.py b/marimo/_ast/codegen.pyindex aa2ed0d545..e78ecf8aa7 100644--- a/marimo/_ast/codegen.py+++ b/marimo/_ast/codegen.py@@ -27,10 +27,7 @@ from marimo._version import __version__if TYPE_CHECKING:from pathlib import Path-if sys.version_info < (3, 10):- from typing_extensions import TypeAlias-else:- from typing import TypeAlias+from typing import TypeAliasCls: TypeAlias = typediff --git a/marimo/_ast/compiler.py b/marimo/_ast/compiler.pyindex cb18137d91..4655305326 100644--- a/marimo/_ast/compiler.py+++ b/marimo/_ast/compiler.py@@ -8,13 +8,12 @@ import ioimport linecacheimport osimport re-import sysimport textwrapimport token as token_typesimport warningsfrom tokenize import tokenizefrom types import CodeType, FrameType-from typing import Any, Callable, Optional, cast+from typing import Any, Callable, Optional, TypeAlias, castfrom marimo import _loggersfrom marimo._ast import parse@@ -32,11 +31,6 @@ from marimo._schemas.serialization import CellDef, ClassCell, FunctionCellfrom marimo._types.ids import CellId_tfrom marimo._utils.tmpdir import get_tmpdir-if sys.version_info < (3, 10):- from typing_extensions import TypeAlias-else:- from typing import TypeAlias-LOGGER = _loggers.marimo_logger()Cls: TypeAlias = typediff --git a/marimo/_ast/visitor.py b/marimo/_ast/visitor.pyindex 20ae2c95cd..135441b09e 100644--- a/marimo/_ast/visitor.py+++ b/marimo/_ast/visitor.py@@ -1056,52 +1056,49 @@ class ScopedVisitor(ast.NodeVisitor):)return node- if sys.version_info >= (3, 10):- # Match statements were introduced in Python 3.10- #- # Top-level match statements are awkward in marimo --- at parse-time,- # we have to register all names in every case/pattern as globals (since- # we don't know the value of the match subject), even though only a- # subset of the names will be bound at runtime. For this reason, in- # marimo, match statements should really only be used in local scopes.- def visit_MatchAs(self, node: ast.MatchAs) -> ast.MatchAs:- if node.name is not None:- node.name = self._if_local_then_mangle(node.name)- self._define(- node,- node.name,- VariableData(kind="variable"),- )- if node.pattern is not None:- # pattern may contain additional MatchAs statements in it- self.visit(node.pattern)- return node+ # Match statements were introduced in Python 3.10+ #+ # Top-level match statements are awkward in marimo --- at parse-time,+ # we have to register all names in every case/pattern as globals (since+ # we don't know the value of the match subject), even though only a+ # subset of the names will be bound at runtime. For this reason, in+ # marimo, match statements should really only be used in local scopes.+ def visit_MatchAs(self, node: ast.MatchAs) -> ast.MatchAs:+ if node.name is not None:+ node.name = self._if_local_then_mangle(node.name)+ self._define(+ node,+ node.name,+ VariableData(kind="variable"),+ )+ if node.pattern is not None:+ # pattern may contain additional MatchAs statements in it+ self.visit(node.pattern)+ return node- def visit_MatchMapping(- self, node: ast.MatchMapping- ) -> ast.MatchMapping:- if node.rest is not None:- node.rest = self._if_local_then_mangle(node.rest)- self._define(- node,- node.rest,- VariableData(kind="variable"),- )- for key in node.keys:- self.visit(key)- for pattern in node.patterns:- self.visit(pattern)- return node+ def visit_MatchMapping(self, node: ast.MatchMapping) -> ast.MatchMapping:+ if node.rest is not None:+ node.rest = self._if_local_then_mangle(node.rest)+ self._define(+ node,+ node.rest,+ VariableData(kind="variable"),+ )+ for key in node.keys:+ self.visit(key)+ for pattern in node.patterns:+ self.visit(pattern)+ return node- def visit_MatchStar(self, node: ast.MatchStar) -> ast.MatchStar:- if node.name is not None:- node.name = self._if_local_then_mangle(node.name)- self._define(- node,- node.name,- VariableData(kind="variable"),- )- return node+ def visit_MatchStar(self, node: ast.MatchStar) -> ast.MatchStar:+ if node.name is not None:+ node.name = self._if_local_then_mangle(node.name)+ self._define(+ node,+ node.name,+ VariableData(kind="variable"),+ )+ return nodeif sys.version_info >= (3, 12):diff --git a/marimo/_cli/development/commands.py b/marimo/_cli/development/commands.pyindex 6a93bf4538..c75bc19a70 100644--- a/marimo/_cli/development/commands.py+++ b/marimo/_cli/development/commands.py@@ -452,13 +452,6 @@ def inline_packages(name: Path) -> None:if not name.exists():raise click.FileError(str(name))- # Validate >=3.10 for sys.stdlib_module_names- if sys.version_info < (3, 10):- # TOD: add support for < 3.10- # We can use https://github.com/omnilib/stdlibs- # to get the stdlib module names- raise click.UsageError("Requires Python >=3.10")-package_names = module_name_to_pypi_name()def get_pypi_package_names() -> list[str]:diff --git a/marimo/_convert/ipynb.py b/marimo/_convert/ipynb.pyindex ba5c89cfaf..9d2e871b3a 100644--- a/marimo/_convert/ipynb.py+++ b/marimo/_convert/ipynb.py@@ -404,17 +404,17 @@ class Renamer:name = node.namenew_name = self._maybe_rename(cell, name, is_reference)node.name = new_name- if sys.version_info >= (3, 10):- if isinstance(node, (ast.MatchAs, ast.MatchStar)):- name = node.name- if name is not None:- new_name = self._maybe_rename(cell, name, is_reference)- node.name = new_name- elif isinstance(node, ast.MatchMapping):- name = node.rest- if name is not None:- new_name = self._maybe_rename(cell, name, is_reference)- node.rest = new_name++ if isinstance(node, (ast.MatchAs, ast.MatchStar)):+ name = node.name+ if name is not None:+ new_name = self._maybe_rename(cell, name, is_reference)+ node.name = new_name+ elif isinstance(node, ast.MatchMapping):+ name = node.rest+ if name is not None:+ new_name = self._maybe_rename(cell, name, is_reference)+ node.rest = new_nameif sys.version_info >= (3, 12):if isinstance(node, (ast.TypeVar, ast.ParamSpec, ast.TypeVarTuple)diff --git a/marimo/_messaging/ops.py b/marimo/_messaging/ops.pyindex 4f3844f3d6..e5d3fe8318 100644--- a/marimo/_messaging/ops.py+++ b/marimo/_messaging/ops.py@@ -613,14 +613,14 @@ class ColumnPreview(msgspec.Struct):stats: Optional[ColumnStats] = None-# We shouldn't need to make table_name and column_name have default values.-# We can use kw_only=True once we drop support for Python 3.9 (25-11-01).-class DataColumnPreview(Op, ColumnPreview, tag="data-column-preview"):+class DataColumnPreview(+ Op, ColumnPreview, kw_only=True, tag="data-column-preview"+):"""Preview of a column in a dataset."""name: ClassVar[str] = "data-column-preview"- table_name: str = ""- column_name: str = ""+ table_name: str+ column_name: strclass DataSourceConnections(Op, tag="data-source-connections"):diff --git a/marimo/_plugins/core/web_component.py b/marimo/_plugins/core/web_component.pyindex 36205f4ea0..0efe6aad1d 100644--- a/marimo/_plugins/core/web_component.py+++ b/marimo/_plugins/core/web_component.py@@ -17,15 +17,8 @@ from marimo._output.md import _mdfrom marimo._output.mime import MIMEif TYPE_CHECKING:- import sysfrom collections.abc import Mapping, Sequence-- if sys.version_info < (3, 10):- from typing_extensions import TypeAlias- else:- from typing import TypeAlias-- from typing import Optional+ from typing import Optional, TypeAliasJSONType: TypeAlias = Union[Mapping[str, "JSONType"],diff --git a/marimo/_plugins/ui/_core/registry.py b/marimo/_plugins/ui/_core/registry.pyindex f6c742bb66..ca932b3ea8 100644--- a/marimo/_plugins/ui/_core/registry.py+++ b/marimo/_plugins/ui/_core/registry.py@@ -1,20 +1,13 @@# Copyright 2024 Marimo. All rights reserved.from __future__ import annotations-import sysimport weakref-from typing import TYPE_CHECKING, Any, Optional, TypeVar, Union--from marimo._runtime.context.types import ContextNotInitializedError--if sys.version_info < (3, 10):- from typing_extensions import TypeAlias-else:- from typing import TypeAlias+from typing import TYPE_CHECKING, Any, Optional, TypeAlias, TypeVarfrom marimo._ast.app import _Namespacefrom marimo._plugins.ui._core.ui_element import UIElementfrom marimo._runtime.context import get_context+from marimo._runtime.context.types import ContextNotInitializedErrorfrom marimo._types.ids import CellId_t, UIElementIdif TYPE_CHECKING:@@ -22,8 +15,7 @@ if TYPE_CHECKING:T = TypeVar("T")-# Recursive types don't support | or dict[] in py3.8/3.9 (25-11-01)-LensValue: TypeAlias = Union[T, dict[str, "LensValue[T]"]]+LensValue: TypeAlias = T | dict[str, "LensValue[T]"]class UIElementRegistry:diff --git a/marimo/_plugins/ui/_impl/altair_chart.py b/marimo/_plugins/ui/_impl/altair_chart.pyindex dd04e9e404..1fe7cb807b 100644--- a/marimo/_plugins/ui/_impl/altair_chart.py+++ b/marimo/_plugins/ui/_impl/altair_chart.py@@ -11,6 +11,7 @@ from typing import (Final,Literal,Optional,+ TypeAlias,Union,cast,)@@ -33,11 +34,6 @@ from marimo._utils.narwhals_utils import (is_narwhals_lazyframe,)-if sys.version_info < (3, 10):- from typing_extensions import TypeAlias-else:- from typing import TypeAlias-LOGGER = _loggers.marimo_logger()if TYPE_CHECKING:diff --git a/marimo/_server/asgi.py b/marimo/_server/asgi.pyindex 4bf9330c58..408952f6e7 100644--- a/marimo/_server/asgi.py+++ b/marimo/_server/asgi.py@@ -16,12 +16,7 @@ from typing import ()if TYPE_CHECKING:- import sys-- if sys.version_info < (3, 10):- from typing_extensions import TypeAlias- else:- from typing import TypeAlias+ from typing import TypeAliasfrom starlette.requests import Requestfrom starlette.responses import Responsediff --git a/marimo/_utils/async_path.py b/marimo/_utils/async_path.pyindex d2a5dd853b..33a23864e0 100644--- a/marimo/_utils/async_path.py+++ b/marimo/_utils/async_path.py@@ -7,7 +7,6 @@ from __future__ import annotationsimport asyncioimport os-import sysfrom pathlib import Path, PurePath, PurePosixPath, PureWindowsPathfrom typing import IO, TYPE_CHECKING, Any, Optional, Union@@ -138,14 +137,9 @@ class AsyncPath(PurePath):newline: Optional[str] = None,) -> int:"""Write text data to the file."""- if sys.version_info >= (3, 10):- return await asyncio.to_thread(- self._path.write_text, data, encoding, errors, newline- )- else:- return await asyncio.to_thread(- self._path.write_text, data, encoding, errors- )+ return await asyncio.to_thread(+ self._path.write_text, data, encoding, errors, newline+ )async def write_bytes(self, data: bytes) -> int:"""Write bytes data to the file."""diff --git a/marimo/_utils/lifespans.py b/marimo/_utils/lifespans.pyindex 31e0968d1a..3626c8af46 100644--- a/marimo/_utils/lifespans.py+++ b/marimo/_utils/lifespans.py@@ -3,19 +3,13 @@ from __future__ import annotationsimport asyncioimport contextlib-import sysfrom collections.abc import AsyncIterator, Sequencefrom contextlib import AbstractAsyncContextManager-from typing import Any, Generic, TypeVar+from typing import Any, Generic, TypeAlias, TypeVarfrom marimo import _loggersfrom marimo._types.lifespan import Lifespan-if sys.version_info < (3, 10):- from typing_extensions import TypeAlias-else:- from typing import TypeAlias-T = TypeVar("T", bound=Any)LifespanList: TypeAlias = Sequence[Lifespan[T]]diff --git a/marimo/_utils/yaml.py b/marimo/_utils/yaml.pyindex 885900dcbf..d0963e5ce0 100644--- a/marimo/_utils/yaml.py+++ b/marimo/_utils/yaml.py@@ -2,18 +2,11 @@from __future__ import annotationsimport re-import sys-from typing import Any, Callable+from typing import Any, Callable, TypeAliasimport yamlfrom yaml.representer import SafeRepresenter, ScalarNode-if sys.version_info < (3, 10):- from typing_extensions import TypeAlias-else:- from typing import TypeAlias--# Regex captures loose yaml for frontmatter# Should match the following:# ---diff --git a/packages/openapi/api.yaml b/packages/openapi/api.yamlindex 9cd5bded4d..125c8abba6 100644--- a/packages/openapi/api.yaml+++ b/packages/openapi/api.yaml@@ -797,7 +797,6 @@ components:- type: 'null'default: nullcolumn_name:- default: ''type: stringerror:anyOf:@@ -820,10 +819,11 @@ components:- $ref: '#/components/schemas/ColumnStats'default: nulltable_name:- default: ''type: stringrequired:- op+ - table_name+ - column_nametitle: DataColumnPreviewtype: objectDataSourceConnection:@@ -3714,7 +3714,7 @@ components:type: objectinfo:title: marimo API- version: 0.16.5+ version: 0.17.6openapi: 3.1.0paths:/@file/{filename_and_length}:diff --git a/packages/openapi/src/api.ts b/packages/openapi/src/api.tsindex 5c5fce39b8..ef7ade333e 100644--- a/packages/openapi/src/api.ts+++ b/packages/openapi/src/api.ts@@ -3231,8 +3231,7 @@ export interface components {chart_code?: string | null;/** @default null */chart_spec?: string | null;- /** @default */- column_name?: string;+ column_name: string;/** @default null */error?: string | null;/** @default null */@@ -3241,8 +3240,7 @@ export interface components {op: "data-column-preview";/** @default null */stats?: null | components["schemas"]["ColumnStats"];- /** @default */- table_name?: string;+ table_name: string;};/*** DataSourceConnectiondiff --git a/pixi.lock b/pixi.lockindex dc5c3d050b..cbf3bda947 100644--- a/pixi.lock+++ b/pixi.lock@@ -1102,7 +1102,7 @@ packages:- pypi: ./name: marimoversion: 0.17.6- sha256: 80f32e9a6e52837821f06f4f7fc3cb30c48c5782ccf34c3f90da21937c8cae20+ sha256: adff4529a418a8f3154adba424233c00d50beece8d4f565645842d85aacfd02crequires_dist:- click>=8.0,<9- jedi>=0.18.0@@ -1145,7 +1145,7 @@ packages:- python-lsp-ruff>=2.0.0 ; extra == 'lsp'- mcp>=1.0.0 ; python_full_version >= '3.10' and extra == 'mcp'- pydantic>2 ; python_full_version >= '3.10' and extra == 'mcp'- requires_python: '>=3.9'+ requires_python: '>=3.10'editable: true- pypi: https://files.pythonhosted.org/packages/3f/08/83871f3c50fc983b88547c196d11cf8c3340e37c32d2e9d6152abe2c61f7/Markdown-3.7-py3-none-any.whlname: markdowndiff --git a/pyproject.toml b/pyproject.tomlindex 8ab97d2374..94095d6139 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -52,7 +52,7 @@ dependencies = []readme = "README.md"license = { file = "LICENSE" }-requires-python = ">=3.9"+requires-python = ">=3.10"classifiers = ["Operating System :: OS Independent","License :: OSI Approved :: Apache Software License",@@ -62,7 +62,6 @@ classifiers = ["Intended Audience :: Science/Research","Intended Audience :: Education","Programming Language :: Python",- "Programming Language :: Python :: 3.9","Programming Language :: Python :: 3.10","Programming Language :: Python :: 3.11","Programming Language :: Python :: 3.12",@@ -210,7 +209,7 @@ extra-dependencies = [][[tool.hatch.envs.test.matrix]]-python = ["3.9", "3.10", "3.11", "3.12", "3.13", "3.14"]+python = ["3.10", "3.11", "3.12", "3.13", "3.14"][tool.hatch.envs.test.scripts]test = "pytest{env:HATCH_TEST_ARGS:} {args:tests}"@@ -260,17 +259,17 @@ extra-dependencies = ["pandas>=1.5.3","hvplot~=0.11.3",# Causes issues installing `shapely` (v2.0.7)- # "geopandas~=1.0.1; python_version > '3.9'",+ # "geopandas~=1.0.1",# FOr testing sql"duckdb<=1.3.0", # 1.4.0 does pass- "ibis-framework[duckdb]>=10.3.0; python_version > '3.9'",+ "ibis-framework[duckdb]>=10.3.0",# For testing mo.image"pillow~=10.4.0","anywidget~=0.9.18","ipython~=8.12.3",# testing gen ai"openai>=1.55.3",- "anthropic==0.52.2; python_version > '3.9'",+ "anthropic==0.52.2","google-genai>=0.2.0","boto3>=1.38.46","litellm==1.70.0",@@ -288,7 +287,7 @@ extra-dependencies = [][[tool.hatch.envs.test-optional.matrix]]-python = ["3.9", "3.10", "3.11", "3.12", "3.13", "3.14"]+python = ["3.10", "3.11", "3.12", "3.13", "3.14"][tool.hatch.envs.docs]dependencies = [@@ -368,8 +367,8 @@ ignore = ["E501", # Line too long, we still trim"D415", # First line should end with a period, question mark, or exclamation point"FA102", # Use `from __future__ import annotations`- "UP007", # Use X | Y for type annotations, not supported in 3.9- "UP045", # Use X | None for optional type annotations, not supported in 3.9+ "UP007", # Use X | Y for type annotations, wasn't supported in 3.9+ "UP045", # Use X | None for optional type annotations, wasn't supported in 3.9]extend-select = [# pyflakesdiff --git a/tests/_ast/test_transformers.py b/tests/_ast/test_transformers.pyindex 77c8b6ab7c..82b474b8fa 100644--- a/tests/_ast/test_transformers.py+++ b/tests/_ast/test_transformers.py@@ -1,7 +1,6 @@from __future__ import annotationsimport ast-import sysimport pytest@@ -22,9 +21,6 @@ from marimo._ast.transformers import ()- sys.version_info < (3, 9), reason="Feature not supported in python 3.8"-)def test_name_transformer() -> None:# Name transformer should naively remap all occurrences of names in an AST,# without taking scoping into account.@@ -83,9 +79,6 @@ new_global = 'world'assert transformer.made_changes- sys.version_info < (3, 9), reason="Feature not supported in python 3.8"-)def test_name_transformer_no_changes() -> None:code = "x = 1"tree = ast.parse(code)diff --git a/tests/_ast/test_visitor.py b/tests/_ast/test_visitor.pyindex db99f19c06..004157836d 100644--- a/tests/_ast/test_visitor.py+++ b/tests/_ast/test_visitor.py@@ -722,7 +722,6 @@ def test_captured_variables() -> None:assert v.refs == set(["x"])[email protected]("sys.version_info < (3, 10)")def test_matchas() -> None:code = cleandoc("""@@ -752,7 +751,6 @@ def test_matchas() -> None:}[email protected]("sys.version_info < (3, 10)")def test_matchstar() -> None:code = cleandoc("""@@ -773,7 +771,6 @@ def test_matchstar() -> None:}[email protected]("sys.version_info < (3, 10)")def test_matchmapping() -> None:code = cleandoc("""diff --git a/tests/_plugins/ui/_impl/test_altair_chart.py b/tests/_plugins/ui/_impl/test_altair_chart.pyindex 8299fbf9c1..a09827c6c3 100644--- a/tests/_plugins/ui/_impl/test_altair_chart.py+++ b/tests/_plugins/ui/_impl/test_altair_chart.py@@ -44,8 +44,6 @@ HAS_DEPS = (and DependencyManager.altair.has()# altair produces different output on windowsand sys.platform != "win32"- # skip 3.9- and sys.version_info >= (3, 10))if HAS_DEPS: