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.

chore: add openapi spec generation and codegen typescript (#1594)

Myles Scolnick7d5183ca88e1
diff --git a/Makefile b/Makefile
index ec26e8c76a..3afa4748a9 100644
--- a/Makefile
+++ b/Makefile
@@ -57,6 +57,10 @@ fe-lint:
fe-typecheck:
cd frontend; pnpm turbo typecheck
+.PHONY: fe-codegen
+fe-codegen:
+ cd openapi; pnpm install; pnpm codegen
+
.PHONY: py-check
# check python
py-check:
diff --git a/development_docs/openapi.md b/development_docs/openapi.md
new file mode 100644
index 0000000000..63c1f4fae2
--- /dev/null
+++ b/development_docs/openapi.md
@@ -0,0 +1,26 @@
+# marimo + openapi
+
+## Printing the OpenAPI schema
+
+```bash
+marimo development openapi
+```
+
+## Writing a new OpenAPI schema
+
+```bash
+marimo development openapi > openapi/api.yaml
+```
+
+## Validating an OpenAPI schema
+
+```bash
+pipx install openapi-spec-validator
+marimo development openapi | openapi-spec-validator -
+```
+
+## Generating a client from an OpenAPI schema
+
+```bash
+make fe-codegen
+```
diff --git a/pyodide/DOCS.md b/development_docs/pyodide.md
similarity index 100%
rename from pyodide/DOCS.md
rename to development_docs/pyodide.md
diff --git a/marimo/_cli/cli.py b/marimo/_cli/cli.py
index cbb6bb1ea7..ec151e0c4f 100644
--- a/marimo/_cli/cli.py
+++ b/marimo/_cli/cli.py
@@ -14,6 +14,7 @@ from marimo import __version__, _loggers
from marimo._ast import codegen
from marimo._cli.config.commands import config
from marimo._cli.convert.commands import convert
+from marimo._cli.development.commands import development
from marimo._cli.envinfo import get_system_info
from marimo._cli.export.commands import export
from marimo._cli.file_path import validate_name
@@ -603,3 +604,4 @@ def env() -> None:
main.command()(convert)
main.add_command(export)
main.add_command(config)
+main.add_command(development)
diff --git a/marimo/_cli/development/commands.py b/marimo/_cli/development/commands.py
new file mode 100644
index 0000000000..16e83e9615
--- /dev/null
+++ b/marimo/_cli/development/commands.py
@@ -0,0 +1,134 @@
+# Copyright 2024 Marimo. All rights reserved.
+from __future__ import annotations
+
+from typing import Any, Dict, Type
+
+import click
+from starlette.schemas import SchemaGenerator
+
+import marimo._runtime.requests as requests
+import marimo._server.models.completion as completion
+import marimo._server.models.export as export
+import marimo._server.models.files as files
+import marimo._server.models.home as home
+import marimo._server.models.models as models
+import marimo._snippets.snippets as snippets
+from marimo import __version__
+from marimo._ast.cell import CellConfig
+from marimo._config.config import MarimoConfig
+from marimo._server.api.router import build_routes
+from marimo._utils.dataclass_to_openapi import dataclass_to_openapi_spec
+
+
+def _generate_schema() -> dict[str, Any]:
+ # dataclass components that we can generate schemas for
+ COMPONENTS = [
+ # Sub components
+ requests.AppMetadata,
+ home.MarimoFile,
+ files.FileInfo,
+ MarimoConfig,
+ CellConfig,
+ requests.ExecutionRequest,
+ snippets.SnippetSection,
+ snippets.Snippet,
+ snippets.Snippets,
+ # Requests/responses
+ completion.AiCompletionRequest,
+ export.ExportAsHTMLRequest,
+ export.ExportAsMarkdownRequest,
+ export.ExportAsScriptRequest,
+ files.FileCreateRequest,
+ files.FileCreateResponse,
+ files.FileDeleteRequest,
+ files.FileDeleteResponse,
+ files.FileDetailsRequest,
+ files.FileDetailsResponse,
+ files.FileListRequest,
+ files.FileListResponse,
+ files.FileMoveRequest,
+ files.FileMoveResponse,
+ files.FileUpdateRequest,
+ files.FileUpdateResponse,
+ home.RecentFilesResponse,
+ home.ShutdownSessionRequest,
+ home.WorkspaceFilesRequest,
+ home.WorkspaceFilesResponse,
+ models.BaseResponse,
+ models.BaseResponse,
+ models.FormatRequest,
+ models.FormatResponse,
+ models.InstantiateRequest,
+ models.OpenFileRequest,
+ models.ReadCodeResponse,
+ models.RenameFileRequest,
+ models.RunRequest,
+ models.SaveAppConfigurationRequest,
+ models.SaveRequest,
+ models.SaveUserConfigurationRequest,
+ models.StdinRequest,
+ models.SuccessResponse,
+ models.SuccessResponse,
+ models.UpdateComponentValuesRequest,
+ requests.CompletionRequest,
+ requests.CreationRequest,
+ requests.DeleteRequest,
+ requests.ExecuteMultipleRequest,
+ requests.ExecuteStaleRequest,
+ requests.ExecutionRequest,
+ requests.FunctionCallRequest,
+ requests.InstallMissingPackagesRequest,
+ requests.PreviewDatasetColumnRequest,
+ requests.SetCellConfigRequest,
+ requests.SetUIElementValueRequest,
+ requests.SetUserConfigRequest,
+ requests.StopRequest,
+ ]
+
+ processed_classes: Dict[Type[Any], str] = {}
+
+ component_schemas: Dict[str, Any] = {}
+ for cls in COMPONENTS:
+ # Remove self from the list
+ # since it may not have been processed yet
+ if cls in processed_classes:
+ del processed_classes[cls]
+ component_schemas[cls.__name__] = dataclass_to_openapi_spec(
+ cls, processed_classes
+ )
+
+ schemas = SchemaGenerator(
+ {
+ "openapi": "3.1.0",
+ "info": {"title": "marimo API", "version": __version__},
+ "components": {
+ "schemas": {
+ **component_schemas,
+ }
+ },
+ }
+ )
+
+ return schemas.get_schema(routes=build_routes())
+
+
+ help="""Various commands for the marimo development.""", hidden=True
+)
+def development() -> None:
+ pass
+
+
[email protected](help="""Print the marimo OpenAPI schema""")
+def openapi() -> None:
+ """
+ Example usage:
+
+ marimo development openapi
+ """
+ import yaml
+
+ print(yaml.dump(_generate_schema(), default_flow_style=False))
+
+
+development.add_command(openapi)
diff --git a/marimo/_config/config.py b/marimo/_config/config.py
index 81fe0aaaff..35a036f57a 100644
--- a/marimo/_config/config.py
+++ b/marimo/_config/config.py
@@ -2,6 +2,7 @@
from __future__ import annotations
import sys
+from dataclasses import dataclass
if sys.version_info < (3, 11):
from typing_extensions import NotRequired
@@ -15,6 +16,7 @@ from marimo._utils.deep_merge import deep_merge
@mddoc
+@dataclass
class CompletionConfig(TypedDict):
"""Configuration for code completion.
@@ -33,6 +35,7 @@ class CompletionConfig(TypedDict):
@mddoc
+@dataclass
class SaveConfig(TypedDict):
"""Configuration for saving.
@@ -49,6 +52,7 @@ class SaveConfig(TypedDict):
@mddoc
+@dataclass
class KeymapConfig(TypedDict, total=False):
"""Configuration for keymaps.
@@ -66,6 +70,7 @@ OnCellChangeType = Literal["lazy", "autorun"]
@mddoc
+@dataclass
class RuntimeConfig(TypedDict):
"""Configuration for runtime.
@@ -94,6 +99,7 @@ WidthType = Literal["normal", "compact", "medium", "full"]
@mddoc
+@dataclass
class DisplayConfig(TypedDict):
"""Configuration for display.
@@ -111,6 +117,7 @@ class DisplayConfig(TypedDict):
@mddoc
+@dataclass
class FormattingConfig(TypedDict):
"""Configuration for code formatting.
@@ -122,6 +129,7 @@ class FormattingConfig(TypedDict):
line_length: int
+@dataclass
class ServerConfig(TypedDict):
"""Configuration for the server.
@@ -137,6 +145,7 @@ class ServerConfig(TypedDict):
follow_symlink: bool
+@dataclass
class PackageManagementConfig(TypedDict):
"""Configuration options for package management.
@@ -148,6 +157,7 @@ class PackageManagementConfig(TypedDict):
manager: Literal["pip", "rye", "uv", "poetry", "pixi"]
+@dataclass
class AiConfig(TypedDict):
"""Configuration options for AI.
@@ -159,6 +169,7 @@ class AiConfig(TypedDict):
open_ai: OpenAiConfig
+@dataclass
class OpenAiConfig(TypedDict):
"""Configuration options for OpenAI or OpenAI-compatible services.
@@ -175,6 +186,7 @@ class OpenAiConfig(TypedDict):
@mddoc
+@dataclass
class MarimoConfig(TypedDict):
"""Configuration for the marimo editor"""
diff --git a/marimo/_server/api/endpoints/ai.py b/marimo/_server/api/endpoints/ai.py
index 5e0a07e46a..f41bdac644 100644
--- a/marimo/_server/api/endpoints/ai.py
+++ b/marimo/_server/api/endpoints/ai.py
@@ -99,6 +99,23 @@ async def ai_completion(
*,
request: Request,
) -> StreamingResponse:
+ """
+ requestBody:
+ description: The prompt to get AI completion for
+ required: true
+ content:
+ application/json:
+ schema:
+ $ref: "#/components/schemas/AiCompletionRequest"
+ responses:
+ 200:
+ description: Get AI completion for a prompt
+ content:
+ application/json:
+ schema:
+ type: object
+ additionalProperties: true
+ """
app_state = AppState(request)
app_state.require_current_session()
config = app_state.config_manager.get_config(hide_secrets=False)
diff --git a/marimo/_server/api/endpoints/assets.py b/marimo/_server/api/endpoints/assets.py
index d8557ea808..ae5c703598 100644
--- a/marimo/_server/api/endpoints/assets.py
+++ b/marimo/_server/api/endpoints/assets.py
@@ -104,7 +104,26 @@ STATIC_FILES = [
def virtual_file(
request: Request,
) -> Response:
- """Handler for virtual files."""
+ """
+ parameters:
+ - in: path
+ name: filename_and_length
+ required: true
+ schema:
+ type: string
+ description: The filename and byte length of the virtual file
+ responses:
+ 200:
+ description: Get a virtual file
+ content:
+ application/octet-stream:
+ schema:
+ type: string
+ 404:
+ description: Invalid virtual file request
+ 404:
+ description: Invalid byte length in virtual file request
+ """
filename_and_length = request.path_params["filename_and_length"]
LOGGER.debug("Getting virtual file: %s", filename_and_length)
diff --git a/marimo/_server/api/endpoints/config.py b/marimo/_server/api/endpoints/config.py
index 407db037f0..10d8db6990 100644
--- a/marimo/_server/api/endpoints/config.py
+++ b/marimo/_server/api/endpoints/config.py
@@ -31,10 +31,15 @@ async def save_user_config(
*,
request: Request,
) -> BaseResponse:
- """Update the user config on disk and in the kernel.
-
- Only allowed in edit mode.
"""
+ responses:
+ 200:
+ description: Update the user config on disk and in the kernel. Only allowed in edit mode.
+ content:
+ application/json:
+ schema:
+ $ref: "#/components/schemas/SuccessResponse"
+ """ # noqa: E501
app_state = AppState(request)
body = await parse_request(request, cls=SaveUserConfigurationRequest)
config = app_state.config_manager.save_config(body.config)
diff --git a/marimo/_server/api/endpoints/datasources.py b/marimo/_server/api/endpoints/datasources.py
index 1d1f678bd8..bc7d658684 100644
--- a/marimo/_server/api/endpoints/datasources.py
+++ b/marimo/_server/api/endpoints/datasources.py
@@ -26,6 +26,20 @@ router = APIRouter()
async def preview_column(
request: Request,
) -> BaseResponse:
+ """
+ requestBody:
+ content:
+ application/json:
+ schema:
+ $ref: "#/components/schemas/PreviewDatasetColumnRequest"
+ responses:
+ 200:
+ description: Preview a column in a dataset
+ content:
+ application/json:
+ schema:
+ $ref: "#/components/schemas/SuccessResponse"
+ """
app_state = AppState(request)
body = await parse_request(request, PreviewDatasetColumnRequest)
app_state.require_current_session().put_control_request(body)
diff --git a/marimo/_server/api/endpoints/documentation.py b/marimo/_server/api/endpoints/documentation.py
index bac0e92f28..37c5115129 100644
--- a/marimo/_server/api/endpoints/documentation.py
+++ b/marimo/_server/api/endpoints/documentation.py
@@ -23,6 +23,15 @@ _SNIPPETS: list[Snippets] = []
async def load_snippets(
request: Request,
) -> Snippets:
+ """
+ responses:
+ 200:
+ description: Load the snippets for the documentation page
+ content:
+ application/json:
+ schema:
+ $ref: "#/components/schemas/Snippets"
+ """
del request
if not _SNIPPETS:
_SNIPPETS.append(await read_snippets())
diff --git a/marimo/_server/api/endpoints/editing.py b/marimo/_server/api/endpoints/editing.py
index 5322ea7fb8..1b466a2656 100644
--- a/marimo/_server/api/endpoints/editing.py
+++ b/marimo/_server/api/endpoints/editing.py
@@ -33,7 +33,20 @@ router = APIRouter()
@router.post("/code_autocomplete")
@requires("edit")
async def code_complete(request: Request) -> BaseResponse:
- """Complete a code fragment."""
+ """
+ requestBody:
+ content:
+ application/json:
+ schema:
+ $ref: "#/components/schemas/CompletionRequest"
+ responses:
+ 200:
+ description: Complete a code fragment
+ content:
+ application/json:
+ schema:
+ $ref: "#/components/schemas/SuccessResponse"
+ """
app_state = AppState(request)
body = await parse_request(request, cls=CompletionRequest)
app_state.require_current_session().put_completion_request(body)
@@ -44,7 +57,20 @@ async def code_complete(request: Request) -> BaseResponse:
@router.post("/delete")
@requires("edit")
async def delete_cell(request: Request) -> BaseResponse:
- """Complete a code fragment."""
+ """
+ requestBody:
+ content:
+ application/json:
+ schema:
+ $ref: "#/components/schemas/DeleteRequest"
+ responses:
+ 200:
+ description: Delete a cell
+ content:
+ application/json:
+ schema:
+ $ref: "#/components/schemas/SuccessResponse"
+ """
app_state = AppState(request)
body = await parse_request(request, cls=DeleteRequest)
app_state.require_current_session().put_control_request(body)
@@ -55,7 +81,20 @@ async def delete_cell(request: Request) -> BaseResponse:
@router.post("/format")
@requires("edit")
async def format_cell(request: Request) -> FormatResponse:
- """Complete a code fragment."""
+ """
+ requestBody:
+ content:
+ application/json:
+ schema:
+ $ref: "#/components/schemas/FormatRequest"
+ responses:
+ 200:
+ description: Format code
+ content:
+ application/json:
+ schema:
+ $ref: "#/components/schemas/FormatResponse"
+ """
body = await parse_request(request, cls=FormatRequest)
formatter = DefaultFormatter(line_length=body.line_length)
@@ -65,7 +104,20 @@ async def format_cell(request: Request) -> FormatResponse:
@router.post("/set_cell_config")
@requires("edit")
async def set_cell_config(request: Request) -> BaseResponse:
- """Set the config for a cell."""
+ """
+ requestBody:
+ content:
+ application/json:
+ schema:
+ $ref: "#/components/schemas/SetCellConfigRequest"
+ responses:
+ 200:
+ description: Set the configuration of a cell
+ content:
+ application/json:
+ schema:
+ $ref: "#/components/schemas/SuccessResponse"
+ """
app_state = AppState(request)
body = await parse_request(request, cls=SetCellConfigRequest)
app_state.require_current_session().put_control_request(body)
@@ -76,7 +128,20 @@ async def set_cell_config(request: Request) -> BaseResponse:
@router.post("/stdin")
@requires("edit")
async def stdin(request: Request) -> BaseResponse:
- """Send input to the stdin stream."""
+ """
+ requestBody:
+ content:
+ application/json:
+ schema:
+ $ref: "#/components/schemas/StdinRequest"
+ responses:
+ 200:
+ description: Send input to the stdin stream
+ content:
+ application/json:
+ schema:
+ $ref: "#/components/schemas/SuccessResponse"
+ """
app_state = AppState(request)
body = await parse_request(request, cls=StdinRequest)
app_state.require_current_session().put_input(body.text)
@@ -84,11 +149,23 @@ async def stdin(request: Request) -> BaseResponse:
return SuccessResponse()
-# TODO(akshayka): allow in run mode when in pyodide
@router.post("/install_missing_packages")
@requires("edit")
async def install_missing_packages(request: Request) -> BaseResponse:
- """Install missing packages"""
+ """
+ requestBody:
+ content:
+ application/json:
+ schema:
+ $ref: "#/components/schemas/InstallMissingPackagesRequest"
+ responses:
+ 200:
+ description: Install missing packages
+ content:
+ application/json:
+ schema:
+ $ref: "#/components/schemas/SuccessResponse"
+ """
app_state = AppState(request)
body = await parse_request(request, cls=InstallMissingPackagesRequest)
app_state.require_current_session().put_control_request(body)
diff --git a/marimo/_server/api/endpoints/execution.py b/marimo/_server/api/endpoints/execution.py
index 0ad7098076..704b9cc297 100644
--- a/marimo/_server/api/endpoints/execution.py
+++ b/marimo/_server/api/endpoints/execution.py
@@ -38,7 +38,18 @@ async def set_ui_element_values(
request: Request,
) -> BaseResponse:
"""
- Set UI element values.
+ requestBody:
+ content:
+ application/json:
+ schema:
+ $ref: "#/components/schemas/UpdateComponentValuesRequest"
+ responses:
+ 200:
+ description: Set UI element values
+ content:
+ application/json:
+ schema:
+ $ref: "#/components/schemas/SuccessResponse"
"""
app_state = AppState(request)
body = await parse_request(request, cls=UpdateComponentValuesRequest)
@@ -55,7 +66,18 @@ async def instantiate(
request: Request,
) -> BaseResponse:
"""
- Instantiate the kernel.
+ requestBody:
+ content:
+ application/json:
+ schema:
+ $ref: "#/components/schemas/InstantiateRequest"
+ responses:
+ 200:
+ description: Instantiate a component
+ content:
+ application/json:
+ schema:
+ $ref: "#/components/schemas/SuccessResponse"
"""
app_state = AppState(request)
body = await parse_request(request, cls=InstantiateRequest)
@@ -69,7 +91,20 @@ async def function_call(
*,
request: Request,
) -> BaseResponse:
- """Invoke an RPC"""
+ """
+ requestBody:
+ content:
+ application/json:
+ schema:
+ $ref: "#/components/schemas/FunctionCallRequest"
+ responses:
+ 200:
+ description: Invoke an RPC
+ content:
+ application/json:
+ schema:
+ $ref: "#/components/schemas/SuccessResponse"
+ """
app_state = AppState(request)
body = await parse_request(request, cls=FunctionCallRequest)
app_state.require_current_session().put_control_request(body)
@@ -83,7 +118,15 @@ async def interrupt(
*,
request: Request,
) -> BaseResponse:
- """Interrupt the kernel's execution."""
+ """
+ responses:
+ 200:
+ description: Interrupt the kernel's execution
+ content:
+ application/json:
+ schema:
+ $ref: "#/components/schemas/SuccessResponse"
+ """
app_state = AppState(request)
app_state.require_current_session().try_interrupt()
@@ -96,13 +139,20 @@ async def run_cell(
*,
request: Request,
) -> BaseResponse:
- """Run multiple cells (and their descendants).
-
- Updates cell code in the kernel if needed; registers new cells
- for unseen cell IDs.
-
- Only allowed in edit mode.
"""
+ requestBody:
+ content:
+ application/json:
+ schema:
+ $ref: "#/components/schemas/RunRequest"
+ responses:
+ 200:
+ description: Run a cell. Updates cell code in the kernel if needed; registers new cells for unseen cell IDs. Only allowed in edit mode.
+ content:
+ application/json:
+ schema:
+ $ref: "#/components/schemas/SuccessResponse"
+ """ # noqa: E501
app_state = AppState(request)
body = await parse_request(request, cls=RunRequest)
app_state.require_current_session().put_control_request(
@@ -119,9 +169,14 @@ async def restart_session(
request: Request,
) -> BaseResponse:
"""
- Restart a session. This does not restart the
- kernel or affect other sessions
- """
+ responses:
+ 200:
+ description: Restart the current session without affecting other sessions.
+ content:
+ application/json:
+ schema:
+ $ref: "#/components/schemas/SuccessResponse"
+ """ # noqa: E501
app_state = AppState(request)
# This just closes the session, and the frontend will
# do a full reload, which will restart the session.
@@ -137,7 +192,15 @@ async def shutdown(
*,
request: Request,
) -> BaseResponse:
- """Shutdown the kernel."""
+ """
+ responses:
+ 200:
+ description: Shutdown the kernel
+ content:
+ application/json:
+ schema:
+ $ref: "#/components/schemas/SuccessResponse"
+ """
LOGGER.debug("Received shutdown request")
app_state = AppState(request)
session_manager = app_state.session_manager
diff --git a/marimo/_server/api/endpoints/export.py b/marimo/_server/api/endpoints/export.py
index e0235aac13..2ea42d1ed6 100644
--- a/marimo/_server/api/endpoints/export.py
+++ b/marimo/_server/api/endpoints/export.py
@@ -36,7 +36,20 @@ async def export_as_html(
request: Request,
) -> HTMLResponse:
"""
- Export the notebook as HTML.
+ requestBody:
+ content:
+ application/json:
+ schema:
+ $ref: "#/components/schemas/ExportAsHTMLRequest"
+ responses:
+ 200:
+ description: Export the notebook as HTML
+ content:
+ text/html:
+ schema:
+ type: string
+ 400:
+ description: File must be saved before downloading
"""
app_state = AppState(request)
body = await parse_request(request, cls=ExportAsHTMLRequest)
@@ -74,7 +87,20 @@ async def export_as_script(
request: Request,
) -> PlainTextResponse:
"""
- Export the notebook as a script.
+ requestBody:
+ content:
+ application/json:
+ schema:
+ $ref: "#/components/schemas/ExportAsScriptRequest"
+ responses:
+ 200:
+ description: Export the notebook as a script
+ content:
+ text/plain:
+ schema:
+ type: string
+ 400:
+ description: File must be saved before downloading
"""
app_state = AppState(request)
body = await parse_request(request, cls=ExportAsScriptRequest)
@@ -103,7 +129,20 @@ async def export_as_markdown(
request: Request,
) -> PlainTextResponse:
"""
- Export the notebook as a markdown.
+ requestBody:
+ content:
+ application/json:
+ schema:
+ $ref: "#/components/schemas/ExportAsMarkdownRequest"
+ responses:
+ 200:
+ description: Export the notebook as a markdown
+ content:
+ text/plain:
+ schema:
+ type: string
+ 400:
+ description: File must be saved before downloading
"""
app_state = AppState(request)
body = await parse_request(request, cls=ExportAsMarkdownRequest)
diff --git a/marimo/_server/api/endpoints/file_explorer.py b/marimo/_server/api/endpoints/file_explorer.py
index 8aeb32225e..dff8525dd0 100644
--- a/marimo/_server/api/endpoints/file_explorer.py
+++ b/marimo/_server/api/endpoints/file_explorer.py
@@ -42,7 +42,20 @@ async def list_files(
*,
request: Request,
) -> FileListResponse:
- """List files and directories in a given path."""
+ """
+ requestBody:
+ content:
+ application/json:
+ schema:
+ $ref: "#/components/schemas/FileListRequest"
+ responses:
+ 200:
+ description: List files and directories in a given path
+ content:
+ application/json:
+ schema:
+ $ref: "#/components/schemas/FileListResponse"
+ """
body = await parse_request(request, cls=FileListRequest)
root = body.path or file_system.get_root()
files = file_system.list_files(root)
@@ -55,7 +68,20 @@ async def file_details(
*,
request: Request,
) -> FileDetailsResponse:
- """Get details of a specific file or directory."""
+ """
+ requestBody:
+ content:
+ application/json:
+ schema:
+ $ref: "#/components/schemas/FileDetailsRequest"
+ responses:
+ 200:
+ description: Get details of a specific file or directory
+ content:
+ application/json:
+ schema:
+ $ref: "#/components/schemas/FileDetailsResponse"
+ """
body = await parse_request(request, cls=FileDetailsRequest)
# This fails if the file isn't encoded as utf-8
# TODO: support returning raw bytes
@@ -68,7 +94,20 @@ async def create_file_or_directory(
*,
request: Request,
) -> FileCreateResponse:
- """Create a new file or directory."""
+ """
+ requestBody:
+ content:
+ application/json:
+ schema:
+ $ref: "#/components/schemas/FileCreateRequest"
+ responses:
+ 200:
+ description: Create a new file or directory
+ content:
+ application/json:
+ schema:
+ $ref: "#/components/schemas/FileCreateResponse"
+ """
body = await parse_request(request, cls=FileCreateRequest)
try:
decoded_contents = (
@@ -92,7 +131,20 @@ async def delete_file_or_directory(
*,
request: Request,
) -> FileDeleteResponse:
- """Delete a file or directory."""
+ """
+ requestBody:
+ content:
+ application/json:
+ schema:
+ $ref: "#/components/schemas/FileDeleteRequest"
+ responses:
+ 200:
+ description: Delete a file or directory
+ content:
+ application/json:
+ schema:
+ $ref: "#/components/schemas/FileDeleteResponse"
+ """
body = await parse_request(request, cls=FileDeleteRequest)
try:
file_system.get_details(body.path)
@@ -109,7 +161,20 @@ async def move_file_or_directory(
*,
request: Request,
) -> FileMoveResponse:
- """Rename or move a file or directory."""
+ """
+ requestBody:
+ content:
+ application/json:
+ schema:
+ $ref: "#/components/schemas/FileMoveRequest"
+ responses:
+ 200:
+ description: Move a file or directory
+ content:
+ application/json:
+ schema:
+ $ref: "#/components/schemas/FileMoveResponse"
+ """
body = await parse_request(request, cls=FileMoveRequest)
try:
file_system.get_details(body.path)
@@ -126,7 +191,20 @@ async def update_file(
*,
request: Request,
) -> FileUpdateResponse:
- """Rename or move a file or directory."""
+ """
+ requestBody:
+ content:
+ application/json:
+ schema:
+ $ref: "#/components/schemas/FileUpdateRequest"
+ responses:
+ 200:
+ description: Update a file or directory
+ content:
+ application/json:
+ schema:
+ $ref: "#/components/schemas/FileUpdateResponse"
+ """
body = await parse_request(request, cls=FileUpdateRequest)
try:
file_system.get_details(body.path)
diff --git a/marimo/_server/api/endpoints/files.py b/marimo/_server/api/endpoints/files.py
index 0cab611afb..4346726e80 100644
--- a/marimo/_server/api/endpoints/files.py
+++ b/marimo/_server/api/endpoints/files.py
@@ -38,8 +38,18 @@ async def read_code(
*,
request: Request,
) -> ReadCodeResponse:
+ """
+ responses:
+ 200:
+ description: Read the code from the server
+ content:
+ application/json:
+ schema:
+ $ref: "#/components/schemas/ReadCodeResponse"
+ 400:
+ description: File must be saved before downloading
+ """
app_state = AppState(request)
- """Handler for reading code from the server."""
session = app_state.require_current_session()
if not session.app_file_manager.path:
@@ -59,7 +69,20 @@ async def rename_file(
*,
request: Request,
) -> BaseResponse:
- """Rename the current app."""
+ """
+ requestBody:
+ content:
+ application/json:
+ schema:
+ $ref: "#/components/schemas/RenameFileRequest"
+ responses:
+ 200:
+ description: Rename the current app
+ content:
+ application/json:
+ schema:
+ $ref: "#/components/schemas/SuccessResponse"
+ """
body = await parse_request(request, cls=RenameFileRequest)
app_state = AppState(request)
session = app_state.require_current_session()
@@ -82,7 +105,22 @@ async def open_file(
*,
request: Request,
) -> BaseResponse:
- """Open a file."""
+ """
+ requestBody:
+ content:
+ application/json:
+ schema:
+ $ref: "#/components/schemas/OpenFileRequest"
+ responses:
+ 200:
+ description: Open a file
+ content:
+ application/json:
+ schema:
+ $ref: "#/components/schemas/SuccessResponse"
+ 400:
+ description: File does not exist
+ """
body = await parse_request(request, cls=OpenFileRequest)
# Validate file exists
@@ -117,7 +155,20 @@ async def save(
*,
request: Request,
) -> BaseResponse:
- """Save the current app."""
+ """
+ requestBody:
+ content:
+ application/json:
+ schema:
+ $ref: "#/components/schemas/SaveRequest"
+ responses:
+ 200:
+ description: Save the current app
+ content:
+ application/json:
+ schema:
+ $ref: "#/components/schemas/SuccessResponse"
+ """
app_state = AppState(request)
body = await parse_request(request, cls=SaveRequest)
session = app_state.require_current_session()
@@ -132,7 +183,20 @@ async def save_app_config(
*,
request: Request,
) -> BaseResponse:
- """Save the current app."""
+ """
+ requestBody:
+ content:
+ application/json:
+ schema:
+ $ref: "#/components/schemas/SaveAppConfigurationRequest"
+ responses:
+ 200:
+ description: Save the app configuration
+ content:
+ application/json:
+ schema:
+ $ref: "#/components/schemas/SuccessResponse"
+ """
app_state = AppState(request)
body = await parse_request(request, cls=SaveAppConfigurationRequest)
session = app_state.require_current_session()
diff --git a/marimo/_server/api/endpoints/health.py b/marimo/_server/api/endpoints/health.py
index 1299eb07f8..6c57940d31 100644
--- a/marimo/_server/api/endpoints/health.py
+++ b/marimo/_server/api/endpoints/health.py
@@ -33,6 +33,36 @@ router.add_route("/healthz", health_check, methods=["GET"])
@router.get("/api/status")
@requires("edit")
async def status(request: Request) -> JSONResponse:
+ """
+ responses:
+ 200:
+ description: Get the status of the application
+ content:
+ application/json:
+ schema:
+ type: object
+ properties:
+ status:
+ type: string
+ filenames:
+ type: array
+ items:
+ type: string
+ mode:
+ type: string
+ sessions:
+ type: integer
+ version:
+ type: string
+ requirements:
+ type: array
+ items:
+ type: string
+ node_version:
+ type: string
+ lsp_running:
+ type: boolean
+ """
app_state = AppState(request)
files = [
session.app_file_manager.filename or "__new__"
@@ -54,6 +84,15 @@ async def status(request: Request) -> JSONResponse:
@router.get("/api/version")
async def version(request: Request) -> PlainTextResponse:
+ """
+ responses:
+ 200:
+ description: Get the version of the application
+ content:
+ text/plain:
+ schema:
+ type: string
+ """
del request # Unused
return PlainTextResponse(__version__)
@@ -61,6 +100,34 @@ async def version(request: Request) -> PlainTextResponse:
@router.get("/api/usage")
@requires("edit")
async def usage(request: Request) -> JSONResponse:
+ """
+ responses:
+ 200:
+ description: Get the current memory and CPU usage of the application
+ content:
+ application/json:
+ schema:
+ type: object
+ properties:
+ memory:
+ type: object
+ properties:
+ total:
+ type: integer
+ available:
+ type: integer
+ percent:
+ type: number
+ used:
+ type: integer
+ free:
+ type: integer
+ cpu:
+ type: object
+ properties:
+ percent:
+ type: number
+ """ # noqa: E501
del request
import psutil
diff --git a/marimo/_server/api/endpoints/home.py b/marimo/_server/api/endpoints/home.py
index bd408c8540..e963d8d1c3 100644
--- a/marimo/_server/api/endpoints/home.py
+++ b/marimo/_server/api/endpoints/home.py
@@ -36,7 +36,15 @@ async def read_code(
*,
request: Request,
) -> RecentFilesResponse:
- """Get the recent files."""
+ """
+ responses:
+ 200:
+ description: Get the recent files
+ content:
+ application/json:
+ schema:
+ $ref: "#/components/schemas/RecentFilesResponse"
+ """
app_state = AppState(request)
files = app_state.session_manager.recents.get_recents()
return RecentFilesResponse(files=files)
@@ -48,7 +56,20 @@ async def workspace_files(
*,
request: Request,
) -> WorkspaceFilesResponse:
- """Get the files in the workspace."""
+ """
+ requestBody:
+ content:
+ application/json:
+ schema:
+ $ref: "#/components/schemas/WorkspaceFilesRequest"
+ responses:
+ 200:
+ description: Get the files in the workspace
+ content:
+ application/json:
+ schema:
+ $ref: "#/components/schemas/WorkspaceFilesResponse"
+ """
body = await parse_request(request, cls=WorkspaceFilesRequest)
session_manager = AppState(request).session_manager
@@ -88,7 +109,15 @@ async def running_notebooks(
*,
request: Request,
) -> WorkspaceFilesResponse:
- """Get the running files."""
+ """
+ responses:
+ 200:
+ description: Get the running files
+ content:
+ application/json:
+ schema:
+ $ref: "#/components/schemas/WorkspaceFilesResponse"
+ """
app_state = AppState(request)
return WorkspaceFilesResponse(files=_get_active_sessions(app_state))
@@ -99,7 +128,20 @@ async def shutdown_session(
*,
request: Request,
) -> WorkspaceFilesResponse:
- """Shutdown the current session."""
+ """
+ requestBody:
+ content:
+ application/json:
+ schema:
+ $ref: "#/components/schemas/ShutdownSessionRequest"
+ responses:
+ 200:
+ description: Shutdown the current session
+ content:
+ application/json:
+ schema:
+ $ref: "#/components/schemas/WorkspaceFilesResponse"
+ """
app_state = AppState(request)
body = await parse_request(request, cls=ShutdownSessionRequest)
app_state.session_manager.close_session(body.session_id)
diff --git a/marimo/_server/api/endpoints/login.py b/marimo/_server/api/endpoints/login.py
index 53516e1506..009f5c2847 100644
--- a/marimo/_server/api/endpoints/login.py
+++ b/marimo/_server/api/endpoints/login.py
@@ -71,6 +71,32 @@ LOGIN_PAGE = """
@router.post("/login")
async def login_submit(request: Request) -> Response:
+ """
+ tags: [auth]
+ summary: Submit login form
+ requestBody:
+ content:
+ application/x-www-form-urlencoded:
+ schema:
+ type: object
+ properties:
+ password:
+ type: string
+ description: Access token or password
+ responses:
+ 302:
+ description: Redirect to the next URL
+ headers:
+ Location:
+ schema:
+ type: string
+ 200:
+ description: Login page
+ content:
+ text/html:
+ schema:
+ type: string
+ """
error = ""
redirect_url = request.query_params.get("next", "/")
diff --git a/marimo/_server/api/endpoints/ws.py b/marimo/_server/api/endpoints/ws.py
index a206443470..5faf6964f7 100644
--- a/marimo/_server/api/endpoints/ws.py
+++ b/marimo/_server/api/endpoints/ws.py
@@ -49,6 +49,11 @@ class WebSocketCodes(IntEnum):
async def websocket_endpoint(
websocket: WebSocket,
) -> None:
+ """
+ responses:
+ 200:
+ description: Websocket endpoint
+ """
app_state = AppState(websocket)
session_id = app_state.query_params(SESSION_QUERY_PARAM_KEY)
if session_id is None:
diff --git a/marimo/_server/router.py b/marimo/_server/router.py
index da33968798..0eb2c685ff 100644
--- a/marimo/_server/router.py
+++ b/marimo/_server/router.py
@@ -72,6 +72,9 @@ class APIRouter(Router):
return JSONResponse(content=json.dumps(response))
+ # Set docstring of wrapper_func to the docstring of func
+ wrapper_func.__doc__ = func.__doc__
+
self.add_route(
path=self.prefix + path,
endpoint=wrapper_func,
@@ -115,6 +118,9 @@ class APIRouter(Router):
return response # type: ignore[no-any-return]
+ # Set docstring of wrapper_func to the docstring of func
+ wrapper_func.__doc__ = func.__doc__
+
self.add_route(
path=self.prefix + path,
endpoint=wrapper_func,
diff --git a/marimo/_utils/dataclass_to_openapi.py b/marimo/_utils/dataclass_to_openapi.py
new file mode 100644
index 0000000000..c9dc599033
--- /dev/null
+++ b/marimo/_utils/dataclass_to_openapi.py
@@ -0,0 +1,164 @@
+# Copyright 2024 Marimo. All rights reserved.
+from __future__ import annotations
+
+import dataclasses
+from enum import Enum
+from typing import (
+ Any,
+ Dict,
+ List,
+ Literal,
+ Optional,
+ Type,
+ Union,
+ get_args,
+ get_origin,
+ get_type_hints,
+)
+
+
+def _python_type_to_openapi_type(
+ py_type: Any, processed_classes: Dict[Type[Any], str]
+) -> Dict[str, Any]:
+ """
+ Convert a Python type to an OpenAPI schema.
+ """
+ origin = get_origin(py_type)
+ if origin is Union:
+ args = get_args(py_type)
+ if type(None) in args:
+ non_none_args = [arg for arg in args if arg is not type(None)]
+ if len(non_none_args) == 1:
+ return {
+ **_python_type_to_openapi_type(
+ non_none_args[0], processed_classes
+ ),
+ "nullable": True,
+ }
+ else:
+ return {
+ "oneOf": [
+ _python_type_to_openapi_type(arg, processed_classes)
+ for arg in non_none_args
+ ],
+ "nullable": True,
+ }
+ else:
+ return {
+ "oneOf": [
+ _python_type_to_openapi_type(arg, processed_classes)
+ for arg in args
+ ]
+ }
+ elif origin in (list, List):
+ (item_type,) = get_args(py_type)
+ return {
+ "type": "array",
+ "items": _python_type_to_openapi_type(
+ item_type, processed_classes
+ ),
+ }
+ elif origin in (dict, Dict):
+ _key_type, value_type = get_args(py_type)
+ return {
+ "type": "object",
+ "additionalProperties": _python_type_to_openapi_type(
+ value_type, processed_classes
+ ),
+ }
+ elif origin is Literal:
+ return {"enum": list(get_args(py_type))}
+ elif origin is tuple:
+ args = get_args(py_type)
+ if len(args) == 2 and isinstance(args[1], type(Ellipsis)):
+ return {
+ "type": "array",
+ "items": _python_type_to_openapi_type(
+ args[0], processed_classes
+ ),
+ }
+ else:
+ return {
+ "type": "array",
+ "prefixItems": [
+ _python_type_to_openapi_type(arg, processed_classes)
+ for arg in args
+ ],
+ }
+ elif dataclasses.is_dataclass(py_type):
+ return dataclass_to_openapi_spec(py_type, processed_classes)
+ elif py_type is Any:
+ return {}
+ elif py_type is object:
+ return {"type": "object", "additionalProperties": True}
+ elif py_type is str:
+ return {"type": "string"}
+ elif py_type is int:
+ return {"type": "integer"}
+ elif py_type is float:
+ return {"type": "number"}
+ elif py_type is bool:
+ return {"type": "boolean"}
+ elif isinstance(py_type, type) and issubclass(py_type, Enum):
+ return {"type": "string", "enum": [e.value for e in py_type]}
+ else:
+ raise ValueError(f"Unsupported type: {py_type}")
+
+
+def dataclass_to_openapi_spec(
+ cls: Type[Any], processed_classes: Optional[Dict[Type[Any], str]] = None
+) -> Dict[str, Any]:
+ """Convert a dataclass to an OpenAPI schema.
+
+ Args:
+ cls (Type[Any]): The dataclass to convert.
+
+ Raises:
+ ValueError: If cls is not a dataclass.
+
+ Returns:
+ Dict[str, Any]: The OpenAPI schema.
+ """
+ if processed_classes is None:
+ processed_classes = {}
+
+ if not dataclasses.is_dataclass(cls):
+ raise ValueError(f"{cls} is not a dataclass")
+
+ if cls in processed_classes:
+ return {"$ref": f"#/components/schemas/{processed_classes[cls]}"}
+
+ schema_name = cls.__name__
+ processed_classes[cls] = schema_name
+
+ fields: tuple[dataclasses.Field[Any], ...] = dataclasses.fields(cls)
+ properties: Dict[str, Dict[str, Any]] = {}
+ required: List[str] = []
+
+ for field in fields:
+ field_type = get_type_hints(cls)[field.name]
+ properties[field.name] = _python_type_to_openapi_type(
+ field_type, processed_classes
+ )
+ if (
+ field.default is dataclasses.MISSING
+ and field.default_factory is dataclasses.MISSING
+ and not _is_optional(field_type)
+ ):
+ required.append(field.name)
+
+ schema: Dict[str, Any] = {
+ "type": "object",
+ "properties": properties,
+ }
+ if required:
+ schema["required"] = required
+
+ return schema
+
+
+def _is_optional(field: dataclasses.Field[Any]) -> bool:
+ """
+ Check if a field is Optional
+ """
+ return get_origin(field) is Union and type(None) in get_args(field)
diff --git a/openapi/api.yaml b/openapi/api.yaml
new file mode 100644
index 0000000000..8449a69eeb
--- /dev/null
+++ b/openapi/api.yaml
@@ -0,0 +1,1355 @@
+components:
+ schemas:
+ AiCompletionRequest:
+ properties:
+ code:
+ type: string
+ include_other_code:
+ type: string
+ prompt:
+ type: string
+ required:
+ - prompt
+ - include_other_code
+ - code
+ type: object
+ AppMetadata:
+ properties:
+ cli_args:
+ additionalProperties:
+ oneOf:
+ - type: string
+ - type: boolean
+ - type: integer
+ - type: number
+ - items:
+ oneOf:
+ - type: string
+ - type: boolean
+ - type: integer
+ - type: number
+ type: array
+ type: object
+ filename:
+ nullable: true
+ type: string
+ query_params:
+ additionalProperties:
+ oneOf:
+ - type: string
+ - items:
+ type: string
+ type: array
+ type: object
+ required:
+ - query_params
+ - cli_args
+ type: object
+ BaseResponse:
+ properties:
+ success:
+ type: boolean
+ required:
+ - success
+ type: object
+ CellConfig:
+ properties:
+ disabled:
+ type: boolean
+ hide_code:
+ type: boolean
+ type: object
+ CompletionRequest:
+ properties:
+ cell_id:
+ type: string
+ document:
+ type: string
+ id:
+ type: string
+ required:
+ - id
+ - document
+ - cell_id
+ type: object
+ CreationRequest:
+ properties:
+ execution_requests:
+ items:
+ $ref: '#/components/schemas/ExecutionRequest'
+ type: array
+ set_ui_element_value_request:
+ properties:
+ ids_and_values:
+ items:
+ prefixItems:
+ - type: string
+ - {}
+ type: array
+ type: array
+ token:
+ type: string
+ required:
+ - ids_and_values
+ type: object
+ required:
+ - execution_requests
+ - set_ui_element_value_request
+ type: object
+ DeleteRequest:
+ properties:
+ cell_id:
+ type: string
+ required:
+ - cell_id
+ type: object
+ ExecuteMultipleRequest:
+ properties:
+ execution_requests:
+ items:
+ $ref: '#/components/schemas/ExecutionRequest'
+ type: array
+ required:
+ - execution_requests
+ type: object
+ ExecuteStaleRequest:
+ properties: {}
+ type: object
+ ExecutionRequest:
+ properties:
+ cell_id:
+ type: string
+ code:
+ type: string
+ required:
+ - cell_id
+ - code
+ type: object
+ ExportAsHTMLRequest:
+ properties:
+ asset_url:
+ nullable: true
+ type: string
+ download:
+ type: boolean
+ files:
+ items:
+ type: string
+ type: array
+ include_code:
+ type: boolean
+ required:
+ - download
+ - files
+ - include_code
+ type: object
+ ExportAsMarkdownRequest:
+ properties:
+ download:
+ type: boolean
+ required:
+ - download
+ type: object
+ ExportAsScriptRequest:
+ properties:
+ download:
+ type: boolean
+ required:
+ - download
+ type: object
+ FileCreateRequest:
+ properties:
+ contents:
+ nullable: true
+ type: string
+ name:
+ type: string
+ path:
+ type: string
+ type:
+ type: string
+ required:
+ - path
+ - type
+ - name
+ type: object
+ FileCreateResponse:
+ properties:
+ info:
+ $ref: '#/components/schemas/FileInfo'
+ nullable: true
+ message:
+ nullable: true
+ type: string
+ success:
+ type: boolean
+ required:
+ - success
+ type: object
+ FileDeleteRequest:
+ properties:
+ path:
+ type: string
+ required:
+ - path
+ type: object
+ FileDeleteResponse:
+ properties:
+ message:
+ nullable: true
+ type: string
+ success:
+ type: boolean
+ required:
+ - success
+ type: object
+ FileDetailsRequest:
+ properties:
+ path:
+ type: string
+ required:
+ - path
+ type: object
+ FileDetailsResponse:
+ properties:
+ contents:
+ nullable: true
+ type: string
+ file:
+ $ref: '#/components/schemas/FileInfo'
+ mime_type:
+ nullable: true
+ type: string
+ required:
+ - file
+ type: object
+ FileInfo:
+ properties:
+ children:
+ items:
+ $ref: '#/components/schemas/FileInfo'
+ type: array
+ id:
+ type: string
+ is_directory:
+ type: boolean
+ is_marimo_file:
+ type: boolean
+ last_modified_date:
+ nullable: true
+ type: number
+ name:
+ type: string
+ path:
+ type: string
+ required:
+ - id
+ - path
+ - name
+ - is_directory
+ - is_marimo_file
+ type: object
+ FileListRequest:
+ properties:
+ path:
+ nullable: true
+ type: string
+ type: object
+ FileListResponse:
+ properties:
+ files:
+ items:
+ $ref: '#/components/schemas/FileInfo'
+ type: array
+ root:
+ type: string
+ required:
+ - files
+ - root
+ type: object
+ FileMoveRequest:
+ properties:
+ new_path:
+ type: string
+ path:
+ type: string
+ required:
+ - path
+ - new_path
+ type: object
+ FileMoveResponse:
+ properties:
+ info:
+ $ref: '#/components/schemas/FileInfo'
+ nullable: true
+ message:
+ nullable: true
+ type: string
+ success:
+ type: boolean
+ required:
+ - success
+ type: object
+ FileUpdateRequest:
+ properties:
+ contents:
+ type: string
+ path:
+ type: string
+ required:
+ - path
+ - contents
+ type: object
+ FileUpdateResponse:
+ properties:
+ info:
+ $ref: '#/components/schemas/FileInfo'
+ nullable: true
+ message:
+ nullable: true
+ type: string
+ success:
+ type: boolean
+ required:
+ - success
+ type: object
+ FormatRequest:
+ properties:
+ codes:
+ additionalProperties:
+ type: string
+ type: object
+ line_length:
+ type: integer
+ required:
+ - codes
+ - line_length
+ type: object
+ FormatResponse:
+ properties:
+ codes:
+ additionalProperties:
+ type: string
+ type: object
+ required:
+ - codes
+ type: object
+ FunctionCallRequest:
+ properties:
+ args:
+ additionalProperties: {}
+ type: object
+ function_call_id:
+ type: string
+ function_name:
+ type: string
+ namespace:
+ type: string
+ required:
+ - function_call_id
+ - namespace
+ - function_name
+ - args
+ type: object
+ InstallMissingPackagesRequest:
+ properties:
+ manager:
+ type: string
+ required:
+ - manager
+ type: object
+ InstantiateRequest:
+ properties:
+ object_ids:
+ items:
+ type: string
+ type: array
+ values:
+ items:
+ nullable: true
+ oneOf:
+ - type: string
+ - type: boolean
+ - type: integer
+ - type: number
+ type: array
+ required:
+ - object_ids
+ - values
+ type: object
+ MarimoConfig:
+ properties:
+ ai:
+ properties:
+ open_ai:
+ properties:
+ api_key:
+ type: string
+ base_url:
+ type: string
+ model:
+ type: string
+ required:
+ - api_key
+ - model
+ - base_url
+ type: object
+ required:
+ - open_ai
+ type: object
+ completion:
+ properties:
+ activate_on_typing:
+ type: boolean
+ copilot:
+ type: boolean
+ required:
+ - activate_on_typing
+ - copilot
+ type: object
+ display:
+ properties:
+ cell_output:
+ enum:
+ - above
+ - below
+ code_editor_font_size:
+ type: integer
+ default_width:
+ enum:
+ - normal
+ - compact
+ - medium
+ - full
+ theme:
+ enum:
+ - light
+ - dark
+ - system
+ required:
+ - theme
+ - code_editor_font_size
+ - cell_output
+ - default_width
+ type: object
+ experimental:
+ additionalProperties: {}
+ type: object
+ formatting:
+ properties:
+ line_length:
+ type: integer
+ required:
+ - line_length
+ type: object
+ keymap:
+ properties:
+ overrides:
+ additionalProperties:
+ type: string
+ type: object
+ preset:
+ enum:
+ - default
+ - vim
+ required:
+ - preset
+ - overrides
+ type: object
+ package_management:
+ properties:
+ manager:
+ enum:
+ - pip
+ - rye
+ - uv
+ - poetry
+ - pixi
+ required:
+ - manager
+ type: object
+ runtime:
+ properties:
+ auto_instantiate:
+ type: boolean
+ auto_reload:
+ enum:
+ - 'off'
+ - lazy
+ - autorun
+ on_cell_change:
+ enum:
+ - lazy
+ - autorun
+ required:
+ - auto_instantiate
+ - auto_reload
+ - on_cell_change
+ type: object
+ save:
+ properties:
+ autosave:
+ enum:
+ - 'off'
+ - after_delay
+ autosave_delay:
+ type: integer
+ format_on_save:
+ type: boolean
+ required:
+ - autosave
+ - autosave_delay
+ - format_on_save
+ type: object
+ server:
+ properties:
+ browser:
+ oneOf:
+ - enum:
+ - default
+ - type: string
+ follow_symlink:
+ type: boolean
+ required:
+ - browser
+ - follow_symlink
+ type: object
+ required:
+ - completion
+ - display
+ - formatting
+ - keymap
+ - runtime
+ - save
+ - server
+ - package_management
+ - ai
+ - experimental
+ type: object
+ MarimoFile:
+ properties:
+ initialization_id:
+ nullable: true
+ type: string
+ last_modified:
+ type: number
+ name:
+ type: string
+ path:
+ type: string
+ session_id:
+ nullable: true
+ type: string
+ required:
+ - name
+ - path
+ - last_modified
+ type: object
+ OpenFileRequest:
+ properties:
+ path:
+ type: string
+ required:
+ - path
+ type: object
+ PreviewDatasetColumnRequest:
+ properties:
+ column_name:
+ type: string
+ source:
+ type: string
+ table_name:
+ type: string
+ required:
+ - source
+ - table_name
+ - column_name
+ type: object
+ ReadCodeResponse:
+ properties:
+ contents:
+ type: string
+ required:
+ - contents
+ type: object
+ RecentFilesResponse:
+ properties:
+ files:
+ items:
+ $ref: '#/components/schemas/MarimoFile'
+ type: array
+ required:
+ - files
+ type: object
+ RenameFileRequest:
+ properties:
+ filename:
+ type: string
+ required:
+ - filename
+ type: object
+ RunRequest:
+ properties:
+ cell_ids:
+ items:
+ type: string
+ type: array
+ codes:
+ items:
+ type: string
+ type: array
+ required:
+ - cell_ids
+ - codes
+ type: object
+ SaveAppConfigurationRequest:
+ properties:
+ config:
+ additionalProperties: {}
+ type: object
+ required:
+ - config
+ type: object
+ SaveRequest:
+ properties:
+ cell_ids:
+ items:
+ type: string
+ type: array
+ codes:
+ items:
+ type: string
+ type: array
+ configs:
+ items:
+ $ref: '#/components/schemas/CellConfig'
+ type: array
+ filename:
+ type: string
+ layout:
+ additionalProperties: {}
+ nullable: true
+ type: object
+ names:
+ items:
+ type: string
+ type: array
+ required:
+ - cell_ids
+ - codes
+ - names
+ - configs
+ - filename
+ type: object
+ SaveUserConfigurationRequest:
+ properties:
+ config:
+ $ref: '#/components/schemas/MarimoConfig'
+ required:
+ - config
+ type: object
+ SetCellConfigRequest:
+ properties:
+ configs:
+ additionalProperties:
+ additionalProperties:
+ additionalProperties: true
+ type: object
+ type: object
+ type: object
+ required:
+ - configs
+ type: object
+ SetUIElementValueRequest:
+ properties:
+ ids_and_values:
+ items:
+ prefixItems:
+ - type: string
+ - {}
+ type: array
+ type: array
+ token:
+ type: string
+ required:
+ - ids_and_values
+ type: object
+ SetUserConfigRequest:
+ properties:
+ config:
+ $ref: '#/components/schemas/MarimoConfig'
+ required:
+ - config
+ type: object
+ ShutdownSessionRequest:
+ properties:
+ session_id:
+ type: string
+ required:
+ - session_id
+ type: object
+ Snippet:
+ properties:
+ sections:
+ items:
+ $ref: '#/components/schemas/SnippetSection'
+ type: array
+ title:
+ type: string
+ required:
+ - title
+ - sections
+ type: object
+ SnippetSection:
+ properties:
+ code:
+ nullable: true
+ type: string
+ html:
+ nullable: true
+ type: string
+ id:
+ type: string
+ required:
+ - id
+ type: object
+ Snippets:
+ properties:
+ snippets:
+ items:
+ $ref: '#/components/schemas/Snippet'
+ type: array
+ required:
+ - snippets
+ type: object
+ StdinRequest:
+ properties:
+ text:
+ type: string
+ required:
+ - text
+ type: object
+ StopRequest:
+ properties: {}
+ type: object
+ SuccessResponse:
+ properties:
+ success:
+ type: boolean
+ type: object
+ UpdateComponentValuesRequest:
+ properties:
+ object_ids:
+ items:
+ type: string
+ type: array
+ values:
+ items:
+ nullable: true
+ oneOf:
+ - type: string
+ - type: boolean
+ - type: integer
+ - type: number
+ type: array
+ required:
+ - object_ids
+ - values
+ type: object
+ WorkspaceFilesRequest:
+ properties:
+ include_markdown:
+ type: boolean
+ type: object
+ WorkspaceFilesResponse:
+ properties:
+ files:
+ items:
+ $ref: '#/components/schemas/MarimoFile'
+ type: array
+ required:
+ - files
+ type: object
+info:
+ title: marimo API
+ version: 0.6.17
+openapi: 3.1.0
+paths:
+ /@file/{filename_and_length}:
+ get:
+ parameters:
+ - description: The filename and byte length of the virtual file
+ in: path
+ name: filename_and_length
+ required: true
+ schema:
+ type: string
+ responses:
+ 200:
+ content:
+ application/octet-stream:
+ schema:
+ type: string
+ description: Get a virtual file
+ 404:
+ description: Invalid byte length in virtual file request
+ /api/ai/completion:
+ post:
+ requestBody:
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/AiCompletionRequest'
+ description: The prompt to get AI completion for
+ required: true
+ responses:
+ 200:
+ content:
+ application/json:
+ schema:
+ additionalProperties: true
+ type: object
+ description: Get AI completion for a prompt
+ /api/datasources/preview_column:
+ post:
+ requestBody:
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/PreviewDatasetColumnRequest'
+ responses:
+ 200:
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/SuccessResponse'
+ description: Preview a column in a dataset
+ /api/documentation/snippets:
+ get:
+ responses:
+ 200:
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/Snippets'
+ description: Load the snippets for the documentation page
+ /api/export/html:
+ post:
+ requestBody:
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/ExportAsHTMLRequest'
+ responses:
+ 200:
+ content:
+ text/html:
+ schema:
+ type: string
+ description: Export the notebook as HTML
+ 400:
+ description: File must be saved before downloading
+ /api/export/markdown:
+ post:
+ requestBody:
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/ExportAsMarkdownRequest'
+ responses:
+ 200:
+ content:
+ text/plain:
+ schema:
+ type: string
+ description: Export the notebook as a markdown
+ 400:
+ description: File must be saved before downloading
+ /api/export/script:
+ post:
+ requestBody:
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/ExportAsScriptRequest'
+ responses:
+ 200:
+ content:
+ text/plain:
+ schema:
+ type: string
+ description: Export the notebook as a script
+ 400:
+ description: File must be saved before downloading
+ /api/files/create:
+ post:
+ requestBody:
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/FileCreateRequest'
+ responses:
+ 200:
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/FileCreateResponse'
+ description: Create a new file or directory
+ /api/files/delete:
+ post:
+ requestBody:
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/FileDeleteRequest'
+ responses:
+ 200:
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/FileDeleteResponse'
+ description: Delete a file or directory
+ /api/files/file_details:
+ post:
+ requestBody:
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/FileDetailsRequest'
+ responses:
+ 200:
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/FileDetailsResponse'
+ description: Get details of a specific file or directory
+ /api/files/list_files:
+ post:
+ requestBody:
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/FileListRequest'
+ responses:
+ 200:
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/FileListResponse'
+ description: List files and directories in a given path
+ /api/files/move:
+ post:
+ requestBody:
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/FileMoveRequest'
+ responses:
+ 200:
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/FileMoveResponse'
+ description: Move a file or directory
+ /api/files/update:
+ post:
+ requestBody:
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/FileUpdateRequest'
+ responses:
+ 200:
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/FileUpdateResponse'
+ description: Update a file or directory
+ /api/home/recent_files:
+ post:
+ responses:
+ 200:
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/RecentFilesResponse'
+ description: Get the recent files
+ /api/home/running_notebooks:
+ post:
+ responses:
+ 200:
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/WorkspaceFilesResponse'
+ description: Get the running files
+ /api/home/shutdown_session:
+ post:
+ requestBody:
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/ShutdownSessionRequest'
+ responses:
+ 200:
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/WorkspaceFilesResponse'
+ description: Shutdown the current session
+ /api/home/workspace_files:
+ post:
+ requestBody:
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/WorkspaceFilesRequest'
+ responses:
+ 200:
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/WorkspaceFilesResponse'
+ description: Get the files in the workspace
+ /api/kernel/code_autocomplete:
+ post:
+ requestBody:
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/CompletionRequest'
+ responses:
+ 200:
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/SuccessResponse'
+ description: Complete a code fragment
+ /api/kernel/delete:
+ post:
+ requestBody:
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/DeleteRequest'
+ responses:
+ 200:
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/SuccessResponse'
+ description: Delete a cell
+ /api/kernel/format:
+ post:
+ requestBody:
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/FormatRequest'
+ responses:
+ 200:
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/FormatResponse'
+ description: Format code
+ /api/kernel/function_call:
+ post:
+ requestBody:
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/FunctionCallRequest'
+ responses:
+ 200:
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/SuccessResponse'
+ description: Invoke an RPC
+ /api/kernel/install_missing_packages:
+ post:
+ requestBody:
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/InstallMissingPackagesRequest'
+ responses:
+ 200:
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/SuccessResponse'
+ description: Install missing packages
+ /api/kernel/instantiate:
+ post:
+ requestBody:
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/InstantiateRequest'
+ responses:
+ 200:
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/SuccessResponse'
+ description: Instantiate a component
+ /api/kernel/interrupt:
+ post:
+ responses:
+ 200:
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/SuccessResponse'
+ description: Interrupt the kernel's execution
+ /api/kernel/open:
+ post:
+ requestBody:
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/OpenFileRequest'
+ responses:
+ 200:
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/SuccessResponse'
+ description: Open a file
+ 400:
+ description: File does not exist
+ /api/kernel/read_code:
+ post:
+ responses:
+ 200:
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/ReadCodeResponse'
+ description: Read the code from the server
+ 400:
+ description: File must be saved before downloading
+ /api/kernel/rename:
+ post:
+ requestBody:
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/RenameFileRequest'
+ responses:
+ 200:
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/SuccessResponse'
+ description: Rename the current app
+ /api/kernel/restart_session:
+ post:
+ responses:
+ 200:
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/SuccessResponse'
+ description: Restart the current session without affecting other sessions.
+ /api/kernel/run:
+ post:
+ requestBody:
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/RunRequest'
+ responses:
+ 200:
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/SuccessResponse'
+ description: Run a cell. Updates cell code in the kernel if needed; registers
+ new cells for unseen cell IDs. Only allowed in edit mode.
+ /api/kernel/save:
+ post:
+ requestBody:
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/SaveRequest'
+ responses:
+ 200:
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/SuccessResponse'
+ description: Save the current app
+ /api/kernel/save_app_config:
+ post:
+ requestBody:
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/SaveAppConfigurationRequest'
+ responses:
+ 200:
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/SuccessResponse'
+ description: Save the app configuration
+ /api/kernel/save_user_config:
+ post:
+ responses:
+ 200:
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/SuccessResponse'
+ description: Update the user config on disk and in the kernel. Only allowed
+ in edit mode.
+ /api/kernel/set_cell_config:
+ post:
+ requestBody:
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/SetCellConfigRequest'
+ responses:
+ 200:
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/SuccessResponse'
+ description: Set the configuration of a cell
+ /api/kernel/set_ui_element_value:
+ post:
+ requestBody:
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/UpdateComponentValuesRequest'
+ responses:
+ 200:
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/SuccessResponse'
+ description: Set UI element values
+ /api/kernel/shutdown:
+ post:
+ responses:
+ 200:
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/SuccessResponse'
+ description: Shutdown the kernel
+ /api/kernel/stdin:
+ post:
+ requestBody:
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/StdinRequest'
+ responses:
+ 200:
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/SuccessResponse'
+ description: Send input to the stdin stream
+ /api/status:
+ get:
+ responses:
+ 200:
+ content:
+ application/json:
+ schema:
+ properties:
+ filenames:
+ items:
+ type: string
+ type: array
+ lsp_running:
+ type: boolean
+ mode:
+ type: string
+ node_version:
+ type: string
+ requirements:
+ items:
+ type: string
+ type: array
+ sessions:
+ type: integer
+ status:
+ type: string
+ version:
+ type: string
+ type: object
+ description: Get the status of the application
+ /api/usage:
+ get:
+ responses:
+ 200:
+ content:
+ application/json:
+ schema:
+ properties:
+ cpu:
+ properties:
+ percent:
+ type: number
+ type: object
+ memory:
+ properties:
+ available:
+ type: integer
+ free:
+ type: integer
+ percent:
+ type: number
+ total:
+ type: integer
+ used:
+ type: integer
+ type: object
+ type: object
+ description: Get the current memory and CPU usage of the application
+ /api/version:
+ get:
+ responses:
+ 200:
+ content:
+ text/plain:
+ schema:
+ type: string
+ description: Get the version of the application
+ /auth/login:
+ post:
+ requestBody:
+ content:
+ application/x-www-form-urlencoded:
+ schema:
+ properties:
+ password:
+ description: Access token or password
+ type: string
+ type: object
+ responses:
+ 200:
+ content:
+ text/html:
+ schema:
+ type: string
+ description: Login page
+ 302:
+ description: Redirect to the next URL
+ headers:
+ Location:
+ schema:
+ type: string
+ summary: Submit login form
+ tags:
+ - auth
+
diff --git a/openapi/package.json b/openapi/package.json
new file mode 100644
index 0000000000..fcaadfb2b0
--- /dev/null
+++ b/openapi/package.json
@@ -0,0 +1,22 @@
+{
+ "name": "@marimo-team/marimo-api",
+ "version": "0.1.0",
+ "private": true,
+ "main": "src/index.ts",
+ "types": "src/index.ts",
+ "type": "module",
+ "license": "Apache-2.0",
+ "files": [
+ "dist"
+ ],
+ "scripts": {
+ "codegen": "npx openapi-typescript ./api.yaml -o ./src/api.d.ts"
+ },
+ "devDependencies": {
+ "openapi-typescript": "^6.7.6",
+ "typescript": "^5.4.5"
+ },
+ "dependencies": {
+ "openapi-fetch": "^0.9.7"
+ }
+}
diff --git a/openapi/pnpm-lock.yaml b/openapi/pnpm-lock.yaml
new file mode 100644
index 0000000000..d1e74d34c6
--- /dev/null
+++ b/openapi/pnpm-lock.yaml
@@ -0,0 +1,202 @@
+lockfileVersion: '6.0'
+
+settings:
+ autoInstallPeers: true
+ excludeLinksFromLockfile: false
+
+dependencies:
+ openapi-fetch:
+ specifier: ^0.9.7
+ version: 0.9.7
+
+devDependencies:
+ openapi-typescript:
+ specifier: ^6.7.6
+ version: 6.7.6
+ typescript:
+ specifier: ^5.4.5
+ version: 5.4.5
+
+packages:
+
+ /@fastify/[email protected]:
+ resolution: {integrity: sha512-vBZP4NlzfOlerQTnba4aqZoMhE/a9HY7HRqoOPaETQcSQuWEIyZMHGfVu6w9wGtGK5fED5qRs2DteVCjOH60sA==}
+ engines: {node: '>=14'}
+ dev: true
+
+ /@nodelib/[email protected]:
+ resolution: {integrity: sha512-vq24Bq3ym5HEQm2NKCr3yXDwjc7vTsEThRDnkp2DK9p1uqLR+DHurm/NOTo0KG7HYHU7eppKZj3MyqYuMBf62g==}
+ engines: {node: '>= 8'}
+ dependencies:
+ '@nodelib/fs.stat': 2.0.5
+ run-parallel: 1.2.0
+ dev: true
+
+ /@nodelib/[email protected]:
+ resolution: {integrity: sha512-RkhPPp2zrqDAQA/2jNhnztcPAlv64XdhIp7a7454A5ovI7Bukxgt7MX7udwAu3zg1DcpPU0rz3VV1SeaqvY4+A==}
+ engines: {node: '>= 8'}
+ dev: true
+
+ /@nodelib/[email protected]:
+ resolution: {integrity: sha512-oGB+UxlgWcgQkgwo8GcEGwemoTFt3FIO9ababBmaGwXIoBKZ+GTy0pP185beGg7Llih/NSHSV2XAs1lnznocSg==}
+ engines: {node: '>= 8'}
+ dependencies:
+ '@nodelib/fs.scandir': 2.1.5
+ fastq: 1.17.1
+ dev: true
+
+ resolution: {integrity: sha512-/6w/C21Pm1A7aZitlI5Ni/2J6FFQN8i1Cvz3kHABAAbw93v/NlvKdVOqz7CCWz/3iv/JplRSEEZ83XION15ovw==}
+ engines: {node: '>=6'}
+ dev: true
+
+ resolution: {integrity: sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==}
+ dev: true
+
+ resolution: {integrity: sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==}
+ engines: {node: '>=8'}
+ dependencies:
+ fill-range: 7.1.1
+ dev: true
+
+ resolution: {integrity: sha512-oX2ruAFQwf/Orj8m737Y5adxDQO0LAB7/S5MnxCdTNDd4p6BsyIVsv9JQsATbTSq8KHRpLwIHbVlUNatxd+1Ow==}
+ engines: {node: '>=8.6.0'}
+ dependencies:
+ '@nodelib/fs.stat': 2.0.5
+ '@nodelib/fs.walk': 1.2.8
+ glob-parent: 5.1.2
+ merge2: 1.4.1
+ micromatch: 4.0.7
+ dev: true
+
+ resolution: {integrity: sha512-sRVD3lWVIXWg6By68ZN7vho9a1pQcN/WBFaAAsDDFzlJjvoGx0P8z7V1t72grFJfJhu3YPZBuu25f7Kaw2jN1w==}
+ dependencies:
+ reusify: 1.0.4
+ dev: true
+
+ resolution: {integrity: sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==}
+ engines: {node: '>=8'}
+ dependencies:
+ to-regex-range: 5.0.1
+ dev: true
+
+ resolution: {integrity: sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==}
+ engines: {node: '>= 6'}
+ dependencies:
+ is-glob: 4.0.3
+ dev: true
+
+ resolution: {integrity: sha512-SbKbANkN603Vi4jEZv49LeVJMn4yGwsbzZworEoyEiutsN3nJYdbO36zfhGJ6QEDpOZIFkDtnq5JRxmvl3jsoQ==}
+ engines: {node: '>=0.10.0'}
+ dev: true
+
+ resolution: {integrity: sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg==}
+ engines: {node: '>=0.10.0'}
+ dependencies:
+ is-extglob: 2.1.1
+ dev: true
+
+ resolution: {integrity: sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==}
+ engines: {node: '>=0.12.0'}
+ dev: true
+
+ resolution: {integrity: sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==}
+ hasBin: true
+ dependencies:
+ argparse: 2.0.1
+ dev: true
+
+ resolution: {integrity: sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg==}
+ engines: {node: '>= 8'}
+ dev: true
+
+ resolution: {integrity: sha512-LPP/3KorzCwBxfeUuZmaR6bG2kdeHSbe0P2tY3FLRU4vYrjYz5hI4QZwV0njUx3jeuKe67YukQ1LSPZBKDqO/Q==}
+ engines: {node: '>=8.6'}
+ dependencies:
+ braces: 3.0.3
+ picomatch: 2.3.1
+ dev: true
+
+ resolution: {integrity: sha512-NMp/GEmWSGO0b2d731IdGXcMP2PF85Rk1q+oy2Mx/DYMdP3pgTZTRamKxgZpkHhM4iOVsyD1iP5HKL9Fr6CH2Q==}
+ dependencies:
+ openapi-typescript-helpers: 0.0.8
+ dev: false
+
+ resolution: {integrity: sha512-1eNjQtbfNi5Z/kFhagDIaIRj6qqDzhjNJKz8cmMW0CVdGwT6e1GLbAfgI0d28VTJa1A8jz82jm/4dG8qNoNS8g==}
+ dev: false
+
+ resolution: {integrity: sha512-c/hfooPx+RBIOPM09GSxABOZhYPblDoyaGhqBkD/59vtpN21jEuWKDlM0KYTvqJVlSYjKs0tBcIdeXKChlSPtw==}
+ hasBin: true
+ dependencies:
+ ansi-colors: 4.1.3
+ fast-glob: 3.3.2
+ js-yaml: 4.1.0
+ supports-color: 9.4.0
+ undici: 5.28.4
+ yargs-parser: 21.1.1
+ dev: true
+
+ resolution: {integrity: sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==}
+ engines: {node: '>=8.6'}
+ dev: true
+
+ resolution: {integrity: sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A==}
+ dev: true
+
+ resolution: {integrity: sha512-U9nH88a3fc/ekCF1l0/UP1IosiuIjyTh7hBvXVMHYgVcfGvt897Xguj2UOLDeI5BG2m7/uwyaLVT6fbtCwTyzw==}
+ engines: {iojs: '>=1.0.0', node: '>=0.10.0'}
+ dev: true
+
+ resolution: {integrity: sha512-5l4VyZR86LZ/lDxZTR6jqL8AFE2S0IFLMP26AbjsLVADxHdhB/c0GUsH+y39UfCi3dzz8OlQuPmnaJOMoDHQBA==}
+ dependencies:
+ queue-microtask: 1.2.3
+ dev: true
+
+ resolution: {integrity: sha512-VL+lNrEoIXww1coLPOmiEmK/0sGigko5COxI09KzHc2VJXJsQ37UaQ+8quuxjDeA7+KnLGTWRyOXSLLR2Wb4jw==}
+ engines: {node: '>=12'}
+ dev: true
+
+ resolution: {integrity: sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==}
+ engines: {node: '>=8.0'}
+ dependencies:
+ is-number: 7.0.0
+ dev: true
+
+ resolution: {integrity: sha512-vcI4UpRgg81oIRUFwR0WSIHKt11nJ7SAVlYNIu+QpqeyXP+gpQJy/Z4+F0aGxSE4MqwjyXvW/TzgkLAx2AGHwQ==}
+ engines: {node: '>=14.17'}
+ hasBin: true
+ dev: true
+
+ resolution: {integrity: sha512-72RFADWFqKmUb2hmmvNODKL3p9hcB6Gt2DOQMis1SEBaV6a4MH8soBvzg+95CYhCKPFedut2JY9bMfrDl9D23g==}
+ engines: {node: '>=14.0'}
+ dependencies:
+ '@fastify/busboy': 2.1.1
+ dev: true
+
+ resolution: {integrity: sha512-tVpsJW7DdjecAiFpbIB1e3qxIQsE6NoPc5/eTdrbbIC4h0LVsWhnoa3g+m2HclBIujHzsxZ4VJVA+GUuc2/LBw==}
+ engines: {node: '>=12'}
+ dev: true
diff --git a/openapi/src/api.d.ts b/openapi/src/api.d.ts
new file mode 100644
index 0000000000..29f02869f0
--- /dev/null
+++ b/openapi/src/api.d.ts
@@ -0,0 +1,1005 @@
+/**
+ * This file was auto-generated by openapi-typescript.
+ * Do not make direct changes to the file.
+ */
+
+export interface paths {
+ "/@file/{filename_and_length}": {
+ get: {
+ parameters: {
+ path: {
+ /** @description The filename and byte length of the virtual file */
+ filename_and_length: string;
+ };
+ };
+ responses: {
+ /** @description Get a virtual file */
+ 200: {
+ content: {
+ "application/octet-stream": string;
+ };
+ };
+ /** @description Invalid byte length in virtual file request */
+ 404: {
+ content: never;
+ };
+ };
+ };
+ };
+ "/api/ai/completion": {
+ post: {
+ /** @description The prompt to get AI completion for */
+ requestBody: {
+ content: {
+ "application/json": components["schemas"]["AiCompletionRequest"];
+ };
+ };
+ responses: {
+ /** @description Get AI completion for a prompt */
+ 200: {
+ content: {
+ "application/json": {
+ [key: string]: unknown;
+ };
+ };
+ };
+ };
+ };
+ };
+ "/api/datasources/preview_column": {
+ post: {
+ requestBody?: {
+ content: {
+ "application/json": components["schemas"]["PreviewDatasetColumnRequest"];
+ };
+ };
+ responses: {
+ /** @description Preview a column in a dataset */
+ 200: {
+ content: {
+ "application/json": components["schemas"]["SuccessResponse"];
+ };
+ };
+ };
+ };
+ };
+ "/api/documentation/snippets": {
+ get: {
+ responses: {
+ /** @description Load the snippets for the documentation page */
+ 200: {
+ content: {
+ "application/json": components["schemas"]["Snippets"];
+ };
+ };
+ };
+ };
+ };
+ "/api/export/html": {
+ post: {
+ requestBody?: {
+ content: {
+ "application/json": components["schemas"]["ExportAsHTMLRequest"];
+ };
+ };
+ responses: {
+ /** @description Export the notebook as HTML */
+ 200: {
+ content: {
+ "text/html": string;
+ };
+ };
+ /** @description File must be saved before downloading */
+ 400: {
+ content: never;
+ };
+ };
+ };
+ };
+ "/api/export/markdown": {
+ post: {
+ requestBody?: {
+ content: {
+ "application/json": components["schemas"]["ExportAsMarkdownRequest"];
+ };
+ };
+ responses: {
+ /** @description Export the notebook as a markdown */
+ 200: {
+ content: {
+ "text/plain": string;
+ };
+ };
+ /** @description File must be saved before downloading */
+ 400: {
+ content: never;
+ };
+ };
+ };
+ };
+ "/api/export/script": {
+ post: {
+ requestBody?: {
+ content: {
+ "application/json": components["schemas"]["ExportAsScriptRequest"];
+ };
+ };
+ responses: {
+ /** @description Export the notebook as a script */
+ 200: {
+ content: {
+ "text/plain": string;
+ };
+ };
+ /** @description File must be saved before downloading */
+ 400: {
+ content: never;
+ };
+ };
+ };
+ };
+ "/api/files/create": {
+ post: {
+ requestBody?: {
+ content: {
+ "application/json": components["schemas"]["FileCreateRequest"];
+ };
+ };
+ responses: {
+ /** @description Create a new file or directory */
+ 200: {
+ content: {
+ "application/json": components["schemas"]["FileCreateResponse"];
+ };
+ };
+ };
+ };
+ };
+ "/api/files/delete": {
+ post: {
+ requestBody?: {
+ content: {
+ "application/json": components["schemas"]["FileDeleteRequest"];
+ };
+ };
+ responses: {
+ /** @description Delete a file or directory */
+ 200: {
+ content: {
+ "application/json": components["schemas"]["FileDeleteResponse"];
+ };
+ };
+ };
+ };
+ };
+ "/api/files/file_details": {
+ post: {
+ requestBody?: {
+ content: {
+ "application/json": components["schemas"]["FileDetailsRequest"];
+ };
+ };
+ responses: {
+ /** @description Get details of a specific file or directory */
+ 200: {
+ content: {
+ "application/json": components["schemas"]["FileDetailsResponse"];
+ };
+ };
+ };
+ };
+ };
+ "/api/files/list_files": {
+ post: {
+ requestBody?: {
+ content: {
+ "application/json": components["schemas"]["FileListRequest"];
+ };
+ };
+ responses: {
+ /** @description List files and directories in a given path */
+ 200: {
+ content: {
+ "application/json": components["schemas"]["FileListResponse"];
+ };
+ };
+ };
+ };
+ };
+ "/api/files/move": {
+ post: {
+ requestBody?: {
+ content: {
+ "application/json": components["schemas"]["FileMoveRequest"];
+ };
+ };
+ responses: {
+ /** @description Move a file or directory */
+ 200: {
+ content: {
+ "application/json": components["schemas"]["FileMoveResponse"];
+ };
+ };
+ };
+ };
+ };
+ "/api/files/update": {
+ post: {
+ requestBody?: {
+ content: {
+ "application/json": components["schemas"]["FileUpdateRequest"];
+ };
+ };
+ responses: {
+ /** @description Update a file or directory */
+ 200: {
+ content: {
+ "application/json": components["schemas"]["FileUpdateResponse"];
+ };
+ };
+ };
+ };
+ };
+ "/api/home/recent_files": {
+ post: {
+ responses: {
+ /** @description Get the recent files */
+ 200: {
+ content: {
+ "application/json": components["schemas"]["RecentFilesResponse"];
+ };
+ };
+ };
+ };
+ };
+ "/api/home/running_notebooks": {
+ post: {
+ responses: {
+ /** @description Get the running files */
+ 200: {
+ content: {
+ "application/json": components["schemas"]["WorkspaceFilesResponse"];
+ };
+ };
+ };
+ };
+ };
+ "/api/home/shutdown_session": {
+ post: {
+ requestBody?: {
+ content: {
+ "application/json": components["schemas"]["ShutdownSessionRequest"];
+ };
+ };
+ responses: {
+ /** @description Shutdown the current session */
+ 200: {
+ content: {
+ "application/json": components["schemas"]["WorkspaceFilesResponse"];
+ };
+ };
+ };
+ };
+ };
+ "/api/home/workspace_files": {
+ post: {
+ requestBody?: {
+ content: {
+ "application/json": components["schemas"]["WorkspaceFilesRequest"];
+ };
+ };
+ responses: {
+ /** @description Get the files in the workspace */
+ 200: {
+ content: {
+ "application/json": components["schemas"]["WorkspaceFilesResponse"];
+ };
+ };
+ };
+ };
+ };
+ "/api/kernel/code_autocomplete": {
+ post: {
+ requestBody?: {
+ content: {
+ "application/json": components["schemas"]["CompletionRequest"];
+ };
+ };
+ responses: {
+ /** @description Complete a code fragment */
+ 200: {
+ content: {
+ "application/json": components["schemas"]["SuccessResponse"];
+ };
+ };
+ };
+ };
+ };
+ "/api/kernel/delete": {
+ post: {
+ requestBody?: {
+ content: {
+ "application/json": components["schemas"]["DeleteRequest"];
+ };
+ };
+ responses: {
+ /** @description Delete a cell */
+ 200: {
+ content: {
+ "application/json": components["schemas"]["SuccessResponse"];
+ };
+ };
+ };
+ };
+ };
+ "/api/kernel/format": {
+ post: {
+ requestBody?: {
+ content: {
+ "application/json": components["schemas"]["FormatRequest"];
+ };
+ };
+ responses: {
+ /** @description Format code */
+ 200: {
+ content: {
+ "application/json": components["schemas"]["FormatResponse"];
+ };
+ };
+ };
+ };
+ };
+ "/api/kernel/function_call": {
+ post: {
+ requestBody?: {
+ content: {
+ "application/json": components["schemas"]["FunctionCallRequest"];
+ };
+ };
+ responses: {
+ /** @description Invoke an RPC */
+ 200: {
+ content: {
+ "application/json": components["schemas"]["SuccessResponse"];
+ };
+ };
+ };
+ };
+ };
+ "/api/kernel/install_missing_packages": {
+ post: {
+ requestBody?: {
+ content: {
+ "application/json": components["schemas"]["InstallMissingPackagesRequest"];
+ };
+ };
+ responses: {
+ /** @description Install missing packages */
+ 200: {
+ content: {
+ "application/json": components["schemas"]["SuccessResponse"];
+ };
+ };
+ };
+ };
+ };
+ "/api/kernel/instantiate": {
+ post: {
+ requestBody?: {
+ content: {
+ "application/json": components["schemas"]["InstantiateRequest"];
+ };
+ };
+ responses: {
+ /** @description Instantiate a component */
+ 200: {
+ content: {
+ "application/json": components["schemas"]["SuccessResponse"];
+ };
+ };
+ };
+ };
+ };
+ "/api/kernel/interrupt": {
+ post: {
+ responses: {
+ /** @description Interrupt the kernel's execution */
+ 200: {
+ content: {
+ "application/json": components["schemas"]["SuccessResponse"];
+ };
+ };
+ };
+ };
+ };
+ "/api/kernel/open": {
+ post: {
+ requestBody?: {
+ content: {
+ "application/json": components["schemas"]["OpenFileRequest"];
+ };
+ };
+ responses: {
+ /** @description Open a file */
+ 200: {
+ content: {
+ "application/json": components["schemas"]["SuccessResponse"];
+ };
+ };
+ /** @description File does not exist */
+ 400: {
+ content: never;
+ };
+ };
+ };
+ };
+ "/api/kernel/read_code": {
+ post: {
+ responses: {
+ /** @description Read the code from the server */
+ 200: {
+ content: {
+ "application/json": components["schemas"]["ReadCodeResponse"];
+ };
+ };
+ /** @description File must be saved before downloading */
+ 400: {
+ content: never;
+ };
+ };
+ };
+ };
+ "/api/kernel/rename": {
+ post: {
+ requestBody?: {
+ content: {
+ "application/json": components["schemas"]["RenameFileRequest"];
+ };
+ };
+ responses: {
+ /** @description Rename the current app */
+ 200: {
+ content: {
+ "application/json": components["schemas"]["SuccessResponse"];
+ };
+ };
+ };
+ };
+ };
+ "/api/kernel/restart_session": {
+ post: {
+ responses: {
+ /** @description Restart the current session without affecting other sessions. */
+ 200: {
+ content: {
+ "application/json": components["schemas"]["SuccessResponse"];
+ };
+ };
+ };
+ };
+ };
+ "/api/kernel/run": {
+ post: {
+ requestBody?: {
+ content: {
+ "application/json": components["schemas"]["RunRequest"];
+ };
+ };
+ responses: {
+ /** @description Run a cell. Updates cell code in the kernel if needed; registers new cells for unseen cell IDs. Only allowed in edit mode. */
+ 200: {
+ content: {
+ "application/json": components["schemas"]["SuccessResponse"];
+ };
+ };
+ };
+ };
+ };
+ "/api/kernel/save": {
+ post: {
+ requestBody?: {
+ content: {
+ "application/json": components["schemas"]["SaveRequest"];
+ };
+ };
+ responses: {
+ /** @description Save the current app */
+ 200: {
+ content: {
+ "application/json": components["schemas"]["SuccessResponse"];
+ };
+ };
+ };
+ };
+ };
+ "/api/kernel/save_app_config": {
+ post: {
+ requestBody?: {
+ content: {
+ "application/json": components["schemas"]["SaveAppConfigurationRequest"];
+ };
+ };
+ responses: {
+ /** @description Save the app configuration */
+ 200: {
+ content: {
+ "application/json": components["schemas"]["SuccessResponse"];
+ };
+ };
+ };
+ };
+ };
+ "/api/kernel/save_user_config": {
+ post: {
+ responses: {
+ /** @description Update the user config on disk and in the kernel. Only allowed in edit mode. */
+ 200: {
+ content: {
+ "application/json": components["schemas"]["SuccessResponse"];
+ };
+ };
+ };
+ };
+ };
+ "/api/kernel/set_cell_config": {
+ post: {
+ requestBody?: {
+ content: {
+ "application/json": components["schemas"]["SetCellConfigRequest"];
+ };
+ };
+ responses: {
+ /** @description Set the configuration of a cell */
+ 200: {
+ content: {
+ "application/json": components["schemas"]["SuccessResponse"];
+ };
+ };
+ };
+ };
+ };
+ "/api/kernel/set_ui_element_value": {
+ post: {
+ requestBody?: {
+ content: {
+ "application/json": components["schemas"]["UpdateComponentValuesRequest"];
+ };
+ };
+ responses: {
+ /** @description Set UI element values */
+ 200: {
+ content: {
+ "application/json": components["schemas"]["SuccessResponse"];
+ };
+ };
+ };
+ };
+ };
+ "/api/kernel/shutdown": {
+ post: {
+ responses: {
+ /** @description Shutdown the kernel */
+ 200: {
+ content: {
+ "application/json": components["schemas"]["SuccessResponse"];
+ };
+ };
+ };
+ };
+ };
+ "/api/kernel/stdin": {
+ post: {
+ requestBody?: {
+ content: {
+ "application/json": components["schemas"]["StdinRequest"];
+ };
+ };
+ responses: {
+ /** @description Send input to the stdin stream */
+ 200: {
+ content: {
+ "application/json": components["schemas"]["SuccessResponse"];
+ };
+ };
+ };
+ };
+ };
+ "/api/status": {
+ get: {
+ responses: {
+ /** @description Get the status of the application */
+ 200: {
+ content: {
+ "application/json": {
+ filenames?: string[];
+ lsp_running?: boolean;
+ mode?: string;
+ node_version?: string;
+ requirements?: string[];
+ sessions?: number;
+ status?: string;
+ version?: string;
+ };
+ };
+ };
+ };
+ };
+ };
+ "/api/usage": {
+ get: {
+ responses: {
+ /** @description Get the current memory and CPU usage of the application */
+ 200: {
+ content: {
+ "application/json": {
+ cpu?: {
+ percent?: number;
+ };
+ memory?: {
+ available?: number;
+ free?: number;
+ percent?: number;
+ total?: number;
+ used?: number;
+ };
+ };
+ };
+ };
+ };
+ };
+ };
+ "/api/version": {
+ get: {
+ responses: {
+ /** @description Get the version of the application */
+ 200: {
+ content: {
+ "text/plain": string;
+ };
+ };
+ };
+ };
+ };
+ "/auth/login": {
+ /** Submit login form */
+ post: {
+ requestBody?: {
+ content: {
+ "application/x-www-form-urlencoded": {
+ /** @description Access token or password */
+ password?: string;
+ };
+ };
+ };
+ responses: {
+ /** @description Login page */
+ 200: {
+ content: {
+ "text/html": string;
+ };
+ };
+ /** @description Redirect to the next URL */
+ 302: {
+ headers: {
+ Location?: string;
+ };
+ content: never;
+ };
+ };
+ };
+ };
+}
+
+export type webhooks = Record<string, never>;
+
+export interface components {
+ schemas: {
+ AiCompletionRequest: {
+ code: string;
+ include_other_code: string;
+ prompt: string;
+ };
+ AppMetadata: {
+ cli_args: {
+ [key: string]:
+ | string
+ | boolean
+ | number
+ | (string | boolean | number)[];
+ };
+ filename?: string | null;
+ query_params: {
+ [key: string]: string | string[];
+ };
+ };
+ BaseResponse: {
+ success: boolean;
+ };
+ CellConfig: {
+ disabled?: boolean;
+ hide_code?: boolean;
+ };
+ CompletionRequest: {
+ cell_id: string;
+ document: string;
+ id: string;
+ };
+ CreationRequest: {
+ execution_requests: components["schemas"]["ExecutionRequest"][];
+ set_ui_element_value_request: {
+ ids_and_values: [string, unknown][];
+ token?: string;
+ };
+ };
+ DeleteRequest: {
+ cell_id: string;
+ };
+ ExecuteMultipleRequest: {
+ execution_requests: components["schemas"]["ExecutionRequest"][];
+ };
+ ExecuteStaleRequest: Record<string, never>;
+ ExecutionRequest: {
+ cell_id: string;
+ code: string;
+ };
+ ExportAsHTMLRequest: {
+ asset_url?: string | null;
+ download: boolean;
+ files: string[];
+ include_code: boolean;
+ };
+ ExportAsMarkdownRequest: {
+ download: boolean;
+ };
+ ExportAsScriptRequest: {
+ download: boolean;
+ };
+ FileCreateRequest: {
+ contents?: string | null;
+ name: string;
+ path: string;
+ type: string;
+ };
+ FileCreateResponse: {
+ info?: components["schemas"]["FileInfo"];
+ message?: string | null;
+ success: boolean;
+ };
+ FileDeleteRequest: {
+ path: string;
+ };
+ FileDeleteResponse: {
+ message?: string | null;
+ success: boolean;
+ };
+ FileDetailsRequest: {
+ path: string;
+ };
+ FileDetailsResponse: {
+ contents?: string | null;
+ file: components["schemas"]["FileInfo"];
+ mime_type?: string | null;
+ };
+ FileInfo: {
+ children?: components["schemas"]["FileInfo"][];
+ id: string;
+ is_directory: boolean;
+ is_marimo_file: boolean;
+ last_modified_date?: number | null;
+ name: string;
+ path: string;
+ };
+ FileListRequest: {
+ path?: string | null;
+ };
+ FileListResponse: {
+ files: components["schemas"]["FileInfo"][];
+ root: string;
+ };
+ FileMoveRequest: {
+ new_path: string;
+ path: string;
+ };
+ FileMoveResponse: {
+ info?: components["schemas"]["FileInfo"];
+ message?: string | null;
+ success: boolean;
+ };
+ FileUpdateRequest: {
+ contents: string;
+ path: string;
+ };
+ FileUpdateResponse: {
+ info?: components["schemas"]["FileInfo"];
+ message?: string | null;
+ success: boolean;
+ };
+ FormatRequest: {
+ codes: {
+ [key: string]: string;
+ };
+ line_length: number;
+ };
+ FormatResponse: {
+ codes: {
+ [key: string]: string;
+ };
+ };
+ FunctionCallRequest: {
+ args: {
+ [key: string]: unknown;
+ };
+ function_call_id: string;
+ function_name: string;
+ namespace: string;
+ };
+ InstallMissingPackagesRequest: {
+ manager: string;
+ };
+ InstantiateRequest: {
+ object_ids: string[];
+ values: (string | boolean | number | null)[];
+ };
+ MarimoConfig: {
+ ai: {
+ open_ai: {
+ api_key: string;
+ base_url: string;
+ model: string;
+ };
+ };
+ completion: {
+ activate_on_typing: boolean;
+ copilot: boolean;
+ };
+ display: {
+ /** @enum {unknown} */
+ cell_output: "above" | "below";
+ code_editor_font_size: number;
+ /** @enum {unknown} */
+ default_width: "normal" | "compact" | "medium" | "full";
+ /** @enum {unknown} */
+ theme: "light" | "dark" | "system";
+ };
+ experimental: {
+ [key: string]: unknown;
+ };
+ formatting: {
+ line_length: number;
+ };
+ keymap: {
+ overrides: {
+ [key: string]: string;
+ };
+ /** @enum {unknown} */
+ preset: "default" | "vim";
+ };
+ package_management: {
+ /** @enum {unknown} */
+ manager: "pip" | "rye" | "uv" | "poetry" | "pixi";
+ };
+ runtime: {
+ auto_instantiate: boolean;
+ /** @enum {unknown} */
+ auto_reload: "off" | "lazy" | "autorun";
+ /** @enum {unknown} */
+ on_cell_change: "lazy" | "autorun";
+ };
+ save: {
+ /** @enum {unknown} */
+ autosave: "off" | "after_delay";
+ autosave_delay: number;
+ format_on_save: boolean;
+ };
+ server: {
+ browser: "default" | string;
+ follow_symlink: boolean;
+ };
+ };
+ MarimoFile: {
+ initialization_id?: string | null;
+ last_modified: number;
+ name: string;
+ path: string;
+ session_id?: string | null;
+ };
+ OpenFileRequest: {
+ path: string;
+ };
+ PreviewDatasetColumnRequest: {
+ column_name: string;
+ source: string;
+ table_name: string;
+ };
+ ReadCodeResponse: {
+ contents: string;
+ };
+ RecentFilesResponse: {
+ files: components["schemas"]["MarimoFile"][];
+ };
+ RenameFileRequest: {
+ filename: string;
+ };
+ RunRequest: {
+ cell_ids: string[];
+ codes: string[];
+ };
+ SaveAppConfigurationRequest: {
+ config: {
+ [key: string]: unknown;
+ };
+ };
+ SaveRequest: {
+ cell_ids: string[];
+ codes: string[];
+ configs: components["schemas"]["CellConfig"][];
+ filename: string;
+ layout?: {
+ [key: string]: unknown;
+ } | null;
+ names: string[];
+ };
+ SaveUserConfigurationRequest: {
+ config: components["schemas"]["MarimoConfig"];
+ };
+ SetCellConfigRequest: {
+ configs: {
+ [key: string]: {
+ [key: string]: {
+ [key: string]: unknown;
+ };
+ };
+ };
+ };
+ SetUIElementValueRequest: {
+ ids_and_values: [string, unknown][];
+ token?: string;
+ };
+ SetUserConfigRequest: {
+ config: components["schemas"]["MarimoConfig"];
+ };
+ ShutdownSessionRequest: {
+ session_id: string;
+ };
+ Snippet: {
+ sections: components["schemas"]["SnippetSection"][];
+ title: string;
+ };
+ SnippetSection: {
+ code?: string | null;
+ html?: string | null;
+ id: string;
+ };
+ Snippets: {
+ snippets: components["schemas"]["Snippet"][];
+ };
+ StdinRequest: {
+ text: string;
+ };
+ StopRequest: Record<string, never>;
+ SuccessResponse: {
+ success?: boolean;
+ };
+ UpdateComponentValuesRequest: {
+ object_ids: string[];
+ values: (string | boolean | number | null)[];
+ };
+ WorkspaceFilesRequest: {
+ include_markdown?: boolean;
+ };
+ WorkspaceFilesResponse: {
+ files: components["schemas"]["MarimoFile"][];
+ };
+ };
+ responses: never;
+ parameters: never;
+ requestBodies: never;
+ headers: never;
+ pathItems: never;
+}
+
+export type $defs = Record<string, never>;
+
+export type external = Record<string, never>;
+
+export type operations = Record<string, never>;
diff --git a/openapi/src/index.ts b/openapi/src/index.ts
new file mode 100644
index 0000000000..da7d34580f
--- /dev/null
+++ b/openapi/src/index.ts
@@ -0,0 +1,8 @@
+export * from "./api.d";
+
+import createClient, { ClientOptions } from "openapi-fetch";
+import type { paths } from "./api.d";
+
+export function createMarimoClient(opts: ClientOptions) {
+ return createClient<paths>(opts);
+}
diff --git a/openapi/tsconfig.json b/openapi/tsconfig.json
new file mode 100644
index 0000000000..f33562f97a
--- /dev/null
+++ b/openapi/tsconfig.json
@@ -0,0 +1,7 @@
+{
+ "compilerOptions": {
+ "module": "ESNext",
+ "moduleResolution": "Bundler",
+ "noUncheckedIndexedAccess": true
+ }
+}
diff --git a/tests/_cli/test_cli_development.py b/tests/_cli/test_cli_development.py
new file mode 100644
index 0000000000..979f1f07d0
--- /dev/null
+++ b/tests/_cli/test_cli_development.py
@@ -0,0 +1,14 @@
+# Copyright 2024 Marimo. All rights reserved.
+from __future__ import annotations
+
+import subprocess
+
+
+def test_cli_development_openapi() -> None:
+ p = subprocess.run(
+ ["marimo", "development", "openapi"],
+ capture_output=True,
+ )
+ assert p.returncode == 0
+ # Check a random endpoint
+ assert "/api/export/html" in p.stdout.decode()
diff --git a/tests/_utils/test_dataclass_to_openapi.py b/tests/_utils/test_dataclass_to_openapi.py
new file mode 100644
index 0000000000..fba617474e
--- /dev/null
+++ b/tests/_utils/test_dataclass_to_openapi.py
@@ -0,0 +1,67 @@
+from __future__ import annotations
+
+import dataclasses
+from typing import Any, List, Literal, Optional
+
+from marimo._utils.dataclass_to_openapi import dataclass_to_openapi_spec
+
+
+class Address:
+ street: str
+ city: str
+ zip_code: Optional[int]
+ kind: Literal["home", "work"]
+
+
+class Person:
+ name: str
+ age: int
+ address: Address
+ tags: List[str]
+ metadata: Any
+
+
+def test_dataclass_to_openapi() -> None:
+ openapi_spec = dataclass_to_openapi_spec(Person)
+ assert openapi_spec == {
+ "type": "object",
+ "properties": {
+ "name": {"type": "string"},
+ "age": {"type": "integer"},
+ "address": {
+ "type": "object",
+ "properties": {
+ "street": {"type": "string"},
+ "city": {"type": "string"},
+ "zip_code": {"type": "integer", "nullable": True},
+ "kind": {"enum": ["home", "work"]},
+ },
+ "required": ["street", "city", "kind"],
+ },
+ "tags": {"type": "array", "items": {"type": "string"}},
+ "metadata": {},
+ },
+ "required": ["name", "age", "address", "tags", "metadata"],
+ }
+
+
+class Node:
+ value: int
+ left: Optional[Node]
+ right: Optional[Node]
+
+
+def test_recursive_dataclass_to_openapi() -> None:
+ openapi_spec = dataclass_to_openapi_spec(Node)
+ assert openapi_spec == {
+ "type": "object",
+ "properties": {
+ "value": {"type": "integer"},
+ "left": {"$ref": "#/components/schemas/Node", "nullable": True},
+ "right": {"$ref": "#/components/schemas/Node", "nullable": True},
+ },
+ "required": ["value"],
+ }