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
chore: fix exports, snapshot public api (#3836)
Myles Scolnick071e57ba12ba
diff --git a/Makefile b/Makefileindex 3898e94b70..e60eef2bde 100644--- a/Makefile+++ b/Makefile@@ -72,11 +72,12 @@ py-test:cd marimo && typos && cd - && hatch run +py=3.12 test-optional:test.PHONY: py-snapshots-# update html snapshots+# update snapshotspy-snapshots:hatch run +py=3.12 test:test \tests/_server/templates/test_templates.py \- tests/_server/api/endpoints/test_export.py+ tests/_server/api/endpoints/test_export.py \+ tests/test_api.py.PHONY: install-all# install everything; takes a long time due to editable installdiff --git a/marimo/__init__.py b/marimo/__init__.pyindex 9d87b0b70c..e63d7e6b10 100644--- a/marimo/__init__.py+++ b/marimo/__init__.py@@ -14,8 +14,6 @@ marimo is designed to be:5. fun"""-from __future__ import annotations-__all__ = [# Core API"App",@@ -90,7 +88,7 @@ import marimo._ai as aiimport marimo._islands as islandsfrom marimo._ast.app import Appfrom marimo._ast.cell import Cell-from marimo._islands.island_generator import MarimoIslandGenerator+from marimo._islands._island_generator import MarimoIslandGeneratorfrom marimo._output.doc import docfrom marimo._output.formatting import as_html, iframe, plainfrom marimo._output.hypertext import Htmldiff --git a/marimo/_ai/__init__.py b/marimo/_ai/__init__.pyindex 4334a8d356..88844f85f0 100644--- a/marimo/_ai/__init__.py+++ b/marimo/_ai/__init__.py@@ -1,8 +1,6 @@# Copyright 2024 Marimo. All rights reserved."""AI utilities."""-from __future__ import annotations-__all__ = ["ChatMessage","ChatModelConfig",@@ -10,8 +8,8 @@ __all__ = ["llm",]-from marimo._ai import llm-from marimo._ai.types import (+import marimo._ai.llm as llm+from marimo._ai._types import (ChatAttachment,ChatMessage,ChatModelConfig,diff --git a/marimo/_ai/convert.py b/marimo/_ai/_convert.pysimilarity index 99%rename from marimo/_ai/convert.pyrename to marimo/_ai/_convert.pyindex d23f014f3e..0ed2211d01 100644--- a/marimo/_ai/convert.py+++ b/marimo/_ai/_convert.py@@ -4,7 +4,7 @@ from __future__ import annotationsimport base64from typing import Any, Dict, List, TypedDict-from marimo._ai.types import ChatMessage+from marimo._ai._types import ChatMessagedef convert_to_openai_messages(diff --git a/marimo/_ai/types.py b/marimo/_ai/_types.pysimilarity index 100%rename from marimo/_ai/types.pyrename to marimo/_ai/_types.pydiff --git a/marimo/_ai/llm/__init__.py b/marimo/_ai/llm/__init__.pynew file mode 100644index 0000000000..a42bdf1fe3--- /dev/null+++ b/marimo/_ai/llm/__init__.py@@ -0,0 +1,3 @@+from marimo._ai.llm._impl import anthropic, google, groq, openai++__all__ = ["openai", "anthropic", "google", "groq"]diff --git a/marimo/_ai/llm.py b/marimo/_ai/llm/_impl.pysimilarity index 99%rename from marimo/_ai/llm.pyrename to marimo/_ai/llm/_impl.pyindex 5371676d02..a3b4eeb5c0 100644--- a/marimo/_ai/llm.py+++ b/marimo/_ai/llm/_impl.py@@ -4,13 +4,13 @@ from __future__ import annotationsimport osfrom typing import Callable, List, Optional, cast-from marimo._ai.convert import (+from marimo._ai._convert import (convert_to_anthropic_messages,convert_to_google_messages,convert_to_groq_messages,convert_to_openai_messages,)-from marimo._ai.types import (+from marimo._ai._types import (ChatMessage,ChatModel,ChatModelConfig,diff --git a/marimo/_islands/__init__.py b/marimo/_islands/__init__.pyindex 92fba771d5..93169d3598 100644--- a/marimo/_islands/__init__.py+++ b/marimo/_islands/__init__.py@@ -1,12 +1,10 @@# Copyright 2024 Marimo. All rights reserved.-from __future__ import annotations-__all__ = ["MarimoIslandGenerator","MarimoIslandStub",]-from marimo._islands.island_generator import (+from marimo._islands._island_generator import (MarimoIslandGenerator,MarimoIslandStub,)diff --git a/marimo/_islands/island_generator.py b/marimo/_islands/_island_generator.pysimilarity index 100%rename from marimo/_islands/island_generator.pyrename to marimo/_islands/_island_generator.pydiff --git a/marimo/_plugins/ui/__init__.py b/marimo/_plugins/ui/__init__.pyindex 1ab60c9cef..5c62eec343 100644--- a/marimo/_plugins/ui/__init__.py+++ b/marimo/_plugins/ui/__init__.py@@ -4,8 +4,6 @@This module contains a library of interactive UI elements."""-from __future__ import annotations-__all__ = ["altair_chart","anywidget",diff --git a/marimo/_plugins/ui/_impl/chat/chat.py b/marimo/_plugins/ui/_impl/chat/chat.pyindex a988ad5159..4169cd979c 100644--- a/marimo/_plugins/ui/_impl/chat/chat.py+++ b/marimo/_plugins/ui/_impl/chat/chat.py@@ -5,7 +5,7 @@ import inspectfrom dataclasses import dataclassfrom typing import Any, Callable, Dict, Final, List, Optional, Union, cast-from marimo._ai.types import (+from marimo._ai._types import (ChatMessage,ChatModelConfig,ChatModelConfigDict,diff --git a/marimo/_plugins/ui/_impl/chat/utils.py b/marimo/_plugins/ui/_impl/chat/utils.pyindex 984f21346c..a0e3a844a5 100644--- a/marimo/_plugins/ui/_impl/chat/utils.py+++ b/marimo/_plugins/ui/_impl/chat/utils.py@@ -3,7 +3,7 @@ from __future__ import annotationsfrom typing import List, Optional-from marimo._ai.types import (+from marimo._ai._types import (ChatAttachment,ChatMessage,ChatMessageDict,diff --git a/marimo/_server/api/endpoints/ai.py b/marimo/_server/api/endpoints/ai.pyindex 7bfea9eba2..c2708df713 100644--- a/marimo/_server/api/endpoints/ai.py+++ b/marimo/_server/api/endpoints/ai.py@@ -8,12 +8,12 @@ from starlette.exceptions import HTTPExceptionfrom starlette.responses import StreamingResponsefrom marimo import _loggers-from marimo._ai.convert import (+from marimo._ai._convert import (convert_to_anthropic_messages,convert_to_google_messages,convert_to_openai_messages,)-from marimo._ai.types import ChatMessage+from marimo._ai._types import ChatMessagefrom marimo._config.config import MarimoConfigfrom marimo._server.ai.prompts import Prompterfrom marimo._server.api.deps import AppStatediff --git a/marimo/_server/export/__init__.py b/marimo/_server/export/__init__.pyindex 63c79c8193..c4010e8622 100644--- a/marimo/_server/export/__init__.py+++ b/marimo/_server/export/__init__.py@@ -184,7 +184,7 @@ async def run_app_then_export_as_reactive_html() -> ExportResult:import os- from marimo._islands.island_generator import MarimoIslandGenerator+ from marimo._islands._island_generator import MarimoIslandGeneratorgenerator = MarimoIslandGenerator.from_file(path.absolute_name, display_code=include_codediff --git a/marimo/_server/models/completion.py b/marimo/_server/models/completion.pyindex fff3eb4a32..1ee2b6fc95 100644--- a/marimo/_server/models/completion.py+++ b/marimo/_server/models/completion.py@@ -4,7 +4,7 @@ from __future__ import annotationsfrom dataclasses import dataclass, fieldfrom typing import Any, List, Literal, Optional-from marimo._ai.types import ChatMessage+from marimo._ai._types import ChatMessage@dataclassdiff --git a/pyproject.toml b/pyproject.tomlindex bb4600f175..883ead4627 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -319,6 +319,7 @@ ignore = ["PT011", # `pytest.raises(ValueError)` is too broad, set the `match` parameter or use a more specific exception"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`]extend-select = [# pyflakesdiff --git a/tests/_ai/test_chat_convert.py b/tests/_ai/test_chat_convert.pyindex 4c4bd04068..769868df7a 100644--- a/tests/_ai/test_chat_convert.py+++ b/tests/_ai/test_chat_convert.py@@ -5,13 +5,13 @@ from typing import Listimport pytest-from marimo._ai.convert import (+from marimo._ai._convert import (convert_to_anthropic_messages,convert_to_google_messages,convert_to_groq_messages,convert_to_openai_messages,)-from marimo._ai.types import (+from marimo._ai._types import (ChatAttachment,ChatMessage,)diff --git a/tests/_ai/test_chat_model.py b/tests/_ai/test_chat_model.pyindex 4e5179c7b4..14a262cfc3 100644--- a/tests/_ai/test_chat_model.py+++ b/tests/_ai/test_chat_model.py@@ -1,7 +1,7 @@from __future__ import annotations-from marimo._ai.llm import simple-from marimo._ai.types import ChatMessage, ChatModelConfig+from marimo._ai._types import ChatMessage, ChatModelConfig+from marimo._ai.llm._impl import simpledef test_simple_model():diff --git a/tests/_islands/test_island_generator.py b/tests/_islands/test_island_generator.pyindex 28f37febfb..c873889f31 100644--- a/tests/_islands/test_island_generator.py+++ b/tests/_islands/test_island_generator.py@@ -6,7 +6,7 @@ import pytestfrom marimo import __version__from marimo._ast.app import _AppConfig-from marimo._islands.island_generator import (+from marimo._islands._island_generator import (MarimoIslandGenerator,)from tests.mocks import snapshotterdiff --git a/tests/_plugins/ui/_impl/chat/test_chat.py b/tests/_plugins/ui/_impl/chat/test_chat.pyindex 16a946ab9e..26b4c980fd 100644--- a/tests/_plugins/ui/_impl/chat/test_chat.py+++ b/tests/_plugins/ui/_impl/chat/test_chat.py@@ -6,7 +6,7 @@ from typing import AsyncIterator, Dict, Listimport pytest-from marimo._ai.types import (+from marimo._ai._types import (ChatMessage,ChatModelConfig,ChatModelConfigDict,diff --git a/tests/snapshots/api.txt b/tests/snapshots/api.txtnew file mode 100644index 0000000000..31b5951d44--- /dev/null+++ b/tests/snapshots/api.txt@@ -0,0 +1,114 @@+App+Cell+Html+MarimoIslandGenerator+MarimoStopError+Thread+accordion+ai+ ChatAttachment+ ChatMessage+ ChatModelConfig+ llm+ anthropic+ groq+ openai+app_meta+as_html+audio+cache+callout+capture_stderr+capture_stdout+carousel+center+cli_args+create_asgi_app+defs+doc+download+hstack+icon+iframe+image+islands+ MarimoIslandGenerator+ MarimoIslandStub+latex+lazy+left+lru_cache+md+mermaid+mpl+ interactive+nav_menu+notebook_dir+notebook_location+output+ append+ clear+ replace+ replace_at_index+persistent_cache+plain+plain_text+query_params+redirect_stderr+redirect_stdout+refs+right+routes+running_in_notebook+show_code+sidebar+sql+stat+state+status+ progress_bar+ spinner+ toast+stop+style+tabs+tree+ui+ altair_chart+ anywidget+ array+ batch+ button+ chat+ checkbox+ code_editor+ data_explorer+ dataframe+ date+ date_range+ datetime+ dictionary+ dropdown+ experimental_data_editor+ file+ file_browser+ form+ microphone+ multiselect+ number+ panel+ plotly+ radio+ range_slider+ refresh+ run_button+ slider+ switch+ table+ tabs+ text+ text_area+video+vstack\ No newline at end of filediff --git a/tests/test_api.py b/tests/test_api.pynew file mode 100644index 0000000000..d47d1d344f--- /dev/null+++ b/tests/test_api.py@@ -0,0 +1,57 @@+from __future__ import annotations++import inspect+from typing import Any, Optional, Set++from tests.mocks import snapshotter++snapshot = snapshotter(__file__)+++def _explore_module(+ module: Any, indent: int = 0, visited: Optional[Set[int]] = None+) -> list[str]:+ """+ Recursively explore a module and print all public exported items.++ Args:+ module: The module or object to explore+ indent: Current indentation level (for pretty printing)+ visited: Set[int] = set()+ """+ if visited is None:+ visited = set()++ # Skip if we've already visited this object+ if id(module) in visited:+ return []++ visited.add(id(module))++ results: list[str] = []+ # Get all attributes of the module+ for name, obj in inspect.getmembers(module):+ # Skip private/special attributes (starting with _)+ if name.startswith("_"):+ continue++ # Create indentation string+ indent_str = " " * indent++ # Print the current item+ results.append(f"{indent_str}{name}")++ # Recursively explore if it's a module, class, or other container type+ if inspect.ismodule(obj) and obj.__name__.startswith(module.__name__):+ # Only recurse into submodules of the original module+ results.extend(_explore_module(obj, indent + 1, visited))++ return results+++def test_api():+ import marimo as mo++ results = _explore_module(mo)+ assert len(results) > 0+ snapshot("api.txt", "\n".join(results))