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.

Migrate custom serde to `msgspec` (#6234)

Trevor Manze3355a5799c0
diff --git a/frontend/src/__mocks__/notebook.ts b/frontend/src/__mocks__/notebook.ts
index 536c0241ef..f96ea947bb 100644
--- a/frontend/src/__mocks__/notebook.ts
+++ b/frontend/src/__mocks__/notebook.ts
@@ -104,12 +104,14 @@ export const MockNotebook = {
type: "exception",
msg,
exception_type,
+ raising_cell: null,
}),
strictException: (msg: string, ref: string): MarimoError => ({
type: "strict-exception",
msg,
ref,
+ blamed_cell: null,
}),
interruption: (): MarimoError => ({
@@ -124,6 +126,7 @@ export const MockNotebook = {
unknown: (msg: string): MarimoError => ({
type: "unknown",
msg,
+ error_type: null,
}),
},
diff --git a/frontend/src/components/datasources/__tests__/utils.test.ts b/frontend/src/components/datasources/__tests__/utils.test.ts
index 8f67d5fcd5..151be1b188 100644
--- a/frontend/src/components/datasources/__tests__/utils.test.ts
+++ b/frontend/src/components/datasources/__tests__/utils.test.ts
@@ -13,6 +13,12 @@ describe("sqlCode", () => {
source: "local",
source_type: "local",
type: "table",
+ engine: null,
+ indexes: null,
+ num_columns: null,
+ num_rows: null,
+ variable_name: null,
+ primary_keys: null,
};
const mockColumn = {
name: "email" as const,
diff --git a/frontend/src/components/datasources/column-preview.tsx b/frontend/src/components/datasources/column-preview.tsx
index bfc91af847..4ef6837076 100644
--- a/frontend/src/components/datasources/column-preview.tsx
+++ b/frontend/src/components/datasources/column-preview.tsx
@@ -173,9 +173,7 @@ export function renderPreviewError({
}
export function renderStats(
- stats: Partial<
- Record<ColumnHeaderStatsKey, string | number | boolean | null | undefined>
- >,
+ stats: Partial<Record<ColumnHeaderStatsKey, unknown>>,
dataType: DataType,
) {
return (
diff --git a/frontend/src/components/editor/chrome/panels/packages-panel.tsx b/frontend/src/components/editor/chrome/panels/packages-panel.tsx
index ca2d980881..9d82f5fc2b 100644
--- a/frontend/src/components/editor/chrome/panels/packages-panel.tsx
+++ b/frontend/src/components/editor/chrome/panels/packages-panel.tsx
@@ -413,7 +413,7 @@ const RemoveButton: React.FC<{
};
const DependencyTree: React.FC<{
- tree?: DependencyTreeNode;
+ tree: DependencyTreeNode | null;
error?: Error | null;
onSuccess: () => void;
}> = ({ tree, error, onSuccess }) => {
diff --git a/frontend/src/core/cells/cell.ts b/frontend/src/core/cells/cell.ts
index 78c0a1de8a..a8e70b7242 100644
--- a/frontend/src/core/cells/cell.ts
+++ b/frontend/src/core/cells/cell.ts
@@ -47,7 +47,7 @@ export function transitionCell(
case "idle":
if (cell.runStartTimestamp) {
nextCell.runElapsedTimeMs = Time.fromSeconds(
- (message.timestamp - cell.runStartTimestamp) as Seconds,
+ ((message.timestamp ?? 0) - cell.runStartTimestamp) as Seconds,
).toMilliseconds();
nextCell.runStartTimestamp = null;
nextCell.staleInputs = false;
@@ -210,7 +210,7 @@ export function outputIsStale(
status === "running" &&
output !== null &&
runStartTimestamp !== null &&
- output.timestamp > runStartTimestamp;
+ (output.timestamp ?? 0) > runStartTimestamp;
// If loading and output has not been received while running
if (loading && !outputReceivedWhileRunning) {
diff --git a/frontend/src/core/cells/cells.ts b/frontend/src/core/cells/cells.ts
index b2ee818253..904acc93a4 100644
--- a/frontend/src/core/cells/cells.ts
+++ b/frontend/src/core/cells/cells.ts
@@ -1372,7 +1372,7 @@ const {
function isCellCodeHidden(state: NotebookState, cellId: CellId): boolean {
return (
- state.cellData[cellId].config.hide_code &&
+ Boolean(state.cellData[cellId].config.hide_code) &&
!state.untouchedNewCells.has(cellId)
);
}
diff --git a/frontend/src/core/cells/logs.ts b/frontend/src/core/cells/logs.ts
index 7d326b2063..41c2fcb422 100644
--- a/frontend/src/core/cells/logs.ts
+++ b/frontend/src/core/cells/logs.ts
@@ -56,7 +56,7 @@ export function getCellLogsForMessage(cell: CellMessage): CellLog[] {
CellLogLogger.log({
level: "stderr",
cellId: cell.cell_id as CellId,
- timestamp: cell.timestamp,
+ timestamp: cell.timestamp ?? 0,
message: JSON.stringify(error),
});
});
diff --git a/frontend/src/core/cells/runs.ts b/frontend/src/core/cells/runs.ts
index f5b85a1d99..12d428a4f3 100644
--- a/frontend/src/core/cells/runs.ts
+++ b/frontend/src/core/cells/runs.ts
@@ -45,6 +45,7 @@ const {
opts: { cellOperation: CellMessage; code: string },
): RunsState => {
const { cellOperation, code } = opts;
+ const timestamp = cellOperation.timestamp ?? 0;
const runId = cellOperation.run_id as RunId | undefined;
if (!runId) {
return state;
@@ -84,11 +85,11 @@ const {
code: code.slice(0, MAX_CODE_LENGTH),
elapsedTime: 0,
status: status,
- startTime: cellOperation.timestamp,
+ startTime: timestamp,
},
],
]),
- runStartTime: cellOperation.timestamp,
+ runStartTime: timestamp,
};
// Manage run history size
@@ -129,12 +130,12 @@ const {
const startTime =
cellOperation.status === "running"
- ? cellOperation.timestamp
+ ? timestamp
: existingCellRun.startTime;
const elapsedTime =
status === "success" || status === "error"
- ? cellOperation.timestamp - existingCellRun.startTime
+ ? timestamp - existingCellRun.startTime
: undefined;
nextCellRuns.set(cellOperation.cell_id as CellId, {
@@ -149,7 +150,7 @@ const {
code: code.slice(0, MAX_CODE_LENGTH),
elapsedTime: 0,
status: status,
- startTime: cellOperation.timestamp,
+ startTime: timestamp,
});
}
diff --git a/frontend/src/core/codemirror/language/__tests__/sql.test.ts b/frontend/src/core/codemirror/language/__tests__/sql.test.ts
index e850b711e5..8da977601a 100644
--- a/frontend/src/core/codemirror/language/__tests__/sql.test.ts
+++ b/frontend/src/core/codemirror/language/__tests__/sql.test.ts
@@ -664,6 +664,9 @@ describe("tablesCompletionSource", () => {
source: "duckdb",
source_type: "local",
type: "table",
+ num_columns: 0,
+ num_rows: 0,
+ variable_name: null,
columns: [
{
name: "id",
@@ -690,6 +693,9 @@ describe("tablesCompletionSource", () => {
source: "duckdb",
source_type: "local",
type: "table",
+ num_columns: 0,
+ num_rows: 0,
+ variable_name: null,
columns: [
{
name: "order_id",
@@ -763,6 +769,9 @@ describe("tablesCompletionSource", () => {
source: "postgres",
source_type: "local",
type: "table",
+ num_columns: 0,
+ num_rows: 0,
+ variable_name: null,
columns: [
{
name: "col1",
@@ -788,6 +797,9 @@ describe("tablesCompletionSource", () => {
source: "postgres",
source_type: "local",
type: "table",
+ num_columns: 0,
+ num_rows: 0,
+ variable_name: null,
columns: [
{
name: "col2",
@@ -856,6 +868,9 @@ describe("tablesCompletionSource", () => {
source: "postgres",
source_type: "local",
type: "table",
+ num_columns: 0,
+ num_rows: 0,
+ variable_name: null,
columns: [
{
name: "col1",
@@ -875,6 +890,9 @@ describe("tablesCompletionSource", () => {
source: "postgres",
source_type: "local",
type: "table",
+ num_columns: 0,
+ num_rows: 0,
+ variable_name: null,
columns: [
{
name: "col2",
@@ -900,6 +918,9 @@ describe("tablesCompletionSource", () => {
source: "postgres",
source_type: "local",
type: "table",
+ num_columns: 0,
+ num_rows: 0,
+ variable_name: null,
columns: [
{
name: "col2",
@@ -925,6 +946,9 @@ describe("tablesCompletionSource", () => {
source: "postgres",
source_type: "local",
type: "table",
+ num_columns: 0,
+ num_rows: 0,
+ variable_name: null,
columns: [
{
name: "col2",
@@ -1002,6 +1026,9 @@ describe("tablesCompletionSource", () => {
source: "postgres",
source_type: "local",
type: "table",
+ num_columns: 0,
+ num_rows: 0,
+ variable_name: null,
columns: [
{
name: "id",
@@ -1070,6 +1097,9 @@ describe("tablesCompletionSource", () => {
source: "postgres",
source_type: "local",
type: "table",
+ num_columns: 0,
+ num_rows: 0,
+ variable_name: null,
columns: [],
},
],
@@ -1109,6 +1139,9 @@ describe("tablesCompletionSource", () => {
source: "postgres",
source_type: "local",
type: "table",
+ num_columns: 0,
+ num_rows: 0,
+ variable_name: null,
columns: [
{
name: "id",
@@ -1134,6 +1167,9 @@ describe("tablesCompletionSource", () => {
source: "postgres",
source_type: "local",
type: "table",
+ num_columns: 0,
+ num_rows: 0,
+ variable_name: null,
columns: [
{
name: "order_id",
@@ -1279,6 +1315,9 @@ describe("tablesCompletionSource", () => {
source: "postgres",
source_type: "local",
type: "table",
+ num_columns: 0,
+ num_rows: 0,
+ variable_name: null,
columns: [
{
name: "id",
@@ -1469,6 +1508,9 @@ describe("tablesCompletionSource", () => {
source: "duckdb",
source_type: "local",
type: "table",
+ num_columns: 0,
+ num_rows: 0,
+ variable_name: null,
columns: [
{
name: "col1",
@@ -1613,6 +1655,9 @@ const mockConnection: DataSourceConnection = {
source: "duckdb",
source_type: "local",
type: "table",
+ num_columns: 0,
+ num_rows: 0,
+ variable_name: null,
columns: [
{
name: "col1",
diff --git a/frontend/src/core/codemirror/markdown/__tests__/commands.test.ts b/frontend/src/core/codemirror/markdown/__tests__/commands.test.ts
index b2e654c065..eae95c3715 100644
--- a/frontend/src/core/codemirror/markdown/__tests__/commands.test.ts
+++ b/frontend/src/core/codemirror/markdown/__tests__/commands.test.ts
@@ -267,6 +267,7 @@ describe("insertImage", () => {
mockRequestClient.sendCreateFileOrFolder.mockResolvedValueOnce({
success: true,
+ message: null,
info: {
path: "nested/public/hello.png",
name: "hello.png",
diff --git a/frontend/src/core/config/capabilities.ts b/frontend/src/core/config/capabilities.ts
index c046149eb3..6220107945 100644
--- a/frontend/src/core/config/capabilities.ts
+++ b/frontend/src/core/config/capabilities.ts
@@ -11,5 +11,5 @@ export const capabilitiesAtom = atom<Capabilities>({
});
export function hasCapability(key: keyof Capabilities): boolean {
- return store.get(capabilitiesAtom)[key];
+ return store.get(capabilitiesAtom)[key] ?? false;
}
diff --git a/frontend/src/core/datasets/__tests__/data-source.test.ts b/frontend/src/core/datasets/__tests__/data-source.test.ts
index ae37beb119..9c2cfec2ef 100644
--- a/frontend/src/core/datasets/__tests__/data-source.test.ts
+++ b/frontend/src/core/datasets/__tests__/data-source.test.ts
@@ -258,6 +258,9 @@ describe("add table list", () => {
{
name: "table1",
columns: [],
+ num_columns: 0,
+ num_rows: 0,
+ variable_name: null,
source: "",
source_type: "local",
type: "table",
@@ -286,6 +289,9 @@ describe("add table list", () => {
{
name: "table2",
columns: [],
+ num_columns: 0,
+ num_rows: 0,
+ variable_name: null,
source: "",
source_type: "local",
type: "table",
@@ -303,6 +309,9 @@ describe("add table list", () => {
{
name: "table1",
columns: [],
+ num_columns: 0,
+ num_rows: 0,
+ variable_name: null,
source: "",
source_type: "local",
type: "table",
@@ -323,6 +332,9 @@ describe("add table list", () => {
{
name: "table2",
columns: [],
+ num_columns: 0,
+ num_rows: 0,
+ variable_name: null,
source: "",
source_type: "local",
type: "table",
@@ -387,6 +399,9 @@ describe("add table", () => {
source: "",
source_type: "local",
type: "table",
+ num_columns: 0,
+ num_rows: 0,
+ variable_name: null,
};
const newState = addTable(table, {
engine: "conn1" as ConnectionName,
@@ -410,6 +425,9 @@ describe("add table", () => {
const table: DataTable = {
name: "table1",
columns: [],
+ num_columns: 0,
+ num_rows: 0,
+ variable_name: null,
source: "",
source_type: "local",
type: "table",
@@ -428,6 +446,9 @@ describe("add table", () => {
source: "new_source",
source_type: "local",
type: "table",
+ num_columns: 0,
+ num_rows: 0,
+ variable_name: null,
};
const updatedState = addTable(updatedTable, sqlTableContext);
@@ -444,6 +465,9 @@ describe("add table", () => {
const table: DataTable = {
name: "table2",
columns: [],
+ num_columns: 0,
+ num_rows: 0,
+ variable_name: null,
source: "",
source_type: "local",
type: "table",
diff --git a/frontend/src/core/errors/__tests__/errors.test.ts b/frontend/src/core/errors/__tests__/errors.test.ts
index 6bd9351dc7..3c1793e401 100644
--- a/frontend/src/core/errors/__tests__/errors.test.ts
+++ b/frontend/src/core/errors/__tests__/errors.test.ts
@@ -34,6 +34,7 @@ describe("getAutoFixes", () => {
type: "exception",
exception_type: "NameError",
msg: "name 'np' is not defined",
+ raising_cell: null,
};
const fixes = getAutoFixes(error);
@@ -46,6 +47,7 @@ describe("getAutoFixes", () => {
type: "exception",
exception_type: "NameError",
msg: "name 'unknown_module' is not defined",
+ raising_cell: null,
};
expect(getAutoFixes(error)).toHaveLength(0);
diff --git a/frontend/src/core/kernel/messages.ts b/frontend/src/core/kernel/messages.ts
index 622451e58d..b3dc9dbd31 100644
--- a/frontend/src/core/kernel/messages.ts
+++ b/frontend/src/core/kernel/messages.ts
@@ -2,7 +2,7 @@
import type { components } from "@marimo-team/marimo-api";
export type schemas = components["schemas"];
-export type DataType = schemas["DataType"];
+export type DataType = schemas["KnownUnions"]["data_type"];
export const DATA_TYPES = [
"string",
"boolean",
@@ -21,7 +21,11 @@ export type Database = schemas["Database"];
export type DatabaseSchema = schemas["Schema"];
export type DataSourceConnection = schemas["DataSourceConnection"];
export type OutputChannel = schemas["CellChannel"];
-export type MarimoError = schemas["Error"];
+export type CellOutput = schemas["CellOutput"];
+export type MarimoError = Extract<
+ CellOutput["data"],
+ Array<{ type: string }>
+>[number];
export type OutputMessage = schemas["CellOutput"];
export type CompletionOption = schemas["CompletionResult"]["options"][0];
export type CompletionResultMessage = OperationMessageData<"completion-result">;
@@ -35,20 +39,21 @@ export type SQLTablePreview = OperationMessageData<"sql-table-preview">;
export type SQLTableListPreview =
OperationMessageData<"sql-table-list-preview">;
export type SecretKeysResult = OperationMessageData<"secret-keys-result">;
+export type MessageOperation = schemas["KnownUnions"]["operation"];
-export type OperationMessageType = schemas["MessageOperation"]["name"];
+export type OperationMessageType = MessageOperation["op"];
export type OperationMessage = {
[Type in OperationMessageType]: {
op: Type;
- data: Omit<Extract<schemas["MessageOperation"], { name: Type }>, "name">;
+ data: Omit<Extract<MessageOperation, { op: Type }>, "op">;
};
}[OperationMessageType];
export type CellMessage = OperationMessageData<"cell-op">;
export type OperationMessageData<T extends OperationMessageType> = Omit<
- Extract<schemas["MessageOperation"], { name: T }>,
- "name"
+ Extract<MessageOperation, { op: T }>,
+ "op"
>;
export type Capabilities = OperationMessageData<"kernel-ready">["capabilities"];
diff --git a/frontend/src/core/layout/layout.ts b/frontend/src/core/layout/layout.ts
index d05f9615b5..6830024c7a 100644
--- a/frontend/src/core/layout/layout.ts
+++ b/frontend/src/core/layout/layout.ts
@@ -77,11 +77,11 @@ export function getSerializedLayout() {
// Vertical layout has no data, as it is the default.
if (selectedLayout === "vertical") {
- return undefined;
+ return null;
}
if (layoutData === undefined) {
- return undefined;
+ return null;
}
const data = layoutData[selectedLayout];
@@ -90,7 +90,7 @@ export function getSerializedLayout() {
);
if (plugin === undefined) {
Logger.error(`Unknown layout type: ${selectedLayout}`);
- return undefined;
+ return null;
}
return {
type: selectedLayout,
diff --git a/frontend/src/core/network/types.ts b/frontend/src/core/network/types.ts
index 5df43f941f..2172735d84 100644
--- a/frontend/src/core/network/types.ts
+++ b/frontend/src/core/network/types.ts
@@ -14,7 +14,7 @@ export type CellConfig = schemas["CellConfig"];
* idle: not running.
* disabled-transitively: disabled because an ancestor was disabled.
*/
-export type RuntimeState = schemas["RuntimeState"];
+export type RuntimeState = schemas["CellOp"]["status"];
export type CodeCompletionRequest = schemas["CodeCompletionRequest"];
export type DeleteCellRequest = schemas["DeleteCellRequest"];
export type ExecuteMultipleRequest = schemas["ExecuteMultipleRequest"];
diff --git a/frontend/src/core/wasm/bridge.ts b/frontend/src/core/wasm/bridge.ts
index 1a00fbbdb2..0be97b9b4a 100644
--- a/frontend/src/core/wasm/bridge.ts
+++ b/frontend/src/core/wasm/bridge.ts
@@ -514,9 +514,16 @@ export class PyodideBridge implements RunRequests, EditRequests {
return response;
};
- getDependencyTree = async () => {
+ getDependencyTree: EditRequests["getDependencyTree"] = async () => {
// WASM doesn't support dependency trees yet
- return { tree: undefined };
+ return {
+ tree: {
+ dependencies: [],
+ name: "",
+ tags: [],
+ version: null,
+ },
+ };
};
listSecretKeys: EditRequests["listSecretKeys"] = async (request) => {
diff --git a/frontend/src/core/wasm/worker/bootstrap.ts b/frontend/src/core/wasm/worker/bootstrap.ts
index d541d0a296..4e7ad82686 100644
--- a/frontend/src/core/wasm/worker/bootstrap.ts
+++ b/frontend/src/core/wasm/worker/bootstrap.ts
@@ -6,6 +6,7 @@ import type { JsonString } from "@/utils/json/base64";
import { invariant } from "../../../utils/invariant";
import { Logger } from "../../../utils/Logger";
import { WasmFileSystem } from "./fs";
+import { getMarimoWheel } from "./getMarimoWheel";
import { t } from "./tracer";
import type { SerializedBridge, WasmController } from "./types";
@@ -57,7 +58,8 @@ export class DefaultWasmController implements WasmController {
// Perf: These get loaded while pyodide is being bootstrapped
packages: [
"micropip",
- "marimo-base",
+ "msgspec",
+ getMarimoWheel(opts.version),
"Markdown",
"pymdown-extensions",
"narwhals",
diff --git a/frontend/src/core/wasm/worker/getMarimoWheel.ts b/frontend/src/core/wasm/worker/getMarimoWheel.ts
index 47a1ccfe86..104363ce5c 100644
--- a/frontend/src/core/wasm/worker/getMarimoWheel.ts
+++ b/frontend/src/core/wasm/worker/getMarimoWheel.ts
@@ -1,15 +1,10 @@
/* Copyright 2024 Marimo. All rights reserved. */
+
export function getMarimoWheel(version: string) {
- if (!version) {
- return "marimo-base>=0.9.0";
- }
- if (version === "local") {
+ if (import.meta.env.DEV && import.meta.env.VITE_MARIMO_VERSION) {
return `http://localhost:8000/dist/marimo-${
import.meta.env.VITE_MARIMO_VERSION
}-py3-none-any.whl`;
}
- if (version === "latest") {
- return "marimo-base";
- }
- return `marimo-base==${version}`;
+ return "marimo-base";
}
diff --git a/frontend/src/plugins/layout/MimeRenderPlugin.tsx b/frontend/src/plugins/layout/MimeRenderPlugin.tsx
index a6c605cdf8..b3704d179c 100644
--- a/frontend/src/plugins/layout/MimeRenderPlugin.tsx
+++ b/frontend/src/plugins/layout/MimeRenderPlugin.tsx
@@ -19,12 +19,9 @@ export class MimeRendererPlugin implements IStatelessPlugin<Data> {
validator = z.object({
mime: z.string().transform((val) => val as OutputMessage["mimetype"]),
- data: z.union([
- z.string(),
- z.null(),
- z.record(z.unknown()),
- z.array(z.any()),
- ]),
+ data: z
+ .union([z.string(), z.null(), z.record(z.unknown()), z.array(z.any())])
+ .transform((val) => val as OutputMessage["data"]),
});
render({ data }: IStatelessPluginProps<Data>): JSX.Element {
diff --git a/frontend/src/stories/cell.stories.tsx b/frontend/src/stories/cell.stories.tsx
index b1eeed2d59..a9f6bd28ce 100644
--- a/frontend/src/stories/cell.stories.tsx
+++ b/frontend/src/stories/cell.stories.tsx
@@ -223,6 +223,7 @@ export const Disabled: Story = {
config: {
disabled: true,
hide_code: false,
+ column: null,
},
output: {
channel: "output",
@@ -303,6 +304,7 @@ export const DisabledAndStaleStatus: Story = {
overrides={{
runElapsedTimeMs: 20 as Milliseconds,
config: {
+ column: null,
disabled: true,
hide_code: false,
},
diff --git a/frontend/src/utils/numbers.ts b/frontend/src/utils/numbers.ts
index 3a25a87528..3e57ea3881 100644
--- a/frontend/src/utils/numbers.ts
+++ b/frontend/src/utils/numbers.ts
@@ -1,8 +1,6 @@
/* Copyright 2024 Marimo. All rights reserved. */
-export function prettyNumber(
- value: number | string | undefined | null | boolean | unknown[],
-): string {
+export function prettyNumber(value: unknown): string {
if (value === undefined || value === null) {
return "";
}
@@ -19,10 +17,14 @@ export function prettyNumber(
return String(value);
}
- return value.toLocaleString(undefined, {
- minimumFractionDigits: 0,
- maximumFractionDigits: 2,
- });
+ if (typeof value === "number" || typeof value === "bigint") {
+ return value.toLocaleString(undefined, {
+ minimumFractionDigits: 0,
+ maximumFractionDigits: 2,
+ });
+ }
+
+ return String(value);
}
function scientificSpecialCase(value: number): string | null {
diff --git a/marimo/_ai/_types.py b/marimo/_ai/_types.py
index c2d03095e4..f0750e490c 100644
--- a/marimo/_ai/_types.py
+++ b/marimo/_ai/_types.py
@@ -4,7 +4,9 @@ from __future__ import annotations
import abc
import mimetypes
from dataclasses import dataclass
-from typing import Any, Literal, Optional, TypedDict, Union
+from typing import TYPE_CHECKING, Any, Literal, Optional, TypedDict, Union
+
+import msgspec
class ChatAttachmentDict(TypedDict):
@@ -127,11 +129,13 @@ class FilePart:
url: str
-ChatPart = Union[TextPart, ReasoningPart, ToolInvocationPart, FilePart]
+if TYPE_CHECKING:
+ ChatPart = Union[TextPart, ReasoningPart, ToolInvocationPart, FilePart]
+else:
+ ChatPart = dict[str, Any]
-@dataclass
-class ChatMessage:
+class ChatMessage(msgspec.Struct):
"""
A message in a chat.
"""
@@ -140,7 +144,7 @@ class ChatMessage:
role: Literal["user", "assistant", "system"]
# The content of the message.
- content: object
+ content: Any
# Optional attachments to the message.
attachments: Optional[list[ChatAttachment]] = None
diff --git a/marimo/_ast/cell.py b/marimo/_ast/cell.py
index d8430969a8..92c68bb32c 100644
--- a/marimo/_ast/cell.py
+++ b/marimo/_ast/cell.py
@@ -9,9 +9,12 @@ from collections.abc import Awaitable, Mapping
from functools import cached_property
from typing import TYPE_CHECKING, Any, Literal, Optional
+import msgspec
+
from marimo import _loggers
from marimo._ast.sql_visitor import SQLRef, SQLVisitor
from marimo._ast.visitor import ImportData, Language, Name, VariableData
+from marimo._messaging.msgspec_encoder import asdict
from marimo._runtime.exceptions import MarimoRuntimeException
from marimo._types.ids import CellId_t
from marimo._utils.deep_merge import deep_merge
@@ -27,8 +30,8 @@ if TYPE_CHECKING:
from marimo._output.hypertext import Html
-class CellConfig:
+# TODO: Use rename="camel" for consistency in JSON-encoding
+class CellConfig(msgspec.Struct):
"""
Internal representation of a cell's configuration.
This is not part of the public API.
@@ -55,7 +58,7 @@ class CellConfig:
return config
def asdict(self) -> dict[str, Any]:
- return dataclasses.asdict(self)
+ return asdict(self)
def asdict_without_defaults(self) -> dict[str, Any]:
return {
@@ -73,16 +76,14 @@ class CellConfig:
`update` can be a partial config or a CellConfig
"""
if isinstance(update, CellConfig):
- update = dataclasses.asdict(update)
- new_config = dataclasses.asdict(
- CellConfig.from_dict(deep_merge(dataclasses.asdict(self), update))
- )
- for key, value in new_config.items():
+ update = asdict(update)
+ new_config = CellConfig.from_dict(deep_merge(self.asdict(), update))
+ for key, value in new_config.asdict().items():
self.__setattr__(key, value)
CellConfigKeys = frozenset(
- {field.name for field in dataclasses.fields(CellConfig)}
+ {field.name for field in msgspec.structs.fields(CellConfig)}
)
diff --git a/marimo/_ast/codegen.py b/marimo/_ast/codegen.py
index f8f019dee8..c6bcd4d653 100644
--- a/marimo/_ast/codegen.py
+++ b/marimo/_ast/codegen.py
@@ -124,25 +124,17 @@ def to_decorator(
config: Optional[CellConfig],
fn: Decorators = "cell",
) -> str:
- if config is None:
+ if config is None or not config.is_different_from_default():
return f"@app.{fn}"
- # Removed defaults. If the cell's config is the default config,
- # don't include it in the decorator.
- if not config.disabled:
- del config.disabled
- if not config.hide_code:
- del config.hide_code
- if not isinstance(config.column, int):
- del config.column
-
- if config == CellConfig():
- return f"@app.{fn}"
- else:
- return format_tuple_elements(
- f"@app.{fn}(...)",
- tuple(f"{key}={value}" for key, value in config.__dict__.items()),
- )
+ # Only include non-defaults in the decorator call
+ return format_tuple_elements(
+ f"@app.{fn}(...)",
+ tuple(
+ f"{key}={value}"
+ for key, value in config.asdict_without_defaults().items()
+ ),
+ )
def build_setup_section(setup_cell: Optional[CellImpl]) -> str:
diff --git a/marimo/_cli/development/commands.py b/marimo/_cli/development/commands.py
index 7979fd5377..b1fe0b1dc9 100644
--- a/marimo/_cli/development/commands.py
+++ b/marimo/_cli/development/commands.py
@@ -9,8 +9,13 @@ from pathlib import Path
from typing import TYPE_CHECKING, Any
import click
+import msgspec
+import msgspec.json
from marimo._cli.print import orange
+from marimo._data.models import DataType
+from marimo._messaging.errors import Error as MarimoError
+from marimo._messaging.ops import MessageOperation
from marimo._server.session.serialize import (
serialize_notebook,
serialize_session_view,
@@ -38,6 +43,7 @@ def _generate_server_api_schema() -> dict[str, Any]:
import marimo._server.models.packages as packages
import marimo._server.models.secrets as secrets
import marimo._snippets.snippets as snippets
+ from marimo._ai._types import ChatMessage
from marimo._ast.cell import CellConfig, RuntimeStateType
from marimo._messaging.cell_output import CellChannel, CellOutput
from marimo._messaging.mimetypes import KnownMimeType
@@ -130,6 +136,8 @@ def _generate_server_api_schema() -> dict[str, Any]:
ops.UpdateCellIdsRequest,
ops.FocusCell,
ops.MessageOperation,
+ # ai
+ ChatMessage,
]
# dataclass components used in requests/responses
@@ -201,6 +209,7 @@ def _generate_server_api_schema() -> dict[str, Any]:
models.InvokeAiToolResponse,
requests.CodeCompletionRequest,
requests.DeleteCellRequest,
+ requests.HTTPRequest,
requests.ExecuteMultipleRequest,
requests.ExecuteScratchpadRequest,
requests.ExecuteStaleRequest,
@@ -215,6 +224,7 @@ def _generate_server_api_schema() -> dict[str, Any]:
requests.PreviewSQLTableRequest,
requests.RenameRequest,
requests.SetCellConfigRequest,
+ requests.ModelMessage,
requests.SetModelMessageRequest,
requests.SetUserConfigRequest,
requests.StopRequest,
@@ -250,17 +260,23 @@ def _generate_server_api_schema() -> dict[str, Any]:
ops.MessageOperation: "MessageOperation",
}
- converter = PythonTypeToOpenAPI(
- camel_case=False, name_overrides=name_overrides
+ # Hack to get the unions to be included in the schema
+ class KnownUnions(msgspec.Struct):
+ operation: MessageOperation
+ error: MarimoError
+ data_type: DataType
+
+ specs = msgspec.json.schema_components(
+ MESSAGES + [KnownUnions],
+ ref_template="#/components/schemas/{name}",
)
- for cls in MESSAGES:
- # Remove self from the list
- # since it may not have been processed yet
- if cls in processed_classes:
- del processed_classes[cls]
- name = name_overrides.get(cls, cls.__name__) # type: ignore[attr-defined]
- component_schemas[name] = converter.convert(cls, processed_classes)
- processed_classes[cls] = name
+ component_schemas = {
+ **specs[1],
+ }
+ processed_classes = {
+ **processed_classes,
+ **{name: name for name in specs[1].keys()},
+ }
converter = PythonTypeToOpenAPI(
camel_case=True, name_overrides=name_overrides
@@ -274,7 +290,7 @@ def _generate_server_api_schema() -> dict[str, Any]:
component_schemas[name] = converter.convert(cls, processed_classes)
processed_classes[cls] = name
- schemas = SchemaGenerator(
+ schemas_geneartor = SchemaGenerator(
{
"openapi": "3.1.0",
"info": {"title": "marimo API", "version": __version__},
@@ -286,7 +302,16 @@ def _generate_server_api_schema() -> dict[str, Any]:
}
)
- return schemas.get_schema(routes=build_routes())
+ schemas = schemas_geneartor.get_schema(routes=build_routes())
+
+ # Find/replace #/$defs with #/components/schemas
+ import json
+
+ schemas_str = json.dumps(schemas)
+ schemas_str = schemas_str.replace("#/$defs", "#/components/schemas")
+ schemas = json.loads(schemas_str)
+
+ return schemas
@click.group(
diff --git a/marimo/_config/config.py b/marimo/_config/config.py
index 1463c55a99..aa4eecc97d 100644
--- a/marimo/_config/config.py
+++ b/marimo/_config/config.py
@@ -492,7 +492,6 @@ class StoreConfig(TypedDict, total=False):
CacheConfig = Union[list[StoreConfig], StoreConfig]
-@dataclass
class ExperimentalConfig(TypedDict, total=False):
"""
Configuration for experimental features.
@@ -515,7 +514,7 @@ class ExperimentalConfig(TypedDict, total=False):
# Prefer to accept any dict since feature flags can change frequently
# But maintain type safety for known flags
-ExperimentalConfigType = Union[dict[str, Any], ExperimentalConfig]
+ExperimentalConfigType = dict[str, Any]
@mddoc
diff --git a/marimo/_data/models.py b/marimo/_data/models.py
index c80d8134ab..535a39c289 100644
--- a/marimo/_data/models.py
+++ b/marimo/_data/models.py
@@ -1,10 +1,10 @@
# Copyright 2024 Marimo. All rights reserved.
from __future__ import annotations
-from dataclasses import dataclass, field
from datetime import date, datetime, time, timedelta # noqa: TCH003
-from decimal import Decimal
-from typing import Any, Literal, Optional, Union
+from typing import TYPE_CHECKING, Any, Literal, Optional, Union
+
+import msgspec
from marimo._types.ids import VariableName
@@ -23,8 +23,7 @@ DataType = Literal[
ExternalDataType = str
-@dataclass
-class DataTableColumn:
+class DataTableColumn(msgspec.Struct):
"""
Represents a column in a data table.
@@ -49,8 +48,7 @@ DataTableSource = Literal["local", "duckdb", "connection", "catalog"]
DataTableType = Literal["table", "view"]
-@dataclass
-class DataTable:
+class DataTable(msgspec.Struct):
"""
Represents a data table.
@@ -81,14 +79,12 @@ class DataTable:
indexes: Optional[list[str]] = None
-@dataclass
-class Schema:
+class Schema(msgspec.Struct):
name: str
- tables: list[DataTable] = field(default_factory=list)
+ tables: list[DataTable]
-@dataclass
-class Database:
+class Database(msgspec.Struct):
"""
Represents a collection of schemas.
@@ -101,20 +97,25 @@ class Database:
name: str
dialect: str
- schemas: list[Schema] = field(default_factory=list)
+ schemas: list[Schema]
engine: Optional[VariableName] = None
-NumericLiteral = Union[int, float, Decimal]
-TemporalLiteral = Union[date, time, datetime, timedelta]
-NonNestedLiteral = Union[NumericLiteral, TemporalLiteral, str, bool, bytes]
+if TYPE_CHECKING:
+ from decimal import Decimal
+
+ NumericLiteral = Union[int, float, Decimal]
+ TemporalLiteral = Union[date, time, datetime, timedelta]
+ NonNestedLiteral = Union[NumericLiteral, TemporalLiteral, str, bool, bytes]
+else:
+ # For runtime/msgspec, use Any since msgspec can't handle unions with
+ # multiple str-like types (str, datetime, date, time, timedelta)
+ NonNestedLiteral = Any
-@dataclass
-class ColumnStats:
+class ColumnStats(msgspec.Struct):
"""
Represents stats for a column in a data table.
-
"""
total: Optional[int] = None
@@ -134,8 +135,7 @@ class ColumnStats:
p95: Optional[NonNestedLiteral] = None
-@dataclass
-class BinValue:
+class BinValue(msgspec.Struct):
"""
Represents bin values for a column in a data table. This is used for plotting.
@@ -150,8 +150,7 @@ class BinValue:
count: int
-@dataclass
-class ValueCount:
+class ValueCount(msgspec.Struct):
"""
Represents a value and its count in a column in a data table.
Currently used for string columns.
@@ -165,8 +164,7 @@ class ValueCount:
count: int
-@dataclass
-class DataSourceConnection:
+class DataSourceConnection(msgspec.Struct):
"""
Represents a data source connection.
@@ -184,6 +182,6 @@ class DataSourceConnection:
dialect: str
name: str
display_name: str
- databases: list[Database] = field(default_factory=list)
+ databases: list[Database]
default_database: Optional[str] = None
default_schema: Optional[str] = None
diff --git a/marimo/_messaging/cell_output.py b/marimo/_messaging/cell_output.py
index 6df52e03b0..e864111b58 100644
--- a/marimo/_messaging/cell_output.py
+++ b/marimo/_messaging/cell_output.py
@@ -4,12 +4,14 @@
from __future__ import annotations
import time
-from dataclasses import asdict, dataclass, field
from enum import Enum
from typing import Any, Union
+import msgspec
+
from marimo._messaging.errors import Error
from marimo._messaging.mimetypes import ConsoleMimeType, KnownMimeType
+from marimo._messaging.msgspec_encoder import asdict
class CellChannel(str, Enum):
@@ -27,13 +29,12 @@ class CellChannel(str, Enum):
return self.value
-@dataclass
-class CellOutput:
+class CellOutput(msgspec.Struct):
# descriptive name about the kind of output: e.g., stdout, stderr, ...
channel: CellChannel
mimetype: KnownMimeType
data: Union[str, list[Error], dict[str, Any]]
- timestamp: float = field(default_factory=lambda: time.time())
+ timestamp: float = msgspec.field(default_factory=lambda: time.time())
def __repr__(self) -> str:
return f"CellOutput(channel={self.channel}, mimetype={self.mimetype}, timestamp={self.timestamp})"
diff --git a/marimo/_messaging/completion_option.py b/marimo/_messaging/completion_option.py
index f0a5ffac5b..54ddff16e7 100644
--- a/marimo/_messaging/completion_option.py
+++ b/marimo/_messaging/completion_option.py
@@ -3,12 +3,12 @@
from __future__ import annotations
-from dataclasses import dataclass
from typing import Optional
+import msgspec
-@dataclass
-class CompletionOption:
+
+class CompletionOption(msgspec.Struct):
# completed symbol name
name: str
# type of symbol
diff --git a/marimo/_messaging/errors.py b/marimo/_messaging/errors.py
index 33e1824eda..62e2830eef 100644
--- a/marimo/_messaging/errors.py
+++ b/marimo/_messaging/errors.py
@@ -1,122 +1,100 @@
# Copyright 2024 Marimo. All rights reserved.
from __future__ import annotations
-from dataclasses import dataclass
-from typing import Literal, Optional, Union
+from typing import Optional, Union
+
+import msgspec
from marimo._runtime.dataflow import EdgeWithVar
from marimo._types.ids import CellId_t
-@dataclass
-class SetupRootError:
+class SetupRootError(msgspec.Struct, tag="setup-refs"):
edges_with_vars: tuple[EdgeWithVar, ...]
- type: Literal["setup-refs"] = "setup-refs"
def describe(self) -> str:
return "The setup cell cannot have references"
-@dataclass
-class CycleError:
+class CycleError(msgspec.Struct, tag="cycle"):
edges_with_vars: tuple[EdgeWithVar, ...]
- type: Literal["cycle"] = "cycle"
def describe(self) -> str:
return "This cell is in a cycle"
-@dataclass
-class MultipleDefinitionError:
+class MultipleDefinitionError(msgspec.Struct, tag="multiple-defs"):
name: str
cells: tuple[CellId_t, ...]
- type: Literal["multiple-defs"] = "multiple-defs"
def describe(self) -> str:
return f"The variable '{self.name}' was defined by another cell"
-@dataclass
-class ImportStarError:
+class ImportStarError(msgspec.Struct, tag="import-star"):
msg: str
- type: Literal["import-star"] = "import-star"
def describe(self) -> str:
return self.msg
-@dataclass
-class MarimoInterruptionError:
- type: Literal["interruption"] = "interruption"
-
+class MarimoInterruptionError(msgspec.Struct, tag="interruption"):
def describe(self) -> str:
return "This cell was interrupted and needs to be re-run"
-@dataclass
-class MarimoAncestorPreventedError:
+class MarimoAncestorPreventedError(msgspec.Struct, tag="ancestor-prevented"):
msg: str
raising_cell: CellId_t
blamed_cell: Optional[CellId_t]
- type: Literal["ancestor-prevented"] = "ancestor-prevented"
def describe(self) -> str:
return self.msg
-@dataclass
-class MarimoAncestorStoppedError:
+class MarimoAncestorStoppedError(msgspec.Struct, tag="ancestor-stopped"):
msg: str
raising_cell: CellId_t
- type: Literal["ancestor-stopped"] = "ancestor-stopped"
def describe(self) -> str:
return self.msg
-@dataclass
-class MarimoExceptionRaisedError:
+class MarimoExceptionRaisedError(msgspec.Struct, tag="exception"):
msg: str
exception_type: str
# None for if raising_cell is the current cell
raising_cell: Optional[CellId_t]
- type: Literal["exception"] = "exception"
def describe(self) -> str:
return self.msg
-@dataclass
-class MarimoSyntaxError:
+class MarimoSyntaxError(msgspec.Struct, tag="syntax"):
msg: str
- type: Literal["syntax"] = "syntax"
def describe(self) -> str:
return self.msg
-@dataclass
-class UnknownError:
+class UnknownError(msgspec.Struct, tag="unknown"):
msg: str
- type: Literal["unknown"] = "unknown"
+ error_type: Optional[str] = None
def describe(self) -> str:
return self.msg
-@dataclass
-class MarimoStrictExecutionError:
+class MarimoStrictExecutionError(msgspec.Struct, tag="strict-exception"):
msg: str
ref: str
blamed_cell: Optional[CellId_t]
- type: Literal["strict-exception"] = "strict-exception"
def describe(self) -> str:
return self.msg
-@dataclass
-class MarimoInternalError:
+class MarimoInternalError(msgspec.Struct, tag="internal"):
"""
An internal error that should be hidden from the user.
The error is logged to the console and then a new error is broadcasted
@@ -126,7 +104,6 @@ class MarimoInternalError:
"""
error_id: str
- type: Literal["internal"] = "internal"
msg: str = ""
def __post_init__(self) -> None:
@@ -141,22 +118,28 @@ def is_unexpected_error(error: Error) -> bool:
These errors are unexpected, in that they are not intentional.
mo.stop and interrupt are intentional.
"""
- return error.type not in [
- "ancestor-prevented",
- "ancestor-stopped",
- "interruption",
- ]
+ return not isinstance(
+ error,
+ (
+ MarimoAncestorPreventedError,
+ MarimoAncestorStoppedError,
+ MarimoInterruptionError,
+ ),
+ )
def is_sensitive_error(error: Error) -> bool:
"""
These errors are sensitive, in that they are intentional.
"""
- return error.type not in [
- "ancestor-prevented",
- "ancestor-stopped",
- "internal",
- ]
+ return not isinstance(
+ error,
+ (
+ MarimoAncestorPreventedError,
+ MarimoAncestorStoppedError,
+ MarimoInternalError,
+ ),
+ )
Error = Union[
diff --git a/marimo/_messaging/msgspec_encoder.py b/marimo/_messaging/msgspec_encoder.py
new file mode 100644
index 0000000000..76e2ae07a9
--- /dev/null
+++ b/marimo/_messaging/msgspec_encoder.py
@@ -0,0 +1,107 @@
+# Copyright 2024 Marimo. All rights reserved.
+"""Msgspec encoder with custom type support for marimo."""
+
+from __future__ import annotations
+
+from typing import Any
+
+import msgspec
+import msgspec.json
+
+from marimo._dependencies.dependencies import DependencyManager
+
+
+def enc_hook(obj: Any) -> Any:
+ """Custom encoding hook for marimo types."""
+
+ if isinstance(obj, range):
+ return list(obj)
+
+ if isinstance(obj, complex):
+ return str(obj)
+
+ if hasattr(obj, "_mime_"):
+ mimetype, data = obj._mime_()
+ return {"mimetype": mimetype, "data": data}
+
+ if DependencyManager.numpy.imported():
+ import numpy as np
+
+ if isinstance(obj, (np.datetime64, np.complexfloating)):
+ return str(obj)
+ if isinstance(obj, np.integer):
+ return int(obj)
+ if isinstance(obj, np.floating):
+ return float(obj)
+ if isinstance(obj, np.ndarray):
+ if any(
+ np.issubdtype(obj.dtype, dtype)
+ for dtype in (np.datetime64, np.complexfloating)
+ ):
+ return obj.astype(str).tolist()
+ return obj.tolist()
+ if isinstance(obj, np.dtype):
+ return str(obj)
+
+ if DependencyManager.pandas.imported():
+ import pandas as pd
+
+ if isinstance(obj, pd.DataFrame):
+ return obj.to_dict("records")
+ if isinstance(obj, pd.Series):
+ return obj.to_list()
+ if isinstance(obj, pd.Categorical):
+ return obj.tolist()
+ if isinstance(
+ obj,
+ (pd.CategoricalDtype, pd.Timestamp, pd.Timedelta, pd.Interval),
+ ):
+ return str(obj)
+ if isinstance(obj, pd.TimedeltaIndex):
+ return obj.astype(str).tolist()
+
+ # Catch-all for other pandas objects
+ try:
+ if isinstance(obj, pd.core.base.PandasObject): # type: ignore
+ import json
+
+ return json.loads(obj.to_json(date_format="iso"))
+ except AttributeError:
+ pass
+
+ if DependencyManager.polars.imported():
+ import polars as pl
+
+ if isinstance(obj, pl.DataFrame):
+ return obj.to_dict()
+
+ if isinstance(obj, pl.Series):
+ return obj.to_list()
+
+ raise NotImplementedError(f"Objects of type {type(obj)} are not supported")
+
+
+_encoder = msgspec.json.Encoder(enc_hook=enc_hook, decimal_format="number")
+
+
+def encode_json_bytes(obj: Any) -> bytes:
+ """
+ Encode an object as JSON and return the result as bytes.
+ """
+ return _encoder.encode(obj)
+
+
+def encode_json_str(obj: Any) -> str:
+ """
+ Encode an object as JSON and return the result as a UTF-8 string.
+ """
+ return _encoder.encode(obj).decode("utf-8")
+
+
+def asdict(obj: msgspec.Struct) -> dict[str, Any]:
+ """
+ Convert a msgspec.Struct into a dict of builtin Python types.
+
+ Uses `msgspec.to_builtins` with `enc_hook` to handle unsupported values.
+ """
+ return msgspec.to_builtins(obj, enc_hook=enc_hook) # type: ignore[no-any-return]
diff --git a/marimo/_messaging/ops.py b/marimo/_messaging/ops.py
index fd7ce8928d..2cd59ab449 100644
--- a/marimo/_messaging/ops.py
+++ b/marimo/_messaging/ops.py
@@ -6,11 +6,9 @@ Messages that the kernel sends to the frontend.
from __future__ import annotations
-import json
import sys
import time
from collections.abc import Sequence # noqa: TC003
-from dataclasses import asdict, dataclass, field
from types import ModuleType
from typing import (
Any,
@@ -18,10 +16,11 @@ from typing import (
Literal,
Optional,
Union,
- cast,
)
from uuid import uuid4
+import msgspec
+
from marimo import _loggers as loggers
from marimo._ast.app_config import _AppConfig
from marimo._ast.cell import CellConfig, RuntimeStateType
@@ -42,11 +41,11 @@ from marimo._messaging.errors import (
is_sensitive_error,
)
from marimo._messaging.mimetypes import KnownMimeType
+from marimo._messaging.msgspec_encoder import encode_json_bytes
from marimo._messaging.streams import output_max_bytes
from marimo._messaging.types import Stream
from marimo._messaging.variables import get_variable_preview
from marimo._output.hypertext import Html
-from marimo._plugins.core.json_encoder import WebComponentEncoder
from marimo._plugins.core.web_component import JSONType
from marimo._plugins.ui._core.ui_element import UIElement
from marimo._runtime.context import get_context
@@ -60,29 +59,9 @@ from marimo._utils.platform import is_pyodide, is_windows
LOGGER = loggers.marimo_logger()
-def serialize(datacls: Any) -> dict[str, JSONType]:
- # TODO(akshayka): maybe serialize as bytes (JSON), not objects ...,
- # then `send_bytes` over connection ... to try to avoid pickling
- # issues
- try:
- # Try to serialize as a dataclass
- return cast(
- dict[str, JSONType],
- asdict(datacls),
- )
- except Exception:
- # If that fails, try to serialize using the WebComponentEncoder
- return cast(
- dict[str, JSONType],
- json.loads(WebComponentEncoder.json_dumps(datacls)),
- )
-
-
-@dataclass
-class Op:
+class Op(msgspec.Struct, tag_field="op"):
name: ClassVar[str]
- # TODO(akshayka): fix typing once mypy has stricter typing for asdict
def broadcast(self, stream: Optional[Stream] = None) -> None:
if stream is None:
try:
@@ -103,12 +82,11 @@ class Op:
)
return
- def serialize(self) -> dict[str, Any]:
- return serialize(self)
+ def serialize(self) -> bytes:
+ return encode_json_bytes(self)
-@dataclass
-class CellOp(Op):
+class CellOp(Op, tag="cell-op"):
"""Op to transition a cell.
A CellOp's data has some optional fields:
@@ -136,7 +114,7 @@ class CellOp(Op):
stale_inputs: Optional[bool] = None
run_id: Optional[RunId_t] = None
serialization: Optional[str] = None
- timestamp: float = field(default_factory=lambda: time.time())
+ timestamp: float = msgspec.field(default_factory=lambda: time.time())
def __post_init__(self) -> None:
if self.run_id is not None:
@@ -327,8 +305,7 @@ class CellOp(Op):
CellOp(cell_id=cell_id, serialization=str(status)).broadcast(stream)
-@dataclass
-class HumanReadableStatus:
+class HumanReadableStatus(msgspec.Struct):
"""Human-readable status."""
code: Literal["ok", "error"]
@@ -336,8 +313,7 @@ class HumanReadableStatus:
message: Union[str, None] = None
-@dataclass
-class FunctionCallResult(Op):
+class FunctionCallResult(Op, tag="function-call-result"):
"""Result of calling a function."""
name: ClassVar[str] = "function-call-result"
@@ -346,29 +322,16 @@ class FunctionCallResult(Op):
return_value: JSONType
status: HumanReadableStatus
- def __post_init__(self) -> None:
- # We want to serialize the return_value using our custom JSON encoder
- try:
- self.return_value = json.loads(
- WebComponentEncoder.json_dumps(self.return_value)
- )
- except Exception as e:
- LOGGER.exception(
- "Error serializing function call result %s: %s",
- self.__class__.__name__,
- e,
- )
-
- def serialize(self) -> dict[str, Any]:
+ def serialize(self) -> bytes:
try:
- return serialize(self)
+ return encode_json_bytes(self)
except Exception as e:
LOGGER.exception(
"Error serializing function call result %s: %s",
self.__class__.__name__,
e,
)
- return serialize(
+ return encode_json_bytes(
FunctionCallResult(
function_call_id=self.function_call_id,
return_value=None,
@@ -381,16 +344,14 @@ class FunctionCallResult(Op):
)
-@dataclass
-class RemoveUIElements(Op):
+class RemoveUIElements(Op, tag="remove-ui-elements"):
"""Invalidate UI elements for a given cell."""
name: ClassVar[str] = "remove-ui-elements"
cell_id: CellId_t
-@dataclass
-class SendUIElementMessage(Op):
+class SendUIElementMessage(Op, tag="send-ui-element-message"):
"""Send a message to a UI element."""
name: ClassVar[str] = "send-ui-element-message"
@@ -400,22 +361,19 @@ class SendUIElementMessage(Op):
buffers: Optional[list[str]] = None
-@dataclass
-class Interrupted(Op):
+class Interrupted(Op, tag="interrupted"):
"""Written when the kernel is interrupted by the user."""
name: ClassVar[str] = "interrupted"
-@dataclass
-class CompletedRun(Op):
+class CompletedRun(Op, tag="completed-run"):
"""Written on run completion (of submitted cells and their descendants."""
name: ClassVar[str] = "completed-run"
-@dataclass
-class KernelCapabilities:
+class KernelCapabilities(msgspec.Struct):
terminal: bool = False
pylsp: bool = False
ty: bool = False
@@ -429,8 +387,7 @@ class KernelCapabilities:
self.ty = DependencyManager.ty.has()
-@dataclass
-class KernelReady(Op):
+class KernelReady(Op, tag="kernel-ready"):
"""Kernel is ready for execution."""
name: ClassVar[str] = "kernel-ready"
@@ -455,8 +412,7 @@ class KernelReady(Op):
capabilities: KernelCapabilities
-@dataclass
-class CompletionResult(Op):
+class CompletionResult(Op, tag="completion-result"):
"""Code completion result."""
name: ClassVar[str] = "completion-result"
@@ -465,8 +421,7 @@ class CompletionResult(Op):
options: list[CompletionOption]
-@dataclass
-class Alert(Op):
+class Alert(Op, tag="alert"):
name: ClassVar[str] = "alert"
title: str
# description may be HTML
@@ -474,8 +429,7 @@ class Alert(Op):
variant: Optional[Literal["danger"]] = None
-@dataclass
-class MissingPackageAlert(Op):
+class MissingPackageAlert(Op, tag="missing-package-alert"):
name: ClassVar[str] = "missing-package-alert"
packages: list[str]
isolated: bool
@@ -487,19 +441,16 @@ PackageStatusType = dict[
]
-@dataclass
-class InstallingPackageAlert(Op):
+class InstallingPackageAlert(Op, tag="installing-package-alert"):
name: ClassVar[str] = "installing-package-alert"
packages: PackageStatusType
-@dataclass
-class Reconnected(Op):
+class Reconnected(Op, tag="reconnected"):
name: ClassVar[str] = "reconnected"
-@dataclass
-class Banner(Op):
+class Banner(Op, tag="banner"):
name: ClassVar[str] = "banner"
title: str
# description may be HTML
@@ -508,48 +459,50 @@ class Banner(Op):
action: Optional[Literal["restart"]] = None
-@dataclass
-class Reload(Op):
+class Reload(Op, tag="reload"):
name: ClassVar[str] = "reload"
-@dataclass
-class VariableDeclaration:
+class VariableDeclaration(msgspec.Struct):
name: str
declared_by: list[CellId_t]
used_by: list[CellId_t]
-@dataclass
-class VariableValue:
+class VariableValue(msgspec.Struct):
name: str
value: Optional[str]
datatype: Optional[str]
- def __init__(
- self, name: str, value: object, datatype: Optional[str] = None
- ) -> None:
- self.name = name
-
+ @staticmethod
+ def create(
+ name: str, value: object, datatype: Optional[str] = None
+ ) -> VariableValue:
+ """Factory method to create a VariableValue from an object."""
# Defensively try-catch attribute accesses, which could raise
# exceptions
# If datatype is already defined, don't try to infer it
if datatype is None:
try:
- self.datatype = (
+ computed_datatype = (
type(value).__name__ if value is not None else None
)
except Exception:
- self.datatype = datatype
+ computed_datatype = datatype
else:
- self.datatype = datatype
+ computed_datatype = datatype
try:
- self.value = self._format_value(value)
+ formatted_value = VariableValue._format_value_static(value)
except Exception:
- self.value = None
+ formatted_value = None
+
+ return VariableValue(
+ name=name, value=formatted_value, datatype=computed_datatype
+ )
- def _stringify(self, value: object) -> str:
+ @staticmethod
+ def _stringify_static(value: object) -> str:
MAX_STR_LEN = 50
if isinstance(value, str):
@@ -566,7 +519,8 @@ class VariableValue:
# BaseExceptions, which shouldn't crash the kernel
return "<UNKNOWN>"
- def _format_value(self, value: object) -> str:
+ @staticmethod
+ def _format_value_static(value: object) -> str:
resolved = value
if isinstance(value, UIElement):
resolved = value.value
@@ -574,27 +528,24 @@ class VariableValue:
resolved = value.text
elif isinstance(value, ModuleType):
resolved = value.__name__
- return self._stringify(resolved)
+ return VariableValue._stringify_static(resolved)
-@dataclass
-class Variables(Op):
+class Variables(Op, tag="variables"):
"""List of variable declarations."""
name: ClassVar[str] = "variables"
variables: list[VariableDeclaration]
-@dataclass
-class VariableValues(Op):
+class VariableValues(Op, tag="variable-values"):
"""List of variables and their types/values."""
name: ClassVar[str] = "variable-values"
variables: list[VariableValue]
-@dataclass
-class Datasets(Op):
+class Datasets(Op, tag="datasets"):
"""List of datasets."""
name: ClassVar[str] = "datasets"
@@ -602,8 +553,7 @@ class Datasets(Op):
clear_channel: Optional[DataTableSource] = None
-@dataclass
-class SQLTablePreview(Op):
+class SQLTablePreview(Op, tag="sql-table-preview"):
"""Preview of a table in a SQL database."""
name: ClassVar[str] = "sql-table-preview"
@@ -612,18 +562,16 @@ class SQLTablePreview(Op):
error: Optional[str] = None
-@dataclass
-class SQLTableListPreview(Op):
+class SQLTableListPreview(Op, tag="sql-table-list-preview"):
"""Preview of a list of tables in a schema."""
name: ClassVar[str] = "sql-table-list-preview"
request_id: RequestId
- tables: list[DataTable] = field(default_factory=list)
+ tables: list[DataTable] = msgspec.field(default_factory=list)
error: Optional[str] = None
-@dataclass
-class ColumnPreview:
+class ColumnPreview(msgspec.Struct):
chart_spec: Optional[str] = None
chart_code: Optional[str] = None
error: Optional[str] = None
@@ -633,8 +581,7 @@ class ColumnPreview:
# We shouldn't need to make table_name and column_name have default values.
# We can use kw_only=True once we drop support for Python 3.9.
-@dataclass()
-class DataColumnPreview(Op, ColumnPreview):
+class DataColumnPreview(Op, ColumnPreview, tag="data-column-preview"):
"""Preview of a column in a dataset."""
name: ClassVar[str] = "data-column-preview"
@@ -642,14 +589,12 @@ class DataColumnPreview(Op, ColumnPreview):
column_name: str = ""
-@dataclass
-class DataSourceConnections(Op):
+class DataSourceConnections(Op, tag="data-source-connections"):
name: ClassVar[str] = "data-source-connections"
connections: list[DataSourceConnection]
-@dataclass
-class QueryParamsSet(Op):
+class QueryParamsSet(Op, tag="query-params-set"):
"""Set query parameters."""
name: ClassVar[str] = "query-params-set"
@@ -657,15 +602,13 @@ class QueryParamsSet(Op):
value: Union[str, list[str]]
-@dataclass
-class QueryParamsAppend(Op):
+class QueryParamsAppend(Op, tag="query-params-append"):
name: ClassVar[str] = "query-params-append"
key: str
value: str
-@dataclass
-class QueryParamsDelete(Op):
+class QueryParamsDelete(Op, tag="query-params-delete"):
name: ClassVar[str] = "query-params-delete"
key: str
# If value is None, delete all values for the key
@@ -673,20 +616,17 @@ class QueryParamsDelete(Op):
value: Optional[str]
-@dataclass
-class QueryParamsClear(Op):
+class QueryParamsClear(Op, tag="query-params-clear"):
# Clear all query parameters
name: ClassVar[str] = "query-params-clear"
-@dataclass
-class FocusCell(Op):
+class FocusCell(Op, tag="focus-cell"):
name: ClassVar[str] = "focus-cell"
cell_id: CellId_t
-@dataclass
-class UpdateCellCodes(Op):
+class UpdateCellCodes(Op, tag="update-cell-codes"):
name: ClassVar[str] = "update-cell-codes"
cell_ids: list[CellId_t]
codes: list[str]
@@ -695,8 +635,7 @@ class UpdateCellCodes(Op):
code_is_stale: bool
-@dataclass
-class SecretKeysResult(Op):
+class SecretKeysResult(Op, tag="secret-keys-result"):
"""Result of listing secret keys."""
request_id: RequestId
@@ -704,8 +643,7 @@ class SecretKeysResult(Op):
secrets: list[SecretKeysWithProvider]
-@dataclass
-class UpdateCellIdsRequest(Op):
+class UpdateCellIdsRequest(Op, tag="update-cell-ids"):
"""
Update the cell ID ordering of the cells in the notebook.
diff --git a/marimo/_messaging/streams.py b/marimo/_messaging/streams.py
index 4a1e1e628e..355ed78360 100644
--- a/marimo/_messaging/streams.py
+++ b/marimo/_messaging/streams.py
@@ -119,7 +119,7 @@ class ThreadSafeStream(Stream):
# stdin messages are pulled from this queue
self.input_queue = input_queue
- def write(self, op: str, data: dict[Any, Any]) -> None:
+ def write(self, op: str, data: bytes) -> None:
with self.stream_lock:
try:
self.pipe.send((op, data))
diff --git a/marimo/_messaging/types.py b/marimo/_messaging/types.py
index 3e4ac42196..4481fa7665 100644
--- a/marimo/_messaging/types.py
+++ b/marimo/_messaging/types.py
@@ -3,14 +3,14 @@ from __future__ import annotations
import abc
import io
-from typing import Any, Optional
+from typing import Optional
from marimo._messaging.mimetypes import ConsoleMimeType
from marimo._types.ids import CellId_t
# The message from the kernel is a tuple of message type
# and a json representation of the message
-KernelMessage = tuple[str, Any]
+KernelMessage = tuple[str, bytes]
class Stream(abc.ABC):
@@ -23,7 +23,7 @@ class Stream(abc.ABC):
cell_id: Optional[CellId_t] = None
@abc.abstractmethod
- def write(self, op: str, data: dict[Any, Any]) -> None:
+ def write(self, op: str, data: bytes) -> None:
pass
def stop(self) -> None:
@@ -32,7 +32,7 @@ class Stream(abc.ABC):
class NoopStream(Stream):
- def write(self, op: str, data: dict[Any, Any]) -> None:
+ def write(self, op: str, data: bytes) -> None:
pass
diff --git a/marimo/_plugins/core/json_encoder.py b/marimo/_plugins/core/json_encoder.py
deleted file mode 100644
index 5a46108798..0000000000
--- a/marimo/_plugins/core/json_encoder.py
+++ /dev/null
@@ -1,182 +0,0 @@
-# Copyright 2024 Marimo. All rights reserved.
-from __future__ import annotations
-
-import dataclasses
-import datetime
-import json
-from decimal import Decimal
-from enum import Enum
-from json import JSONEncoder
-from typing import Any
-from uuid import UUID
-
-from marimo._dependencies.dependencies import DependencyManager
-
-
-class WebComponentEncoder(JSONEncoder):
- @staticmethod
- def json_dumps(o: Any) -> Any:
- """Serialize an object to JSON."""
- return json.dumps(o, cls=WebComponentEncoder)
-
- def default(self, o: Any) -> Any:
- """Override default method to handle additional types."""
- return self._convert_to_json(o)
-
- def _convert_to_json(self, o: Any) -> Any:
- """Convert various types to JSON serializable format."""
- # Primitives (most common case first for performance)
- if isinstance(o, (str, int, float, bool, type(None))):
- return o
-
- # Handle bytes objects
- if isinstance(o, memoryview):
- o = o.tobytes()
-
- if isinstance(o, bytes):
- try:
- return o.decode("utf-8")
- except UnicodeDecodeError:
- # Fallback to latin1
- return o.decode("latin1")
-
- # Handle datetime objects
- if isinstance(o, (datetime.datetime, datetime.date, datetime.time)):
- return o.isoformat()
-
- # Handle timedelta
- if isinstance(o, datetime.timedelta):
- return str(o)
-
- # Handle UUID
- if isinstance(o, UUID):
- return str(o)
-
- # Handle enum
- if isinstance(o, Enum):
- return o.name
-
- # Handle complex numbers
- if isinstance(o, complex):
- return str(o)
-
- # Handle iterable objects
- if isinstance(o, (set, frozenset)):
- return list(o)
-
- # If handled by default encoder
- if isinstance(o, (dict, list)):
- return o
-
- # Handle range and tuple
- if isinstance(o, range) or isinstance(o, tuple):
- return list(o)
-
- # Handle MIME objects
- if hasattr(o, "_mime_"):
- mimetype, data = o._mime_()
- return {"mimetype": mimetype, "data": data}
-
- # Handle decimal objects
- if isinstance(o, Decimal):
- return float(o)
-
- # Handle dataclasses
- # Must come after MIME objects
- if dataclasses.is_dataclass(o):
- # We cannot use asdict since we need to recursively encode
- # the values
- return {
- field.name: self._convert_to_json(getattr(o, field.name))
- for field in dataclasses.fields(o)
- }
-
- # Handle numpy objects
- if DependencyManager.numpy.imported():
- import numpy as np
-
- if isinstance(o, (np.datetime64, np.complexfloating)):
- return str(o)
- if isinstance(o, np.integer):
- return int(o)
- if isinstance(o, np.floating):
- return float(o)
- if isinstance(o, np.ndarray):
- if any(
- np.issubdtype(o.dtype, dtype)
- for dtype in (np.datetime64, np.complexfloating)
- ):
- return o.astype(str).tolist()
- return o.tolist()
- if isinstance(o, np.dtype):
- return str(o)
-
- # Handle pandas objects
- if DependencyManager.pandas.imported():
- import pandas as pd
-
- if isinstance(o, pd.DataFrame):
- return o.to_dict("records")
- if isinstance(o, pd.Series):
- return o.to_list()
- if isinstance(o, pd.Categorical):
- return o.tolist()
- if isinstance(
- o,
- (pd.CategoricalDtype, pd.Timestamp, pd.Timedelta, pd.Interval),
- ):
- return str(o)
- if isinstance(o, pd.TimedeltaIndex):
- return o.astype(str).tolist()
-
- # Catch-all for other pandas objects
- try:
- if isinstance(o, pd.core.base.PandasObject): # type: ignore
- return json.loads(o.to_json(date_format="iso"))
- except AttributeError:
- pass
-
- # Handle polars objects
- if DependencyManager.polars.imported():
- import polars as pl
-
- if isinstance(o, pl.DataFrame):
- return o.to_dict()
-
- if isinstance(o, pl.Series):
- return o.to_list()
-
- # Handle named tuples
- if isinstance(o, tuple) and hasattr(o, "_fields"):
- return {
- field: self._convert_to_json(getattr(o, field))
- for field in o._fields # type: ignore
- }
-
- # Handle objects with __slots__
- if hasattr(o, "__slots__"):
- slots = getattr(o, "__slots__", None)
- if slots is not None:
- # Reported error that sometimes poorly formed objects do get passed
- # in.
- try:
- slots = iter(slots)
- except TypeError as e:
- raise TypeError(
- "__slots__ expected to be tuple or list (or at least "
- f"iterable), but got {type(slots)} for {type(o)}"
- ) from e
- return {
- slot: self._convert_to_json(getattr(o, slot))
- for slot in slots
- if hasattr(o, slot)
- }
-
- # Handle custom objects with __dict__
- if hasattr(o, "__dict__"):
- return {
- key: self._convert_to_json(value)
- for key, value in o.__dict__.items()
- }
- # Fallthrough to default encoder
- return JSONEncoder.default(self, o)
diff --git a/marimo/_plugins/core/web_component.py b/marimo/_plugins/core/web_component.py
index f396dc1ee0..36205f4ea0 100644
--- a/marimo/_plugins/core/web_component.py
+++ b/marimo/_plugins/core/web_component.py
@@ -3,17 +3,22 @@ from __future__ import annotations
import json
import re
-from collections.abc import Mapping, Sequence
from html import escape, unescape
from typing import (
TYPE_CHECKING,
+ Any,
TypeVar,
Union,
cast,
)
+from marimo._messaging.msgspec_encoder import encode_json_str
+from marimo._output.md import _md
+from marimo._output.mime import MIME
+
if TYPE_CHECKING:
import sys
+ from collections.abc import Mapping, Sequence
if sys.version_info < (3, 10):
from typing_extensions import TypeAlias
@@ -22,27 +27,26 @@ if TYPE_CHECKING:
from typing import Optional
-from marimo._output.md import _md
-from marimo._output.mime import MIME
-from marimo._plugins.core.json_encoder import WebComponentEncoder
-
-JSONType: TypeAlias = Union[
- Mapping[str, "JSONType"],
- Sequence["JSONType"],
- str,
- int,
- float,
- bool,
- object,
- MIME, # MIME is a JSONType since we have a custom JSONEncoder for it
- None,
-]
+ JSONType: TypeAlias = Union[
+ Mapping[str, "JSONType"],
+ Sequence["JSONType"],
+ str,
+ int,
+ float,
+ bool,
+ object,
+ MIME, # MIME is a JSONType since we have a custom JSONEncoder for it
+ None,
+ ]
+
+else:
+ JSONType = Any
S = TypeVar("S", bound=JSONType)
def _build_attr(name: str, value: JSONType) -> str:
- processed = escape(json.dumps(value, cls=WebComponentEncoder))
+ processed = escape(encode_json_str(value))
# manual escapes for things html.escape doesn't escape
#
# - backslashes, when unescaped can lead to problems
diff --git a/marimo/_plugins/ui/_impl/tables/default_table.py b/marimo/_plugins/ui/_impl/tables/default_table.py
index 5d2561aaca..67f91560b0 100644
--- a/marimo/_plugins/ui/_impl/tables/default_table.py
+++ b/marimo/_plugins/ui/_impl/tables/default_table.py
@@ -2,15 +2,14 @@
from __future__ import annotations
import functools
-import json
from collections import defaultdict
from collections.abc import Sequence
from typing import Any, Optional, Union, cast
from marimo._data.models import BinValue, ColumnStats, ExternalDataType
from marimo._dependencies.dependencies import DependencyManager
+from marimo._messaging.msgspec_encoder import encode_json_str
from marimo._output.mime import MIME
-from marimo._plugins.core.json_encoder import WebComponentEncoder
from marimo._plugins.core.web_component import JSONType
from marimo._plugins.ui._impl.tables.format import (
FormatMapping,
@@ -100,10 +99,10 @@ class DefaultTableManager(TableManager[JsonTableData]):
def to_json_str(
self, format_mapping: Optional[FormatMapping] = None
) -> str:
- return json.dumps(
- self._normalize_data(self.apply_formatting(format_mapping).data),
- cls=WebComponentEncoder,
+ normalized = self._normalize_data(
+ self.apply_formatting(format_mapping).data
)
+ return encode_json_str(normalized)
def to_parquet(self) -> bytes:
if isinstance(self.data, dict) and not self.is_column_oriented:
diff --git a/marimo/_plugins/ui/_impl/tables/narwhals_table.py b/marimo/_plugins/ui/_impl/tables/narwhals_table.py
index 57b003a80e..fea3a4bdc2 100644
--- a/marimo/_plugins/ui/_impl/tables/narwhals_table.py
+++ b/marimo/_plugins/ui/_impl/tables/narwhals_table.py
@@ -7,6 +7,7 @@ import io
from functools import cached_property
from typing import Any, Optional, Union, cast
+import msgspec
import narwhals.stable.v1 as nw
from narwhals.stable.v1.typing import IntoFrameT
@@ -314,9 +315,12 @@ class NarwhalsTableManager(
category=UserWarning,
)
- for key, value in stats.__dict__.items():
+ # Normalize values to Python builtins
+ for field in msgspec.structs.fields(stats):
+ value = getattr(stats, field.name)
if value is not None:
- stats.__dict__[key] = unwrap_py_scalar(value)
+ setattr(stats, field.name, unwrap_py_scalar(value))
+
return stats
def _get_stats_internal(self, column: str) -> ColumnStats:
diff --git a/marimo/_pyodide/bootstrap.py b/marimo/_pyodide/bootstrap.py
index 640d63bd69..927d3964ed 100644
--- a/marimo/_pyodide/bootstrap.py
+++ b/marimo/_pyodide/bootstrap.py
@@ -5,8 +5,11 @@ import json
from typing import TYPE_CHECKING, Callable
from marimo._config.config import merge_config
-from marimo._messaging.ops import KernelCapabilities, KernelReady, serialize
-from marimo._plugins.core.json_encoder import WebComponentEncoder
+from marimo._messaging.msgspec_encoder import (
+ encode_json_bytes,
+ encode_json_str,
+)
+from marimo._messaging.ops import KernelCapabilities, KernelReady
from marimo._runtime.requests import (
AppMetadata,
CreationRequest,
@@ -78,9 +81,7 @@ def create_session(
"""
def write_kernel_message(op: KernelMessage) -> None:
- message_callback(
- WebComponentEncoder.json_dumps({"op": op[0], "data": op[1]})
- )
+ message_callback(encode_json_str({"op": op[0], "data": op[1]}))
# Lazy import to decrease startup time
from marimo._config.config import merge_default_config
@@ -106,7 +107,7 @@ def create_session(
write_kernel_message(
(
KernelReady.name,
- serialize(
+ encode_json_bytes(
KernelReady(
codes=tuple(app.cell_manager.codes()),
names=tuple(app.cell_manager.names()),
diff --git a/marimo/_pyodide/pyodide_session.py b/marimo/_pyodide/pyodide_session.py
index 935a82130c..5b2ffb4d5f 100644
--- a/marimo/_pyodide/pyodide_session.py
+++ b/marimo/_pyodide/pyodide_session.py
@@ -3,16 +3,19 @@ from __future__ import annotations
import asyncio
import base64
-import dataclasses
import json
import re
import signal
+import typing
from pathlib import Path
from typing import Any, Callable, TypeVar
+import msgspec
+
from marimo import _loggers
from marimo._ast.cell import CellConfig
from marimo._config.config import MarimoConfig, merge_default_config
+from marimo._messaging.msgspec_encoder import encode_json_str
from marimo._messaging.types import KernelMessage
from marimo._pyodide.restartable_task import RestartableTask
from marimo._pyodide.streams import (
@@ -67,7 +70,6 @@ from marimo._server.models.models import (
from marimo._server.session.session_view import SessionView
from marimo._snippets.snippets import read_snippets
from marimo._types.ids import CellId_t
-from marimo._utils.case import deep_to_camel_case
from marimo._utils.formatter import DefaultFormatter
from marimo._utils.inline_script_metadata import PyProjectReader
from marimo._utils.parse_dataclass import parse_raw
@@ -209,11 +211,21 @@ class PyodideBridge:
self.file_system = OSFileSystem()
def put_control_request(self, request: str) -> None:
- @dataclasses.dataclass
- class Container:
- body: requests.ControlRequest
+ # Hack: msgspec only supports discriminated unions. This is a hack to just
+ # iterate through possible ControlRequest variants and decode until one works.
+ parsed = None
+ for ControlRequestType in typing.get_args(requests.ControlRequest):
+ try:
+ parsed = parse_raw(request, cls=ControlRequestType)
+ break # success
+ except msgspec.DecodeError:
+ continue
+
+ if parsed is None:
+ raise msgspec.DecodeError(
+ f"Could not decode ControlRequest as any of {typing.get_args(requests.ControlRequest)}"
+ )
- parsed = parse_raw({"body": json.loads(request)}, Container).body
self.session.put_control_request(parsed)
def put_input(self, text: str) -> None:
@@ -350,10 +362,10 @@ class PyodideBridge:
return json.dumps(md)
def _parse(self, request: str, cls: type[T]) -> T:
- return parse_raw(json.loads(request), cls)
+ return parse_raw(request, cls)
def _dump(self, response: Any) -> str:
- return json.dumps(deep_to_camel_case(dataclasses.asdict(response)))
+ return encode_json_str(response)
def _launch_pyodide_kernel(
diff --git a/marimo/_pyodide/streams.py b/marimo/_pyodide/streams.py
index dba5dcfd9d..0b96de954a 100644
--- a/marimo/_pyodide/streams.py
+++ b/marimo/_pyodide/streams.py
@@ -3,7 +3,7 @@ from __future__ import annotations
import asyncio
import sys
-from typing import TYPE_CHECKING, Any, Callable, Optional
+from typing import TYPE_CHECKING, Callable, Optional
from marimo import _loggers
from marimo._messaging.cell_output import CellOutput
@@ -38,7 +38,7 @@ class PyodideStream(Stream):
self.cell_id = cell_id
self.input_queue = input_queue
- def write(self, op: str, data: dict[Any, Any]) -> None:
+ def write(self, op: str, data: bytes) -> None:
self.pipe((op, data))
diff --git a/marimo/_runtime/packages/package_manager.py b/marimo/_runtime/packages/package_manager.py
index 21bc296a9d..b0409e0ae2 100644
--- a/marimo/_runtime/packages/package_manager.py
+++ b/marimo/_runtime/packages/package_manager.py
@@ -3,9 +3,10 @@ from __future__ import annotations
import abc
import subprocess
-from dataclasses import dataclass
from typing import TYPE_CHECKING, Optional
+import msgspec
+
from marimo import _loggers
from marimo._dependencies.dependencies import DependencyManager
from marimo._messaging.ops import Alert
@@ -17,8 +18,7 @@ if TYPE_CHECKING:
LOGGER = _loggers.marimo_logger()
-@dataclass
-class PackageDescription:
+class PackageDescription(msgspec.Struct, rename="camel"):
name: str
version: str
diff --git a/marimo/_runtime/requests.py b/marimo/_runtime/requests.py
index 722f6b16df..b5ca61ef08 100644
--- a/marimo/_runtime/requests.py
+++ b/marimo/_runtime/requests.py
@@ -3,8 +3,8 @@ from __future__ import annotations
import time
from collections import defaultdict
-from collections.abc import Iterator, Mapping
-from dataclasses import asdict, dataclass, field
+from collections.abc import Mapping
+from dataclasses import dataclass
from typing import (
TYPE_CHECKING,
Any,
@@ -14,12 +14,16 @@ from typing import (
)
from uuid import uuid4
+import msgspec
+
from marimo._ast.app_config import _AppConfig
from marimo._config.config import MarimoConfig
from marimo._data.models import DataTableSource
from marimo._types.ids import CellId_t, RequestId, UIElementId, WidgetModelId
if TYPE_CHECKING:
+ from collections.abc import Iterator
+
from starlette.datastructures import URL
from starlette.requests import HTTPConnection
@@ -67,7 +71,9 @@ class HTTPRequest(Mapping[str, Any]):
def _display_(self) -> Any:
try:
- return asdict(self)
+ import dataclasses
+
+ return dataclasses.asdict(self)
except TypeError:
return self.__dict__
@@ -119,8 +125,7 @@ class HTTPRequest(Mapping[str, Any]):
)
-@dataclass
-class PdbRequest:
+class PdbRequest(msgspec.Struct, rename="camel"):
cell_id: CellId_t
# incoming request, e.g. from Starlette or FastAPI
request: Optional[HTTPRequest] = None
@@ -129,26 +134,23 @@ class PdbRequest:
return f"PdbRequest(cell={self.cell_id})"
-@dataclass
-class ExecutionRequest:
+class ExecutionRequest(msgspec.Struct, rename="camel"):
cell_id: CellId_t
code: str
# incoming request, e.g. from Starlette or FastAPI
request: Optional[HTTPRequest] = None
- timestamp: float = field(default_factory=time.time)
+ timestamp: float = msgspec.field(default_factory=time.time)
def __repr__(self) -> str:
preview = self.code[:10].replace("\n", " ")
return f"ExecutionRequest(cell={self.cell_id}, code_preview={preview})"
-@dataclass
-class ExecuteStaleRequest:
+class ExecuteStaleRequest(msgspec.Struct, rename="camel"):
request: Optional[HTTPRequest] = None
-@dataclass
-class ExecuteMultipleRequest:
+class ExecuteMultipleRequest(msgspec.Struct, rename="camel"):
# ids of cells to run
cell_ids: list[CellId_t]
# code to register/run for each cell
@@ -156,7 +158,7 @@ class ExecuteMultipleRequest:
# incoming request, e.g. from Starlette or FastAPI
request: Optional[HTTPRequest] = None
# time at which the request was received
- timestamp: float = field(default_factory=time.time)
+ timestamp: float = msgspec.field(default_factory=time.time)
def __repr__(self) -> str:
return f"ExecuteMultipleRequest(cells={len(self.cell_ids)})"
@@ -179,26 +181,23 @@ class ExecuteMultipleRequest:
)
-@dataclass
-class ExecuteScratchpadRequest:
+class ExecuteScratchpadRequest(msgspec.Struct, rename="camel"):
code: str
# incoming request, e.g. from Starlette or FastAPI
request: Optional[HTTPRequest] = None
-@dataclass
-class RenameRequest:
+class RenameRequest(msgspec.Struct, rename="camel"):
filename: str
-@dataclass
-class SetUIElementValueRequest:
+class SetUIElementValueRequest(msgspec.Struct, rename="camel"):
object_ids: list[UIElementId]
values: list[Any]
# Incoming request, e.g. from Starlette or FastAPI
request: Optional[HTTPRequest] = None
# uniquely identifies the request
- token: str = field(default_factory=lambda: str(uuid4()))
+ token: str = msgspec.field(default_factory=lambda: str(uuid4()))
def __repr__(self) -> str:
return f"SetUIElementValueRequest(n_elements={len(self.object_ids)}, token={self.token})"
@@ -229,8 +228,7 @@ class SetUIElementValueRequest:
return list(zip(self.object_ids, self.values))
-@dataclass
-class FunctionCallRequest:
+class FunctionCallRequest(msgspec.Struct, rename="camel"):
function_call_id: RequestId
namespace: str
function_name: str
@@ -240,8 +238,7 @@ class FunctionCallRequest:
return f"FunctionCallRequest(id={self.function_call_id}, fn={self.namespace}.{self.function_name})"
-@dataclass
-class AppMetadata:
+class AppMetadata(msgspec.Struct, rename="camel"):
"""Hold metadata about the app, like its filename."""
query_params: SerializedQueryParams
@@ -252,14 +249,12 @@ class AppMetadata:
filename: Optional[str] = None
-@dataclass
-class SetCellConfigRequest:
+class SetCellConfigRequest(msgspec.Struct, rename="camel"):
# Map from Cell ID to (possibly partial) CellConfig
configs: dict[CellId_t, dict[str, Any]]
-@dataclass
-class SetUserConfigRequest:
+class SetUserConfigRequest(msgspec.Struct, rename="camel"):
# MarimoConfig TypedDict
config: MarimoConfig
@@ -267,26 +262,22 @@ class SetUserConfigRequest:
return "SetUserConfigRequest(config=...)"
-@dataclass
-class CreationRequest:
+class CreationRequest(msgspec.Struct, rename="camel"):
execution_requests: tuple[ExecutionRequest, ...]
set_ui_element_value_request: SetUIElementValueRequest
auto_run: bool
request: Optional[HTTPRequest] = None
-@dataclass
-class DeleteCellRequest:
+class DeleteCellRequest(msgspec.Struct, rename="camel"):
cell_id: CellId_t
-@dataclass
-class StopRequest:
+class StopRequest(msgspec.Struct, rename="camel"):
pass
-@dataclass
-class CodeCompletionRequest:
+class CodeCompletionRequest(msgspec.Struct, rename="camel"):
id: CompletionRequestId
document: str
"""Source code found in the cell up to the cursor position."""
@@ -296,8 +287,7 @@ class CodeCompletionRequest:
return f"CodeCompletionRequest(id={self.id}, cell={self.cell_id})"
-@dataclass
-class InstallMissingPackagesRequest:
+class InstallMissingPackagesRequest(msgspec.Struct, rename="camel"):
# TODO: index URL (index/channel/...)
manager: str
@@ -307,8 +297,7 @@ class InstallMissingPackagesRequest:
versions: dict[str, str]
-@dataclass
-class PreviewDatasetColumnRequest:
+class PreviewDatasetColumnRequest(msgspec.Struct, rename="camel"):
# The source type of the dataset
source_type: DataTableSource
# The source of the dataset
@@ -324,8 +313,7 @@ class PreviewDatasetColumnRequest:
fully_qualified_table_name: Optional[str] = None
-@dataclass
-class PreviewSQLTableRequest:
+class PreviewSQLTableRequest(msgspec.Struct, rename="camel"):
"""Preview table details in an SQL database"""
request_id: RequestId
@@ -335,8 +323,7 @@ class PreviewSQLTableRequest:
table_name: str
-@dataclass
-class PreviewSQLTableListRequest:
+class PreviewSQLTableListRequest(msgspec.Struct, rename="camel"):
"""Preview list of tables in an SQL schema"""
request_id: RequestId
@@ -345,33 +332,28 @@ class PreviewSQLTableListRequest:
schema: str
-@dataclass
-class PreviewDataSourceConnectionRequest:
+class PreviewDataSourceConnectionRequest(msgspec.Struct, rename="camel"):
"""Fetch a datasource connection"""
engine: str
-@dataclass
-class ListSecretKeysRequest:
+class ListSecretKeysRequest(msgspec.Struct, rename="camel"):
request_id: RequestId
-@dataclass
-class ModelMessage:
+class ModelMessage(msgspec.Struct, rename="camel"):
state: dict[str, Any]
buffer_paths: list[list[Union[str, int]]]
-@dataclass
-class SetModelMessageRequest:
+class SetModelMessageRequest(msgspec.Struct, rename="camel"):
model_id: WidgetModelId
message: ModelMessage
buffers: Optional[list[str]] = None
-@dataclass
-class RefreshSecretsRequest:
+class RefreshSecretsRequest(msgspec.Struct, rename="camel"):
pass
diff --git a/marimo/_runtime/runner/hooks_post_execution.py b/marimo/_runtime/runner/hooks_post_execution.py
index e2a440c958..6d1396905e 100644
--- a/marimo/_runtime/runner/hooks_post_execution.py
+++ b/marimo/_runtime/runner/hooks_post_execution.py
@@ -109,7 +109,7 @@ def _broadcast_variables(
del run_result
values = [
- VariableValue(
+ VariableValue.create(
name=variable,
value=(
runner.glbls[variable] if variable in runner.glbls else None
diff --git a/marimo/_runtime/runtime.py b/marimo/_runtime/runtime.py
index 4fbd4328e5..e89b3058d0 100644
--- a/marimo/_runtime/runtime.py
+++ b/marimo/_runtime/runtime.py
@@ -1860,7 +1860,9 @@ class Kernel:
referring_cells: set[CellId_t] = set()
for name in bound_names:
# TODO update variable values even for namespaces? lenses? etc
- variable_values.append(VariableValue(name=name, value=value))
+ variable_values.append(
+ VariableValue.create(name=name, value=value)
+ )
try:
# subtracting self.graph.definitions[name]: never rerun the
# cell that created the name
diff --git a/marimo/_secrets/models.py b/marimo/_secrets/models.py
index bd25035941..dbba574f9f 100644
--- a/marimo/_secrets/models.py
+++ b/marimo/_secrets/models.py
@@ -2,14 +2,14 @@
from __future__ import annotations
from abc import ABC, abstractmethod
-from dataclasses import dataclass
from typing import Literal
+import msgspec
+
SecretProviderType = Literal["env", "dotenv"]
-@dataclass
-class SecretKeysWithProvider:
+class SecretKeysWithProvider(msgspec.Struct):
provider: SecretProviderType
name: str
keys: list[str]
diff --git a/marimo/_server/api/endpoints/ai.py b/marimo/_server/api/endpoints/ai.py
index 2c5d3c06eb..41195c7189 100644
--- a/marimo/_server/api/endpoints/ai.py
+++ b/marimo/_server/api/endpoints/ai.py
@@ -1,14 +1,13 @@
# Copyright 2024 Marimo. All rights reserved.
from __future__ import annotations
-from dataclasses import asdict
from typing import TYPE_CHECKING
from starlette.authentication import requires
from starlette.exceptions import HTTPException
from starlette.responses import (
- JSONResponse,
PlainTextResponse,
+ Response,
StreamingResponse,
)
@@ -49,6 +48,7 @@ from marimo._server.models.models import (
InvokeAiToolRequest,
InvokeAiToolResponse,
)
+from marimo._server.responses import StructResponse
from marimo._server.router import APIRouter
if TYPE_CHECKING:
@@ -303,7 +303,7 @@ async def ai_inline_completion(
async def invoke_tool(
*,
request: Request,
-) -> JSONResponse:
+) -> Response:
"""
requestBody:
description: The request body for tool invocation
@@ -331,22 +331,23 @@ async def invoke_tool(
body.tool_name, body.arguments
)
- # Create and return the response
- response = InvokeAiToolResponse(
- success=result.error is None,
- tool_name=result.tool_name,
- result=result.result,
- error=result.error,
+ return StructResponse(
+ InvokeAiToolResponse(
+ success=result.error is None,
+ tool_name=result.tool_name,
+ result=result.result,
+ error=result.error,
+ )
)
- return JSONResponse(content=asdict(response))
except Exception as e:
LOGGER.error("Error invoking AI tool %s: %s", body.tool_name, str(e))
# Return error response instead of letting it crash
- error_response = InvokeAiToolResponse(
- success=False,
- tool_name=body.tool_name,
- result=None,
- error=f"Tool invocation failed: {str(e)}",
+ return StructResponse(
+ InvokeAiToolResponse(
+ success=False,
+ tool_name=body.tool_name,
+ result=None,
+ error=f"Tool invocation failed: {str(e)}",
+ )
)
- return JSONResponse(content=asdict(error_response))
diff --git a/marimo/_server/api/endpoints/config.py b/marimo/_server/api/endpoints/config.py
index b4e90d993c..4ef88ef8b7 100644
--- a/marimo/_server/api/endpoints/config.py
+++ b/marimo/_server/api/endpoints/config.py
@@ -1,13 +1,15 @@
# Copyright 2024 Marimo. All rights reserved.
from __future__ import annotations
-from typing import TYPE_CHECKING, Optional
+from typing import TYPE_CHECKING, Optional, cast
from starlette.authentication import requires
from starlette.background import BackgroundTask
from starlette.responses import JSONResponse
from marimo import _loggers
+from marimo._config.config import PartialMarimoConfig
+from marimo._messaging.msgspec_encoder import asdict
from marimo._runtime.requests import SetUserConfigRequest
from marimo._server.api.deps import AppState
from marimo._server.api.utils import parse_request
@@ -52,7 +54,11 @@ async def save_user_config(
body = await parse_request(
request, cls=SaveUserConfigurationRequest, allow_unknown_keys=True
)
- config = app_state.config_manager.save_config(body.config)
+ # TODO: we may want to validate deep-partial here, but validating with PartialMarimoConfig it too strict
+ # so we just cast to PartialMarimoConfig
+ config = app_state.config_manager.save_config(
+ cast(PartialMarimoConfig, body.config)
+ )
background_task: Optional[BackgroundTask] = None
# Update the server's view of the config
@@ -74,6 +80,6 @@ async def save_user_config(
)
return JSONResponse(
- content=SuccessResponse().as_camel_case(),
+ content=asdict(SuccessResponse()),
background=background_task,
)
diff --git a/marimo/_server/api/endpoints/export.py b/marimo/_server/api/endpoints/export.py
index dbebf17273..41b4c846cf 100644
--- a/marimo/_server/api/endpoints/export.py
+++ b/marimo/_server/api/endpoints/export.py
@@ -9,6 +9,7 @@ from starlette.exceptions import HTTPException
from starlette.responses import HTMLResponse, JSONResponse, PlainTextResponse
from marimo import _loggers
+from marimo._messaging.msgspec_encoder import asdict
from marimo._server.api.deps import AppState
from marimo._server.api.status import HTTPStatus
from marimo._server.api.utils import parse_request
@@ -153,7 +154,7 @@ async def auto_export_as_html(
session_view.mark_auto_export_html()
return JSONResponse(
- content=SuccessResponse().as_camel_case(),
+ content=asdict(SuccessResponse()),
background=BackgroundTask(_background_export),
)
@@ -306,7 +307,7 @@ async def auto_export_as_markdown(
session_view.mark_auto_export_md()
return JSONResponse(
- content=SuccessResponse().as_camel_case(),
+ content=asdict(SuccessResponse()),
background=BackgroundTask(_background_export),
)
@@ -367,6 +368,6 @@ async def auto_export_as_ipynb(
session_view.mark_auto_export_ipynb()
return JSONResponse(
- content=SuccessResponse().as_camel_case(),
+ content=asdict(SuccessResponse()),
background=BackgroundTask(_background_export),
)
diff --git a/marimo/_server/api/endpoints/home.py b/marimo/_server/api/endpoints/home.py
index 95a2033082..b3a099a237 100644
--- a/marimo/_server/api/endpoints/home.py
+++ b/marimo/_server/api/endpoints/home.py
@@ -178,10 +178,12 @@ async def tutorial(
schema:
$ref: "#/components/schemas/MarimoFile"
"""
+ import msgspec
+
# Create a new tutorial file and return the filepath
try:
body = await parse_request(request, cls=OpenTutorialRequest)
- except ValueError:
+ except msgspec.ValidationError:
return JSONResponse({"detail": "Tutorial not found"}, status_code=400)
temp_dir = tempfile.TemporaryDirectory()
path = create_temp_tutorial_file(body.tutorial_id, temp_dir)
diff --git a/marimo/_server/api/endpoints/ws.py b/marimo/_server/api/endpoints/ws.py
index 9b5be03596..872b38890c 100644
--- a/marimo/_server/api/endpoints/ws.py
+++ b/marimo/_server/api/endpoints/ws.py
@@ -2,7 +2,6 @@
from __future__ import annotations
import asyncio
-import json
import sys
from typing import TYPE_CHECKING, Any, Callable, Optional
@@ -13,6 +12,7 @@ from marimo._ast.cell import CellConfig
from marimo._cli.upgrade import check_for_updates
from marimo._config.settings import GLOBAL_SETTINGS
from marimo._dependencies.dependencies import DependencyManager
+from marimo._messaging.msgspec_encoder import encode_json_bytes
from marimo._messaging.ops import (
Alert,
Banner,
@@ -22,10 +22,8 @@ from marimo._messaging.ops import (
KernelReady,
MessageOperation,
Reconnected,
- serialize,
)
from marimo._messaging.types import KernelMessage, NoopStream
-from marimo._plugins.core.json_encoder import WebComponentEncoder
from marimo._plugins.core.web_component import JSONType
from marimo._runtime.params import QueryParams
from marimo._server.api.deps import AppState
@@ -323,7 +321,7 @@ class WebsocketHandler(SessionConsumer):
self.message_queue.put_nowait(
(
KernelReady.name,
- serialize(
+ encode_json_bytes(
KernelReady(
codes=codes,
names=names,
@@ -618,14 +616,8 @@ class WebsocketHandler(SessionConsumer):
continue
try:
- text = json.dumps(
- {
- "op": op,
- "data": data,
- },
- cls=WebComponentEncoder,
- )
- except TypeError as e:
+ text = f'{{"op": "{op}", "data": {data.decode("utf-8")}}}'
+ except Exception as e:
# This is a deserialization error
LOGGER.error(
"Failed to send message to frontend: %s", str(e)
@@ -687,7 +679,7 @@ class WebsocketHandler(SessionConsumer):
return listener
def write_operation(self, op: MessageOperation) -> None:
- self.message_queue.put_nowait((op.name, serialize(op)))
+ self.message_queue.put_nowait((op.name, encode_json_bytes(op)))
def on_stop(self) -> None:
# Cancel the heartbeat task, reader
diff --git a/marimo/_server/errors.py b/marimo/_server/errors.py
index 2e0f4171a6..38e1728541 100644
--- a/marimo/_server/errors.py
+++ b/marimo/_server/errors.py
@@ -3,6 +3,7 @@ from __future__ import annotations
from typing import TYPE_CHECKING, Any
+import msgspec
from starlette.exceptions import HTTPException
from starlette.responses import JSONResponse
@@ -72,6 +73,8 @@ async def handle_error(request: Request, response: Any) -> Any:
return JSONResponse({"detail": str(response)}, status_code=500)
except Exception as e:
LOGGER.warning(f"Failed to send missing package alert: {e}")
+ if isinstance(response, msgspec.ValidationError):
+ return JSONResponse({"detail": str(response)}, status_code=400)
if isinstance(response, NotImplementedError):
return JSONResponse({"detail": "Not supported"}, status_code=501)
if isinstance(response, TypeError):
diff --git a/marimo/_server/export/__init__.py b/marimo/_server/export/__init__.py
index f18b6c00d1..fed3a90afb 100644
--- a/marimo/_server/export/__init__.py
+++ b/marimo/_server/export/__init__.py
@@ -5,7 +5,7 @@ import asyncio
import os
import sys
from dataclasses import dataclass
-from typing import TYPE_CHECKING, Any, Callable, Literal, Optional, cast
+from typing import TYPE_CHECKING, Callable, Literal, Optional, cast
from marimo import _loggers
from marimo._cli.print import echo
@@ -13,9 +13,9 @@ from marimo._config.config import RuntimeConfig
from marimo._config.manager import (
get_default_config_manager,
)
-from marimo._messaging.cell_output import CellChannel
+from marimo._messaging.cell_output import CellChannel, CellOutput
from marimo._messaging.errors import Error, is_unexpected_error
-from marimo._messaging.ops import MessageOperation
+from marimo._messaging.ops import CellOp, MessageOperation
from marimo._messaging.types import KernelMessage
from marimo._output.hypertext import patch_html_for_non_interactive_output
from marimo._runtime.requests import AppMetadata, SerializedCLIArgs
@@ -246,33 +246,25 @@ async def run_app_until_completion(
self,
) -> Callable[[KernelMessage], None]:
def listener(message: KernelMessage) -> None:
+ op, data = message
# Print errors to stderr
- if message[0] == "cell-op":
- op_data = message[1]
- output = op_data.get("output")
- console_output = op_data.get("console")
- if (
- output
- and output["channel"] == CellChannel.MARIMO_ERROR
- ):
- errors = cast(list[Any], output["data"])
-
- @dataclass
- class Container:
- error: Error
-
+ if op == "cell-op":
+ op_data = parse_raw(data, CellOp)
+ output = op_data.output
+ console_output = op_data.console
+ if output and output.channel == CellChannel.MARIMO_ERROR:
+ errors = cast(list[Error], output.data)
for err in errors:
- parsed = parse_raw({"error": err}, Container)
# Not all errors are fatal
- if is_unexpected_error(parsed.error):
+ if is_unexpected_error(err):
echo(
- f"{parsed.error.__class__.__name__}: {parsed.error.describe()}",
+ f"{err.__class__.__name__}: {err.describe()}",
file=sys.stderr,
)
self.did_error = True
if console_output:
- console_as_list: list[dict[str, Any]] = (
+ console_as_list: list[CellOutput] = (
console_output
if isinstance(console_output, list)
else [console_output]
@@ -281,11 +273,9 @@ async def run_app_until_completion(
for line in console_as_list:
# We print to stderr to not interfere with the
# piped output
- mimetype = line.get("mimetype")
+ mimetype = line.mimetype
if mimetype == "text/plain":
- echo(
- line["data"], file=sys.stderr, nl=False
- )
+ echo(line.data, file=sys.stderr, nl=False)
except Exception:
LOGGER.warning("Error printing console output")
pass
diff --git a/marimo/_server/models/completion.py b/marimo/_server/models/completion.py
index cbc70875fb..990f0f6047 100644
--- a/marimo/_server/models/completion.py
+++ b/marimo/_server/models/completion.py
@@ -1,44 +1,42 @@
# Copyright 2024 Marimo. All rights reserved.
from __future__ import annotations
-from dataclasses import dataclass, field
from typing import Any, Literal, Optional, Union
+import msgspec
+
from marimo._ai._types import ChatMessage
-@dataclass
-class SchemaColumn:
+class SchemaColumn(msgspec.Struct, rename="camel"):
name: str
type: str
sample_values: list[Any]
-@dataclass
-class SchemaTable:
+class SchemaTable(msgspec.Struct, rename="camel"):
name: str
columns: list[SchemaColumn]
-@dataclass
-class VariableContext:
+class VariableContext(msgspec.Struct, rename="camel"):
name: str
value_type: str
preview_value: Any
-@dataclass
-class AiCompletionContext:
- schema: list[SchemaTable] = field(default_factory=list)
- variables: list[Union[VariableContext, str]] = field(default_factory=list)
+class AiCompletionContext(msgspec.Struct, rename="camel"):
+ schema: list[SchemaTable] = msgspec.field(default_factory=list)
+ variables: list[Union[VariableContext, str]] = msgspec.field(
+ default_factory=list
+ )
plain_text: str = ""
Language = Literal["python", "markdown", "sql"]
-@dataclass
-class AiCompletionRequest:
+class AiCompletionRequest(msgspec.Struct, rename="camel"):
prompt: str
include_other_code: str
code: str
@@ -47,15 +45,13 @@ class AiCompletionRequest:
language: Language = "python"
-@dataclass
-class AiInlineCompletionRequest:
+class AiInlineCompletionRequest(msgspec.Struct, rename="camel"):
prefix: str
suffix: str
language: Language = "python"
-@dataclass
-class ChatRequest:
+class ChatRequest(msgspec.Struct, rename="camel"):
context: AiCompletionContext
include_other_code: str
messages: list[ChatMessage]
diff --git a/marimo/_server/models/export.py b/marimo/_server/models/export.py
index b1a4eb2b64..4e4af4a705 100644
--- a/marimo/_server/models/export.py
+++ b/marimo/_server/models/export.py
@@ -1,28 +1,25 @@
# Copyright 2024 Marimo. All rights reserved.
from __future__ import annotations
-from dataclasses import dataclass
from typing import Optional
+import msgspec
-@dataclass
-class ExportAsHTMLRequest:
+
+class ExportAsHTMLRequest(msgspec.Struct, rename="camel"):
download: bool
files: list[str]
include_code: bool
asset_url: Optional[str] = None
-@dataclass
-class ExportAsScriptRequest:
+class ExportAsScriptRequest(msgspec.Struct, rename="camel"):
download: bool
-@dataclass
-class ExportAsIPYNBRequest:
+class ExportAsIPYNBRequest(msgspec.Struct, rename="camel"):
download: bool
-@dataclass
-class ExportAsMarkdownRequest:
+class ExportAsMarkdownRequest(msgspec.Struct, rename="camel"):
download: bool
diff --git a/marimo/_server/models/files.py b/marimo/_server/models/files.py
index 130deaea17..6f81a190fc 100644
--- a/marimo/_server/models/files.py
+++ b/marimo/_server/models/files.py
@@ -1,50 +1,45 @@
# Copyright 2024 Marimo. All rights reserved.
from __future__ import annotations
-from dataclasses import dataclass, field
from typing import Literal, Optional
+import msgspec
+
from marimo._server.models.models import BaseResponse
-@dataclass
-class FileInfo:
+class FileInfo(msgspec.Struct, rename="camel"):
id: str
path: str
name: str
is_directory: bool
is_marimo_file: bool
last_modified: Optional[float] = None
- children: list[FileInfo] = field(default_factory=list)
+ children: list[FileInfo] = msgspec.field(default_factory=list)
-@dataclass
-class FileListRequest:
+class FileListRequest(msgspec.Struct, rename="camel"):
# The directory path to list files from
# If None, the root directory will be used
path: Optional[str] = None
-@dataclass
-class FileDetailsRequest:
+class FileDetailsRequest(msgspec.Struct, rename="camel"):
# The path of the file or directory
path: str
-@dataclass
-class FileOpenRequest:
+class FileOpenRequest(msgspec.Struct, rename="camel"):
# The path of the file to open
path: str
-@dataclass
-class FileTreeRequest:
+class FileTreeRequest(msgspec.Struct, rename="camel"):
# The root directory path for the tree
path: str
-@dataclass
-class FileCreateRequest:
+class FileCreateRequest(msgspec.Struct, rename="camel"):
# The path where to create the file or directory
path: str
# 'file' or 'directory'
@@ -55,62 +50,53 @@ class FileCreateRequest:
contents: Optional[str] = None
-@dataclass
-class FileDeleteRequest:
+class FileDeleteRequest(msgspec.Struct, rename="camel"):
# The path of the file or directory to delete
path: str
-@dataclass
-class FileMoveRequest:
+class FileMoveRequest(msgspec.Struct, rename="camel"):
# The current path of the file or directory
path: str
# The new path or name for the file or directory
new_path: str
-@dataclass
-class FileUpdateRequest:
+class FileUpdateRequest(msgspec.Struct, rename="camel"):
# The current path of the file or directory
path: str
# The new contents of the file
contents: str
-@dataclass
-class FileListResponse:
+class FileListResponse(msgspec.Struct, rename="camel"):
files: list[FileInfo]
root: str
-@dataclass
-class FileDetailsResponse:
+class FileDetailsResponse(msgspec.Struct, rename="camel"):
file: FileInfo
contents: Optional[str] = None
mime_type: Optional[str] = None
-@dataclass
class FileCreateResponse(BaseResponse):
# Additional information, e.g., error message
message: Optional[str] = None
info: Optional[FileInfo] = None
-@dataclass
class FileDeleteResponse(BaseResponse):
# Additional information, e.g., error message
message: Optional[str] = None
-@dataclass
class FileUpdateResponse(BaseResponse):
# Additional information, e.g., error message
message: Optional[str] = None
info: Optional[FileInfo] = None
-@dataclass
class FileMoveResponse(BaseResponse):
# Additional information, e.g., error message
message: Optional[str] = None
diff --git a/marimo/_server/models/home.py b/marimo/_server/models/home.py
index 6ff0fb3d53..6f440bf47e 100644
--- a/marimo/_server/models/home.py
+++ b/marimo/_server/models/home.py
@@ -1,16 +1,16 @@
# Copyright 2024 Marimo. All rights reserved.
from __future__ import annotations
-from dataclasses import dataclass
from typing import Optional
+import msgspec
+
from marimo._server.models.files import FileInfo
from marimo._tutorials import Tutorial # type: ignore
from marimo._types.ids import SessionId
-@dataclass
-class MarimoFile:
+class MarimoFile(msgspec.Struct, rename="camel"):
# Name of the file
name: str
# Absolute path to the file
@@ -24,32 +24,26 @@ class MarimoFile:
initialization_id: Optional[str] = None
-@dataclass
-class RecentFilesResponse:
+class RecentFilesResponse(msgspec.Struct, rename="camel"):
files: list[MarimoFile]
-@dataclass
-class RunningNotebooksResponse:
+class RunningNotebooksResponse(msgspec.Struct, rename="camel"):
files: list[MarimoFile]
-@dataclass
-class OpenTutorialRequest:
+class OpenTutorialRequest(msgspec.Struct, rename="camel"):
tutorial_id: Tutorial
-@dataclass
-class WorkspaceFilesRequest:
+class WorkspaceFilesRequest(msgspec.Struct, rename="camel"):
include_markdown: bool = False
-@dataclass
-class WorkspaceFilesResponse:
+class WorkspaceFilesResponse(msgspec.Struct, rename="camel"):
root: str
files: list[FileInfo]
-@dataclass
-class ShutdownSessionRequest:
+class ShutdownSessionRequest(msgspec.Struct, rename="camel"):
session_id: SessionId
diff --git a/marimo/_server/models/models.py b/marimo/_server/models/models.py
index 32a6ae1d0e..bd0857dc8e 100644
--- a/marimo/_server/models/models.py
+++ b/marimo/_server/models/models.py
@@ -1,24 +1,21 @@
# Copyright 2024 Marimo. All rights reserved.
from __future__ import annotations
-import dataclasses
import os
-from dataclasses import dataclass
from typing import Any, Optional
+import msgspec
+
from marimo._ast.cell import CellConfig
-from marimo._config.config import MarimoConfig
from marimo._runtime.requests import (
ExecuteMultipleRequest,
HTTPRequest,
RenameRequest,
)
from marimo._types.ids import CellId_t, UIElementId
-from marimo._utils.case import deep_to_camel_case
-@dataclass
-class UpdateComponentValuesRequest:
+class UpdateComponentValuesRequest(msgspec.Struct, rename="camel"):
object_ids: list[UIElementId]
values: list[Any]
@@ -34,56 +31,44 @@ class UpdateComponentValuesRequest:
)
-@dataclass
class InstantiateRequest(UpdateComponentValuesRequest):
auto_run: bool = True
-@dataclass
-class BaseResponse:
+class BaseResponse(msgspec.Struct, rename="camel"):
success: bool
- def as_camel_case(self) -> dict[str, Any]:
- return deep_to_camel_case(dataclasses.asdict(self))
-
-@dataclass
class SuccessResponse(BaseResponse):
success: bool = True
-@dataclass
class ErrorResponse(BaseResponse):
success: bool = False
message: Optional[str] = None
-@dataclass
-class FormatRequest:
+class FormatRequest(msgspec.Struct, rename="camel"):
codes: dict[CellId_t, str]
line_length: int
-@dataclass
-class FormatResponse:
+class FormatResponse(msgspec.Struct, rename="camel"):
codes: dict[CellId_t, str]
-@dataclass
-class ReadCodeResponse:
+class ReadCodeResponse(msgspec.Struct, rename="camel"):
contents: str
-@dataclass
-class RenameFileRequest:
+class RenameFileRequest(msgspec.Struct, rename="camel"):
filename: str
def as_execution_request(self) -> RenameRequest:
return RenameRequest(filename=os.path.abspath(self.filename))
-@dataclass
-class RunRequest:
+class RunRequest(msgspec.Struct, rename="camel"):
# ids of cells to run
cell_ids: list[CellId_t]
# code to register/run for each cell
@@ -105,8 +90,7 @@ class RunRequest:
)
-@dataclass
-class SaveNotebookRequest:
+class SaveNotebookRequest(msgspec.Struct, rename="camel"):
# id of each cell
cell_ids: list[CellId_t]
# code for each cell
@@ -135,8 +119,7 @@ class SaveNotebookRequest:
)
-@dataclass
-class CopyNotebookRequest:
+class CopyNotebookRequest(msgspec.Struct, rename="camel"):
# path to app
source: str
destination: str
@@ -155,30 +138,25 @@ class CopyNotebookRequest:
)
-@dataclass
-class SaveAppConfigurationRequest:
+class SaveAppConfigurationRequest(msgspec.Struct, rename="camel"):
# partial app config
config: dict[str, Any]
-@dataclass
-class SaveUserConfigurationRequest:
- # user configuration
- config: MarimoConfig
+class SaveUserConfigurationRequest(msgspec.Struct, rename="camel"):
+ # deep partial user configuration
+ config: dict[str, Any]
-@dataclass
-class StdinRequest:
+class StdinRequest(msgspec.Struct, rename="camel"):
text: str
-@dataclass
-class InvokeAiToolRequest:
+class InvokeAiToolRequest(msgspec.Struct, rename="camel"):
tool_name: str
arguments: dict[str, Any]
-@dataclass
class InvokeAiToolResponse(BaseResponse):
tool_name: str
result: Any
diff --git a/marimo/_server/models/packages.py b/marimo/_server/models/packages.py
index 62ffc717cd..4193379426 100644
--- a/marimo/_server/models/packages.py
+++ b/marimo/_server/models/packages.py
@@ -1,14 +1,14 @@
# Copyright 2024 Marimo. All rights reserved.
from __future__ import annotations
-from dataclasses import dataclass
from typing import Optional
+import msgspec
+
from marimo._runtime.packages.package_manager import PackageDescription
-@dataclass
-class AddPackageRequest:
+class AddPackageRequest(msgspec.Struct, rename="camel"):
"""
This can be a remove package or a local package.
@@ -26,18 +26,15 @@ class AddPackageRequest:
upgrade: Optional[bool] = False
-@dataclass
-class RemovePackageRequest:
+class RemovePackageRequest(msgspec.Struct, rename="camel"):
package: str
-@dataclass
-class ListPackagesResponse:
+class ListPackagesResponse(msgspec.Struct, rename="camel"):
packages: list[PackageDescription]
-@dataclass
-class DependencyTreeNode:
+class DependencyTreeNode(msgspec.Struct, rename="camel"):
name: str
version: Optional[str]
# List of {"kind": "extra"|"group", "value": str}
@@ -45,13 +42,11 @@ class DependencyTreeNode:
dependencies: list[DependencyTreeNode]
-@dataclass
-class DependencyTreeResponse:
+class DependencyTreeResponse(msgspec.Struct, rename="camel"):
tree: Optional[DependencyTreeNode]
-@dataclass
-class PackageOperationResponse:
+class PackageOperationResponse(msgspec.Struct, rename="camel"):
success: bool
error: Optional[str] = None
diff --git a/marimo/_server/models/secrets.py b/marimo/_server/models/secrets.py
index c95279366b..e89476c03b 100644
--- a/marimo/_server/models/secrets.py
+++ b/marimo/_server/models/secrets.py
@@ -1,18 +1,16 @@
# Copyright 2025 Marimo. All rights reserved.
from __future__ import annotations
-from dataclasses import dataclass
+import msgspec
from marimo._secrets.models import SecretKeysWithProvider, SecretProviderType
-@dataclass
-class ListSecretKeysResponse:
+class ListSecretKeysResponse(msgspec.Struct, rename="camel"):
keys: list[SecretKeysWithProvider]
-@dataclass
-class CreateSecretRequest:
+class CreateSecretRequest(msgspec.Struct, rename="camel"):
key: str
value: str
provider: SecretProviderType
@@ -26,8 +24,7 @@ class CreateSecretRequest:
raise ValueError("Key cannot contain spaces or whitespace")
-@dataclass
-class DeleteSecretRequest:
+class DeleteSecretRequest(msgspec.Struct, rename="camel"):
key: str
def __post_init__(self) -> None:
diff --git a/marimo/_server/responses.py b/marimo/_server/responses.py
new file mode 100644
index 0000000000..5937ec548c
--- /dev/null
+++ b/marimo/_server/responses.py
@@ -0,0 +1,12 @@
+# Copyright 2025 Marimo. All rights reserved.
+import msgspec
+import starlette.responses
+
+from marimo._messaging.msgspec_encoder import encode_json_bytes
+
+
+class StructResponse(starlette.responses.Response):
+ media_type = "application/json"
+
+ def __init__(self, struct: msgspec.Struct) -> None:
+ super().__init__(content=encode_json_bytes(struct))
diff --git a/marimo/_server/router.py b/marimo/_server/router.py
index ae5848bdc4..37c5604d44 100644
--- a/marimo/_server/router.py
+++ b/marimo/_server/router.py
@@ -1,25 +1,18 @@
# Copyright 2024 Marimo. All rights reserved.
from __future__ import annotations
-import dataclasses
-import json
from asyncio import iscoroutine
from dataclasses import dataclass
from typing import TYPE_CHECKING, Any, Callable, Optional, TypeVar
from starlette.responses import (
FileResponse,
- HTMLResponse,
- JSONResponse,
- PlainTextResponse,
- RedirectResponse,
Response,
- StreamingResponse,
)
from starlette.routing import Mount, Router
from marimo import _loggers
-from marimo._utils.case import deep_to_camel_case
+from marimo._server.responses import StructResponse
if TYPE_CHECKING:
from starlette.requests import Request
@@ -54,31 +47,13 @@ class APIRouter(Router):
response = await func(request=request)
if isinstance(response, FileResponse):
return response
- if isinstance(response, StreamingResponse):
- return response
- if isinstance(response, HTMLResponse):
- return response
- if isinstance(response, PlainTextResponse):
- return response
- if isinstance(response, RedirectResponse):
- return response
- if isinstance(response, JSONResponse):
+
+ # If we already have a response, just return it
+ if isinstance(response, Response):
return response
- if dataclasses.is_dataclass(response):
- # Handle both dataclass instance and dataclass type
- if isinstance(response, type):
- # If it's a type, we can't call asdict on it
- return JSONResponse(content=deep_to_camel_case({}))
- else:
- # If it's an instance, we can call asdict
- return JSONResponse(
- content=deep_to_camel_case(
- dataclasses.asdict(response)
- )
- )
-
- return JSONResponse(content=json.dumps(response))
+ # Otherwise it's one of our structs that we need to encode
+ return StructResponse(response)
# Set docstring of wrapper_func to the docstring of func
wrapper_func.__doc__ = func.__doc__
@@ -106,31 +81,13 @@ class APIRouter(Router):
response = func(request=request)
if iscoroutine(response):
response = await response
- if isinstance(response, FileResponse):
- return response
- if isinstance(response, StreamingResponse):
- return response
- if isinstance(response, PlainTextResponse):
- return response
- if isinstance(response, RedirectResponse):
- return response
- if isinstance(response, HTMLResponse):
+
+ # If we already have a response, just return it
+ if isinstance(response, Response):
return response
- if dataclasses.is_dataclass(response):
- # Handle both dataclass instance and dataclass type
- if isinstance(response, type):
- # If it's a type, we can't call asdict on it
- return JSONResponse(content=deep_to_camel_case({}))
- else:
- # If it's an instance, we can call asdict
- return JSONResponse(
- content=deep_to_camel_case(
- dataclasses.asdict(response)
- )
- )
-
- return response # type: ignore[no-any-return]
+ # Otherwise it's one of our structs that we need to encode
+ return StructResponse(response)
# Set docstring of wrapper_func to the docstring of func
wrapper_func.__doc__ = func.__doc__
diff --git a/marimo/_server/session/serialize.py b/marimo/_server/session/serialize.py
index 85b7f83135..27d737ec6b 100644
--- a/marimo/_server/session/serialize.py
+++ b/marimo/_server/session/serialize.py
@@ -15,8 +15,10 @@ from marimo._messaging.cell_output import CellChannel, CellOutput
from marimo._messaging.errors import (
Error as MarimoError,
MarimoExceptionRaisedError,
+ UnknownError,
)
from marimo._messaging.mimetypes import KnownMimeType
+from marimo._messaging.msgspec_encoder import asdict
from marimo._messaging.ops import CellOp
from marimo._schemas.notebook import (
NotebookCell,
@@ -59,9 +61,16 @@ def _normalize_error(error: Union[MarimoError, dict[str, Any]]) -> ErrorOutput:
traceback=error.get("traceback", []),
)
else:
+ if isinstance(error, UnknownError) and error.error_type:
+ # UnknownError with custom error_type field
+ ename = error.error_type
+ else:
+ # For msgspec structs with tagged unions, the type is in the serialized form
+ ename = asdict(error).get("type", "UnknownError")
+
return ErrorOutput(
type="error",
- ename=error.type,
+ ename=ename,
evalue=error.describe(),
traceback=getattr(error, "traceback", []),
)
@@ -177,7 +186,6 @@ def deserialize_session(session: NotebookSessionV1) -> SessionView:
CellOutput.errors(
[
MarimoExceptionRaisedError(
- type="exception",
exception_type=output["ename"],
msg=output["evalue"],
raising_cell=None,
diff --git a/marimo/_server/session/session_view.py b/marimo/_server/session/session_view.py
index 1bd21a783d..412020951c 100644
--- a/marimo/_server/session/session_view.py
+++ b/marimo/_server/session/session_view.py
@@ -106,15 +106,8 @@ class SessionView:
def add_raw_operation(self, raw_operation: Any) -> None:
self._touch()
-
- # parse_raw only accepts a dataclass, so we wrap MessageOperation in a
- # dataclass.
- @dataclass
- class _Container:
- operation: MessageOperation
-
- operation = parse_raw({"operation": raw_operation}, _Container)
- self.add_operation(operation.operation)
+ # Type ignore because MessageOperation is a Union, not a class
+ self.add_operation(parse_raw(raw_operation, cls=MessageOperation)) # type: ignore[arg-type]
def add_control_request(self, request: ControlRequest) -> None:
self._touch()
diff --git a/marimo/_snippets/snippets.py b/marimo/_snippets/snippets.py
index 15eac28056..e995be0de0 100644
--- a/marimo/_snippets/snippets.py
+++ b/marimo/_snippets/snippets.py
@@ -2,10 +2,11 @@
from __future__ import annotations
from collections.abc import Awaitable, Generator
-from dataclasses import dataclass
from pathlib import Path
from typing import Any, Optional
+import msgspec
+
from marimo import _loggers
from marimo._ast.load import load_app
from marimo._config.manager import get_default_config_manager
@@ -14,21 +15,18 @@ from marimo._utils.paths import marimo_package_path
LOGGER = _loggers.marimo_logger()
-@dataclass
-class SnippetSection:
+class SnippetSection(msgspec.Struct, rename="camel"):
id: str
html: Optional[str] = None
code: Optional[str] = None
-@dataclass
-class Snippet:
+class Snippet(msgspec.Struct, rename="camel"):
title: str
sections: list[SnippetSection]
-@dataclass
-class Snippets:
+class Snippets(msgspec.Struct, rename="camel"):
snippets: list[Snippet]
diff --git a/marimo/_sql/get_engines.py b/marimo/_sql/get_engines.py
index 9b2bdb21ea..db9d3fba68 100644
--- a/marimo/_sql/get_engines.py
+++ b/marimo/_sql/get_engines.py
@@ -80,6 +80,7 @@ def engine_to_data_source_connection(
dialect=engine.dialect,
name=variable_name,
display_name=variable_name,
+ databases=[],
)
try:
diff --git a/marimo/_utils/dataclass_to_openapi.py b/marimo/_utils/dataclass_to_openapi.py
index 27b426be19..faac7dd4b6 100644
--- a/marimo/_utils/dataclass_to_openapi.py
+++ b/marimo/_utils/dataclass_to_openapi.py
@@ -28,6 +28,9 @@ else:
from typing import Sequence # noqa: UP035
+import msgspec
+import msgspec.json
+
class PythonTypeToOpenAPI:
def __init__(self, name_overrides: dict[Any, str], camel_case: bool):
@@ -48,6 +51,9 @@ class PythonTypeToOpenAPI:
Returns:
Dict[str, Any]: The OpenAPI schema.
"""
+ if type(py_type) is type(msgspec.Struct):
+ return msgspec.json.schema(py_type)["$defs"][py_type.__name__] # type: ignore[no-any-return]
+
origin = get_origin(py_type)
optional_name_overrides = self.optional_name_overrides
diff --git a/marimo/_utils/parse_dataclass.py b/marimo/_utils/parse_dataclass.py
index c3799a5731..dd3058648e 100644
--- a/marimo/_utils/parse_dataclass.py
+++ b/marimo/_utils/parse_dataclass.py
@@ -12,11 +12,15 @@ from typing import (
Optional,
TypeVar,
Union,
+ cast,
get_args,
get_origin,
get_type_hints,
)
+import msgspec
+import msgspec.json
+
# Import NotRequired from typing_extensions for Python < 3.11
if sys.version_info < (3, 11):
from typing_extensions import NotRequired
@@ -191,7 +195,7 @@ class DataclassParser:
def parse_raw(
- message: Union[bytes, dict[Any, Any]],
+ message: Union[bytes, str, dict[Any, Any]],
cls: type[T],
allow_unknown_keys: bool = False,
) -> T:
@@ -213,11 +217,28 @@ def parse_raw(
Transforms all fields in the parsed JSON from camel case to snake case.
"""
- # If it is a dict, it is already parsed and we can just build the
- # dataclass.
- if isinstance(message, dict):
- return DataclassParser(allow_unknown_keys).build_dataclass(
- message, cls
+ # Previous behavior (before using msgspec). Our DataClassParser handles
+ # non-discrimated unions, unlike msgspec, so we use dataclasses for non-discrimated
+ # union types. We could move off if we changed the over-the-wire types to have
+ # a tag, but that would require updating the front end.
+ if dataclasses.is_dataclass(cls):
+ if isinstance(message, dict):
+ return cast(
+ "T",
+ DataclassParser(allow_unknown_keys).build_dataclass(
+ message, cls
+ ),
+ )
+ parsed = json.loads(message)
+ return cast(
+ "T",
+ DataclassParser(allow_unknown_keys).build_dataclass(parsed, cls),
)
- parsed = json.loads(message)
- return DataclassParser(allow_unknown_keys).build_dataclass(parsed, cls)
+
+ # If it is a dict, it is already parsed and we can just build the dataclass.
+ if isinstance(message, dict):
+ return msgspec.convert(message, type=cls)
+
+ return msgspec.json.decode(
+ message, strict=not allow_unknown_keys, type=cls
+ )
diff --git a/marimo/_utils/toml.py b/marimo/_utils/toml.py
index df68317eb6..7e5c38da99 100644
--- a/marimo/_utils/toml.py
+++ b/marimo/_utils/toml.py
@@ -17,7 +17,8 @@ def read_toml(file_path: Union[str, Path]) -> dict[str, Any]:
import tomlkit
with open(file_path, "rb") as file:
- return tomlkit.load(file)
+ # Use unwrap() to convert tomlkit types to Python built-ins
+ return tomlkit.load(file).unwrap()
else:
import tomllib
@@ -32,7 +33,8 @@ def read_toml_string(s: str) -> dict[str, Any]:
if DependencyManager.tomlkit.has():
import tomlkit
- return tomlkit.loads(s)
+ # Use unwrap() to convert tomlkit types to Python built-ins
+ return tomlkit.loads(s).unwrap()
else:
import tomllib
diff --git a/packages/openapi/api.yaml b/packages/openapi/api.yaml
index c72a48228f..291615a76c 100644
--- a/packages/openapi/api.yaml
+++ b/packages/openapi/api.yaml
@@ -1,61 +1,95 @@
components:
schemas:
AddPackageRequest:
+ description: 'This can be a remove package or a local package.
+
+
+ Supported formats:
+
+
+ httpx
+
+ httpx==0.27.0
+
+ httpx>=0.27.0
+
+ git+https://github.com/encode/httpx
+
+ https://files.pythonhosted.org/packages/5c/2d/3da5bdf4408b8b2800061c339f240c1802f2e82d55e50bd39c5a881f47f0/httpx-0.27.0.tar.gz
+
+ /example/foo-0.1.0-py3-none-any.whl'
properties:
package:
type: string
upgrade:
- nullable: true
- type: boolean
+ anyOf:
+ - type: boolean
+ - type: 'null'
+ default: false
required:
- package
+ title: AddPackageRequest
type: object
AiCompletionContext:
properties:
plainText:
+ default: ''
type: string
schema:
+ default: []
items:
$ref: '#/components/schemas/SchemaTable'
type: array
variables:
+ default: []
items:
- oneOf:
- - $ref: '#/components/schemas/VariableContext'
+ anyOf:
- type: string
+ - $ref: '#/components/schemas/VariableContext'
type: array
- required:
- - schema
- - variables
- - plainText
+ required: []
+ title: AiCompletionContext
type: object
AiCompletionRequest:
properties:
code:
type: string
context:
- $ref: '#/components/schemas/AiCompletionContext'
- nullable: true
+ anyOf:
+ - type: 'null'
+ - $ref: '#/components/schemas/AiCompletionContext'
+ default: null
includeOtherCode:
type: string
language:
+ default: python
enum:
- - python
- markdown
+ - python
- sql
- type: string
prompt:
type: string
selectedText:
- nullable: true
- type: string
+ anyOf:
+ - type: string
+ - type: 'null'
+ default: null
required:
- prompt
- includeOtherCode
- code
- - language
+ title: AiCompletionRequest
type: object
AiConfig:
+ description: "Configuration options for AI.\n\n **Keys.**\n\n - `rules`:\
+ \ custom rules to include in all AI completion prompts\n - `max_tokens`:\
+ \ the maximum number of tokens to use in AI completions\n - `mode`: the\
+ \ mode to use for AI completions. Can be one of: `\"ask\"` or `\"manual\"\
+ `\n - `models`: the models to use for AI completions\n - `open_ai`:\
+ \ the OpenAI config\n - `anthropic`: the Anthropic config\n - `google`:\
+ \ the Google AI config\n - `bedrock`: the Bedrock config\n - `azure`:\
+ \ the Azure config\n - `ollama`: the Ollama config\n - `github`: the\
+ \ GitHub config\n - `open_ai_compatible`: the OpenAI-compatible config"
properties:
anthropic:
$ref: '#/components/schemas/AnthropicConfig'
@@ -73,27 +107,8 @@ components:
enum:
- ask
- manual
- type: string
models:
- properties:
- autocomplete_model:
- type: string
- chat_model:
- type: string
- custom_models:
- items:
- type: string
- type: array
- displayed_models:
- items:
- type: string
- type: array
- edit_model:
- type: string
- required:
- - displayed_models
- - custom_models
- type: object
+ $ref: '#/components/schemas/AiModelConfig'
ollama:
$ref: '#/components/schemas/OpenAiConfig'
open_ai:
@@ -102,15 +117,17 @@ components:
$ref: '#/components/schemas/OpenAiConfig'
rules:
type: string
+ required: []
+ title: AiConfig
type: object
AiInlineCompletionRequest:
properties:
language:
+ default: python
enum:
- - python
- markdown
+ - python
- sql
- type: string
prefix:
type: string
suffix:
@@ -118,57 +135,91 @@ components:
required:
- prefix
- suffix
- - language
+ title: AiInlineCompletionRequest
+ type: object
+ AiModelConfig:
+ description: "Configuration options for an AI model.\n\n **Keys.**\n\n \
+ \ - `chat_model`: the model to use for chat completions\n - `edit_model`:\
+ \ the model to use for edit completions\n - `autocomplete_model`: the model\
+ \ to use for code completion/autocomplete\n - `displayed_models`: a list\
+ \ of models to display in the UI\n - `custom_models`: a list of custom\
+ \ models to use that are not from the default list"
+ properties:
+ autocomplete_model:
+ type: string
+ chat_model:
+ type: string
+ custom_models:
+ items:
+ type: string
+ type: array
+ displayed_models:
+ items:
+ type: string
+ type: array
+ edit_model:
+ type: string
+ required:
+ - custom_models
+ - displayed_models
+ title: AiModelConfig
type: object
Alert:
properties:
description:
type: string
- name:
+ op:
enum:
- alert
- type: string
title:
type: string
variant:
- enum:
- - danger
- nullable: true
- type: string
+ anyOf:
+ - enum:
+ - danger
+ - type: 'null'
+ default: null
required:
+ - op
- title
- description
- - name
+ title: Alert
type: object
AnthropicConfig:
+ description: "Configuration options for Anthropic.\n\n **Keys.**\n\n -\
+ \ `api_key`: the Anthropic API key"
properties:
api_key:
type: string
+ required: []
+ title: AnthropicConfig
type: object
Banner:
properties:
action:
- enum:
- - restart
- nullable: true
- type: string
+ anyOf:
+ - enum:
+ - restart
+ - type: 'null'
+ default: null
description:
type: string
- name:
+ op:
enum:
- banner
- type: string
title:
type: string
variant:
- enum:
- - danger
- nullable: true
- type: string
+ anyOf:
+ - enum:
+ - danger
+ - type: 'null'
+ default: null
required:
+ - op
- title
- description
- - name
+ title: Banner
type: object
BaseResponse:
properties:
@@ -176,8 +227,26 @@ components:
type: boolean
required:
- success
+ title: BaseResponse
+ type: object
+ BasedpyrightServerConfig:
+ description: 'Configuration options for basedpyright Language Server.
+
+
+ basedpyright handles completion, hover, go-to-definition, and diagnostics,
+
+ but we only use it for diagnostics.'
+ properties:
+ enabled:
+ type: boolean
+ required: []
+ title: BasedpyrightServerConfig
type: object
BedrockConfig:
+ description: "Configuration options for Bedrock.\n\n **Keys.**\n\n - `profile_name`:\
+ \ the AWS profile to use\n - `region_name`: the AWS region to use\n \
+ \ - `aws_access_key_id`: the AWS access key ID\n - `aws_secret_access_key`:\
+ \ the AWS secret access key"
properties:
aws_access_key_id:
type: string
@@ -187,88 +256,210 @@ components:
type: string
region_name:
type: string
+ required: []
+ title: BedrockConfig
type: object
CellChannel:
+ description: The channel of a cell's output.
enum:
- - stdout
- - stderr
- - stdin
- - pdb
- - output
- marimo-error
- media
- type: string
+ - output
+ - pdb
+ - stderr
+ - stdin
+ - stdout
+ title: CellChannel
CellConfig:
+ description: 'Internal representation of a cell''s configuration.
+
+ This is not part of the public API.'
properties:
column:
- nullable: true
- type: integer
+ anyOf:
+ - type: integer
+ - type: 'null'
+ default: null
disabled:
+ default: false
type: boolean
hide_code:
+ default: false
type: boolean
- required:
- - disabled
- - hide_code
+ required: []
+ title: CellConfig
type: object
CellOp:
+ description: "Op to transition a cell.\n\n A CellOp's data has some optional\
+ \ fields:\n\n output - a CellOutput\n console - a CellOutput\
+ \ (console msg to append), or a list of\n CellOutputs\n\
+ \ status - execution status\n stale_inputs - whether the cell\
+ \ has stale inputs (variables, modules, ...)\n run_id - the run\
+ \ associated with this cell.\n serialization - the serialization status\
+ \ of the cell\n\n Omitting a field means that its value should be unchanged!\n\
+ \n And one required field:\n\n cell_id - the cell id"
properties:
cell_id:
type: string
console:
- nullable: true
- oneOf:
- - $ref: '#/components/schemas/CellOutput'
+ anyOf:
- items:
$ref: '#/components/schemas/CellOutput'
type: array
- name:
+ - type: 'null'
+ - $ref: '#/components/schemas/CellOutput'
+ default: null
+ op:
enum:
- cell-op
- type: string
output:
- $ref: '#/components/schemas/CellOutput'
- nullable: true
+ anyOf:
+ - type: 'null'
+ - $ref: '#/components/schemas/CellOutput'
+ default: null
run_id:
- nullable: true
- type: string
+ anyOf:
+ - type: string
+ - type: 'null'
+ default: null
serialization:
- nullable: true
- type: string
+ anyOf:
+ - type: string
+ - type: 'null'
+ default: null
stale_inputs:
- nullable: true
- type: boolean
+ anyOf:
+ - type: boolean
+ - type: 'null'
+ default: null
status:
- $ref: '#/components/schemas/RuntimeState'
- nullable: true
+ anyOf:
+ - enum:
+ - disabled-transitively
+ - idle
+ - queued
+ - running
+ - type: 'null'
+ default: null
timestamp:
type: number
required:
+ - op
- cell_id
- - timestamp
- - name
+ title: CellOp
type: object
CellOutput:
properties:
channel:
$ref: '#/components/schemas/CellChannel'
data:
- oneOf:
+ anyOf:
- type: string
- items:
- $ref: '#/components/schemas/Error'
+ anyOf:
+ - $ref: '#/components/schemas/SetupRootError'
+ - $ref: '#/components/schemas/CycleError'
+ - $ref: '#/components/schemas/MultipleDefinitionError'
+ - $ref: '#/components/schemas/ImportStarError'
+ - $ref: '#/components/schemas/MarimoAncestorStoppedError'
+ - $ref: '#/components/schemas/MarimoAncestorPreventedError'
+ - $ref: '#/components/schemas/MarimoExceptionRaisedError'
+ - $ref: '#/components/schemas/MarimoStrictExecutionError'
+ - $ref: '#/components/schemas/MarimoInterruptionError'
+ - $ref: '#/components/schemas/MarimoSyntaxError'
+ - $ref: '#/components/schemas/MarimoInternalError'
+ - $ref: '#/components/schemas/UnknownError'
+ discriminator:
+ mapping:
+ ancestor-prevented: '#/components/schemas/MarimoAncestorPreventedError'
+ ancestor-stopped: '#/components/schemas/MarimoAncestorStoppedError'
+ cycle: '#/components/schemas/CycleError'
+ exception: '#/components/schemas/MarimoExceptionRaisedError'
+ import-star: '#/components/schemas/ImportStarError'
+ internal: '#/components/schemas/MarimoInternalError'
+ interruption: '#/components/schemas/MarimoInterruptionError'
+ multiple-defs: '#/components/schemas/MultipleDefinitionError'
+ setup-refs: '#/components/schemas/SetupRootError'
+ strict-exception: '#/components/schemas/MarimoStrictExecutionError'
+ syntax: '#/components/schemas/MarimoSyntaxError'
+ unknown: '#/components/schemas/UnknownError'
+ propertyName: type
type: array
- - additionalProperties: {}
- type: object
+ - type: object
mimetype:
- $ref: '#/components/schemas/MimeType'
+ enum:
+ - application/json
+ - application/vnd.jupyter.widget-view+json
+ - application/vnd.marimo+error
+ - application/vnd.marimo+mimebundle
+ - application/vnd.marimo+traceback
+ - application/vnd.vega.v5+json
+ - application/vnd.vegalite.v5+json
+ - image/avif
+ - image/bmp
+ - image/gif
+ - image/jpeg
+ - image/png
+ - image/svg+xml
+ - image/tiff
+ - text/csv
+ - text/html
+ - text/latex
+ - text/markdown
+ - text/plain
+ - video/mp4
+ - video/mpeg
timestamp:
type: number
required:
- channel
- mimetype
- data
- - timestamp
+ title: CellOutput
+ type: object
+ ChatAttachment:
+ properties:
+ content_type:
+ anyOf:
+ - type: string
+ - type: 'null'
+ default: null
+ name:
+ default: attachment
+ type: string
+ url:
+ type: string
+ required:
+ - url
+ title: ChatAttachment
+ type: object
+ ChatMessage:
+ description: A message in a chat.
+ properties:
+ attachments:
+ anyOf:
+ - items:
+ $ref: '#/components/schemas/ChatAttachment'
+ type: array
+ - type: 'null'
+ default: null
+ content: {}
+ parts:
+ anyOf:
+ - items:
+ type: object
+ type: array
+ - type: 'null'
+ default: null
+ role:
+ enum:
+ - assistant
+ - system
+ - user
+ required:
+ - role
+ - content
+ title: ChatMessage
type: object
ChatRequest:
properties:
@@ -278,129 +469,27 @@ components:
type: string
messages:
items:
- properties:
- attachments:
- items:
- properties:
- contentType:
- nullable: true
- type: string
- name:
- type: string
- url:
- type: string
- required:
- - url
- - name
- type: object
- nullable: true
- type: array
- content:
- additionalProperties: true
- type: object
- parts:
- items:
- oneOf:
- - properties:
- text:
- type: string
- type:
- enum:
- - text
- type: string
- required:
- - type
- - text
- type: object
- - properties:
- details:
- items:
- properties:
- signature:
- nullable: true
- type: string
- text:
- type: string
- type:
- enum:
- - text
- type: string
- required:
- - type
- - text
- type: object
- type: array
- reasoning:
- type: string
- type:
- enum:
- - reasoning
- type: string
- required:
- - type
- - reasoning
- - details
- type: object
- - properties:
- toolInvocation:
- properties:
- args:
- additionalProperties: {}
- type: object
- result: {}
- state:
- enum:
- - result
- type: string
- step:
- type: integer
- toolCallId:
- type: string
- toolName:
- type: string
- required:
- - state
- - result
- - toolCallId
- - toolName
- - step
- - args
- type: object
- type:
- enum:
- - tool-invocation
- type: string
- required:
- - type
- - toolInvocation
- type: object
- nullable: true
- type: array
- role:
- enum:
- - user
- - assistant
- - system
- type: string
- required:
- - role
- - content
- type: object
+ $ref: '#/components/schemas/ChatMessage'
type: array
model:
- nullable: true
- type: string
+ anyOf:
+ - type: string
+ - type: 'null'
+ default: null
variables:
- items:
- oneOf:
- - $ref: '#/components/schemas/VariableContext'
- - type: string
- nullable: true
- type: array
+ anyOf:
+ - items:
+ anyOf:
+ - type: string
+ - $ref: '#/components/schemas/VariableContext'
+ type: array
+ - type: 'null'
+ default: null
required:
- context
- includeOtherCode
- messages
+ title: ChatRequest
type: object
CodeCompletionRequest:
properties:
@@ -414,91 +503,168 @@ components:
- id
- document
- cellId
+ title: CodeCompletionRequest
type: object
ColumnStats:
+ description: Represents stats for a column in a data table.
properties:
'false':
- nullable: true
- type: integer
+ anyOf:
+ - type: integer
+ - type: 'null'
+ default: null
max:
- $ref: '#/components/schemas/NonNestedLiteral'
- nullable: true
+ anyOf:
+ - {}
+ - type: 'null'
+ default: null
mean:
- $ref: '#/components/schemas/NonNestedLiteral'
- nullable: true
+ anyOf:
+ - {}
+ - type: 'null'
+ default: null
median:
- $ref: '#/components/schemas/NonNestedLiteral'
- nullable: true
+ anyOf:
+ - {}
+ - type: 'null'
+ default: null
min:
- $ref: '#/components/schemas/NonNestedLiteral'
- nullable: true
+ anyOf:
+ - {}
+ - type: 'null'
+ default: null
nulls:
- nullable: true
- type: integer
+ anyOf:
+ - type: integer
+ - type: 'null'
+ default: null
p25:
- $ref: '#/components/schemas/NonNestedLiteral'
- nullable: true
+ anyOf:
+ - {}
+ - type: 'null'
+ default: null
p5:
- $ref: '#/components/schemas/NonNestedLiteral'
- nullable: true
+ anyOf:
+ - {}
+ - type: 'null'
+ default: null
p75:
- $ref: '#/components/schemas/NonNestedLiteral'
- nullable: true
+ anyOf:
+ - {}
+ - type: 'null'
+ default: null
p95:
- $ref: '#/components/schemas/NonNestedLiteral'
- nullable: true
+ anyOf:
+ - {}
+ - type: 'null'
+ default: null
std:
- $ref: '#/components/schemas/NonNestedLiteral'
- nullable: true
+ anyOf:
+ - {}
+ - type: 'null'
+ default: null
total:
- nullable: true
- type: integer
+ anyOf:
+ - type: integer
+ - type: 'null'
+ default: null
'true':
- nullable: true
- type: integer
+ anyOf:
+ - type: integer
+ - type: 'null'
+ default: null
unique:
- nullable: true
- type: integer
+ anyOf:
+ - type: integer
+ - type: 'null'
+ default: null
+ required: []
+ title: ColumnStats
type: object
CompletedRun:
+ description: Written on run completion (of submitted cells and their descendants.
properties:
- name:
+ op:
enum:
- completed-run
+ required:
+ - op
+ title: CompletedRun
+ type: object
+ CompletionConfig:
+ description: "Configuration for code completion.\n\n A dict with key/value\
+ \ pairs configuring code completion in the marimo\n editor.\n\n **Keys.**\n\
+ \n - `activate_on_typing`: if `False`, completion won't activate\n until\
+ \ the completion hotkey is entered\n - `copilot`: one of `\"github\"`,\
+ \ `\"codeium\"`, or `\"custom\"`\n - `codeium_api_key`: the Codeium API\
+ \ key"
+ properties:
+ activate_on_typing:
+ type: boolean
+ api_key:
+ anyOf:
+ - type: string
+ - type: 'null'
+ base_url:
+ anyOf:
+ - type: string
+ - type: 'null'
+ codeium_api_key:
+ anyOf:
+ - type: string
+ - type: 'null'
+ copilot:
+ anyOf:
+ - type: boolean
+ - enum:
+ - codeium
+ - custom
+ - github
+ model:
+ anyOf:
+ - type: string
+ - type: 'null'
+ required:
+ - activate_on_typing
+ - copilot
+ title: CompletionConfig
+ type: object
+ CompletionOption:
+ properties:
+ completion_info:
+ anyOf:
+ - type: string
+ - type: 'null'
+ name:
+ type: string
+ type:
type: string
required:
- name
+ - type
+ - completion_info
+ title: CompletionOption
type: object
CompletionResult:
+ description: Code completion result.
properties:
completion_id:
type: string
- name:
+ op:
enum:
- completion-result
- type: string
options:
items:
- properties:
- completion_info:
- nullable: true
- type: string
- name:
- type: string
- type:
- type: string
- required:
- - name
- - type
- type: object
+ $ref: '#/components/schemas/CompletionOption'
type: array
prefix_length:
type: integer
required:
+ - op
- completion_id
- prefix_length
- options
- - name
+ title: CompletionResult
type: object
CopyNotebookRequest:
properties:
@@ -509,6 +675,7 @@ components:
required:
- source
- destination
+ title: CopyNotebookRequest
type: object
CreateSecretRequest:
properties:
@@ -518,9 +685,8 @@ components:
type: string
provider:
enum:
- - env
- dotenv
- type: string
+ - env
value:
type: string
required:
@@ -528,11 +694,15 @@ components:
- value
- provider
- name
+ title: CreateSecretRequest
type: object
CycleError:
properties:
edges_with_vars:
items:
+ items: false
+ maxItems: 3
+ minItems: 3
prefixItems:
- type: string
- items:
@@ -544,81 +714,79 @@ components:
type:
enum:
- cycle
- type: string
required:
- - edges_with_vars
- type
+ - edges_with_vars
+ title: CycleError
type: object
DataColumnPreview:
+ description: Preview of a column in a dataset.
properties:
chart_code:
- nullable: true
- type: string
+ anyOf:
+ - type: string
+ - type: 'null'
+ default: null
chart_spec:
- nullable: true
- type: string
+ anyOf:
+ - type: string
+ - type: 'null'
+ default: null
column_name:
+ default: ''
type: string
error:
- nullable: true
- type: string
+ anyOf:
+ - type: string
+ - type: 'null'
+ default: null
missing_packages:
- items:
- type: string
- nullable: true
- type: array
- name:
+ anyOf:
+ - items:
+ type: string
+ type: array
+ - type: 'null'
+ default: null
+ op:
enum:
- data-column-preview
- type: string
stats:
- $ref: '#/components/schemas/ColumnStats'
- nullable: true
+ anyOf:
+ - type: 'null'
+ - $ref: '#/components/schemas/ColumnStats'
+ default: null
table_name:
+ default: ''
type: string
required:
- - table_name
- - column_name
- - name
+ - op
+ title: DataColumnPreview
type: object
DataSourceConnection:
+ description: "Represents a data source connection.\n\nAttributes:\n source\
+ \ (str): The source of the data source connection. E.g 'postgres'.\n dialect\
+ \ (str): The dialect of the data source connection. E.g 'postgresql'.\n \
+ \ name (str): The name of the data source connection. E.g 'engine'.\n \
+ \ display_name (str): The display name of the data source connection. E.g\
+ \ 'PostgresQL (engine)'.\n databases (List[Database]): The databases in\
+ \ the data source connection.\n default_database (Optional[str]): The default\
+ \ database in the data source connection.\n default_schema (Optional[str]):\
+ \ The default schema in the data source connection."
properties:
databases:
items:
- properties:
- dialect:
- type: string
- engine:
- nullable: true
- type: string
- name:
- type: string
- schemas:
- items:
- properties:
- name:
- type: string
- tables:
- items:
- $ref: '#/components/schemas/DataTable'
- type: array
- required:
- - name
- - tables
- type: object
- type: array
- required:
- - name
- - dialect
- - schemas
- type: object
+ $ref: '#/components/schemas/Database'
type: array
default_database:
- nullable: true
- type: string
+ anyOf:
+ - type: string
+ - type: 'null'
+ default: null
default_schema:
- nullable: true
- type: string
+ anyOf:
+ - type: string
+ - type: 'null'
+ default: null
dialect:
type: string
display_name:
@@ -633,6 +801,7 @@ components:
- name
- display_name
- databases
+ title: DataSourceConnection
type: object
DataSourceConnections:
properties:
@@ -640,100 +809,130 @@ components:
items:
$ref: '#/components/schemas/DataSourceConnection'
type: array
- name:
+ op:
enum:
- data-source-connections
- type: string
required:
+ - op
- connections
- - name
+ title: DataSourceConnections
type: object
DataTable:
+ description: "Represents a data table.\n\nAttributes:\n source_type (DataTableSource):\
+ \ Type of data source ('local', 'duckdb', 'connection').\n source (str):\
+ \ Can be dialect, or source db name.\n name (str): Name of the data table.\n\
+ \ num_rows (Optional[int]): Total number of rows in the table, if known.\n\
+ \ num_columns (Optional[int]): Total number of columns in the table, if\
+ \ known.\n variable_name (Optional[VariableName]): Variable name referencing\
+ \ this table in code.\n columns (List[DataTableColumn]): List of column\
+ \ definitions and metadata.\n engine (Optional[VariableName]): Database\
+ \ engine or connection handler, if any.\n type (DataTableType): Table type,\
+ \ either 'table' or 'view'. Defaults to 'table'.\n primary_keys (Optional[List[str]]):\
+ \ Column names used as primary keys, if any.\n indexes (Optional[List[str]]):\
+ \ Column names used as indexes, if any."
properties:
columns:
items:
$ref: '#/components/schemas/DataTableColumn'
type: array
engine:
- nullable: true
- type: string
+ anyOf:
+ - type: string
+ - type: 'null'
+ default: null
indexes:
- items:
- type: string
- nullable: true
- type: array
+ anyOf:
+ - items:
+ type: string
+ type: array
+ - type: 'null'
+ default: null
name:
type: string
num_columns:
- nullable: true
- type: integer
+ anyOf:
+ - type: integer
+ - type: 'null'
num_rows:
- nullable: true
- type: integer
+ anyOf:
+ - type: integer
+ - type: 'null'
primary_keys:
- items:
- type: string
- nullable: true
- type: array
+ anyOf:
+ - items:
+ type: string
+ type: array
+ - type: 'null'
+ default: null
source:
type: string
source_type:
enum:
- - local
- - duckdb
- - connection
- catalog
- type: string
+ - connection
+ - duckdb
+ - local
type:
+ default: table
enum:
- table
- view
- type: string
variable_name:
- nullable: true
- type: string
+ anyOf:
+ - type: string
+ - type: 'null'
required:
- source_type
- source
- name
+ - num_rows
+ - num_columns
+ - variable_name
- columns
- - type
+ title: DataTable
type: object
DataTableColumn:
+ description: "Represents a column in a data table.\n\nAttributes:\n name\
+ \ (str): The name of the column.\n type (DataType): The data type of the\
+ \ column.\n external_type (ExternalDataType): The raw data type of the\
+ \ column.\n sample_values (List[Any]): The sample values of the column."
properties:
external_type:
type: string
name:
type: string
sample_values:
- items: {}
type: array
type:
- $ref: '#/components/schemas/DataType'
+ enum:
+ - boolean
+ - date
+ - datetime
+ - integer
+ - number
+ - string
+ - time
+ - unknown
required:
- name
- type
- external_type
- sample_values
+ title: DataTableColumn
type: object
- DataType:
- enum:
- - string
- - boolean
- - integer
- - number
- - date
- - datetime
- - time
- - unknown
- type: string
Database:
+ description: "Represents a collection of schemas.\n\nAttributes:\n name (str):\
+ \ The name of the database\n dialect (str): The dialect of the database\n\
+ \ schemas (List[Schema]): List of schemas in the database\n engine (Optional[VariableName]):\
+ \ Database engine or connection handler, if any."
properties:
dialect:
type: string
engine:
- nullable: true
- type: string
+ anyOf:
+ - type: string
+ - type: 'null'
+ default: null
name:
type: string
schemas:
@@ -744,28 +943,56 @@ components:
- name
- dialect
- schemas
+ title: Database
type: object
Datasets:
+ description: List of datasets.
properties:
clear_channel:
- enum:
- - local
- - duckdb
- - connection
- - catalog
- nullable: true
- type: string
- name:
+ anyOf:
+ - enum:
+ - catalog
+ - connection
+ - duckdb
+ - local
+ - type: 'null'
+ default: null
+ op:
enum:
- datasets
- type: string
tables:
items:
$ref: '#/components/schemas/DataTable'
type: array
required:
+ - op
- tables
- - name
+ title: Datasets
+ type: object
+ DatasourcesConfig:
+ description: "Configuration for datasources panel.\n\n **Keys.**\n\n -\
+ \ `auto_discover_schemas`: if `True`, include schemas in the datasource\n\
+ \ - `auto_discover_tables`: if `True`, include tables in the datasource\n\
+ \ - `auto_discover_columns`: if `True`, include columns & table metadata\
+ \ in the datasource"
+ properties:
+ auto_discover_columns:
+ anyOf:
+ - type: boolean
+ - enum:
+ - auto
+ auto_discover_schemas:
+ anyOf:
+ - type: boolean
+ - enum:
+ - auto
+ auto_discover_tables:
+ anyOf:
+ - type: boolean
+ - enum:
+ - auto
+ required: []
+ title: DatasourcesConfig
type: object
DeleteCellRequest:
properties:
@@ -773,6 +1000,7 @@ components:
type: string
required:
- cellId
+ title: DeleteCellRequest
type: object
DeleteSecretRequest:
properties:
@@ -780,6 +1008,7 @@ components:
type: string
required:
- key
+ title: DeleteSecretRequest
type: object
DependencyTreeNode:
properties:
@@ -796,33 +1025,87 @@ components:
type: object
type: array
version:
- nullable: true
- type: string
+ anyOf:
+ - type: string
+ - type: 'null'
required:
- name
+ - version
- tags
- dependencies
+ title: DependencyTreeNode
type: object
DependencyTreeResponse:
properties:
tree:
- $ref: '#/components/schemas/DependencyTreeNode'
- nullable: true
- type: object
- Error:
- oneOf:
- - $ref: '#/components/schemas/SetupRootError'
- - $ref: '#/components/schemas/CycleError'
- - $ref: '#/components/schemas/MultipleDefinitionError'
- - $ref: '#/components/schemas/ImportStarError'
- - $ref: '#/components/schemas/MarimoAncestorStoppedError'
- - $ref: '#/components/schemas/MarimoAncestorPreventedError'
- - $ref: '#/components/schemas/MarimoExceptionRaisedError'
- - $ref: '#/components/schemas/MarimoStrictExecutionError'
- - $ref: '#/components/schemas/MarimoInterruptionError'
- - $ref: '#/components/schemas/MarimoSyntaxError'
- - $ref: '#/components/schemas/MarimoInternalError'
- - $ref: '#/components/schemas/UnknownError'
+ anyOf:
+ - type: 'null'
+ - $ref: '#/components/schemas/DependencyTreeNode'
+ required:
+ - tree
+ title: DependencyTreeResponse
+ type: object
+ DiagnosticsConfig:
+ description: "Configuration options for diagnostics.\n\n **Keys.**\n\n \
+ \ - `enabled`: if `True`, diagnostics will be shown in the editor"
+ properties:
+ enabled:
+ type: boolean
+ required: []
+ title: DiagnosticsConfig
+ type: object
+ DisplayConfig:
+ description: "Configuration for display.\n\n **Keys.**\n\n - `theme`:\
+ \ `\"light\"`, `\"dark\"`, or `\"system\"`\n - `code_editor_font_size`:\
+ \ font size for the code editor\n - `cell_output`: `\"above\"` or `\"below\"\
+ `\n - `dataframes`: `\"rich\"` or `\"plain\"`\n - `custom_css`: list\
+ \ of paths to custom CSS files\n - `default_table_page_size`: default number\
+ \ of rows to display in tables\n - `default_table_max_columns`: default\
+ \ maximum number of columns to display in tables\n - `reference_highlighting`:\
+ \ if `True`, highlight reactive variable references"
+ properties:
+ cell_output:
+ enum:
+ - above
+ - below
+ code_editor_font_size:
+ type: integer
+ custom_css:
+ items:
+ type: string
+ type: array
+ dataframes:
+ enum:
+ - plain
+ - rich
+ default_table_max_columns:
+ type: integer
+ default_table_page_size:
+ type: integer
+ default_width:
+ enum:
+ - columns
+ - compact
+ - full
+ - medium
+ - normal
+ reference_highlighting:
+ type: boolean
+ theme:
+ enum:
+ - dark
+ - light
+ - system
+ required:
+ - cell_output
+ - code_editor_font_size
+ - dataframes
+ - default_table_max_columns
+ - default_table_page_size
+ - default_width
+ - theme
+ title: DisplayConfig
+ type: object
ExecuteMultipleRequest:
properties:
cellIds:
@@ -834,30 +1117,39 @@ components:
type: string
type: array
request:
- $ref: '#/components/schemas/HTTPRequest'
- nullable: true
+ anyOf:
+ - $ref: '#/components/schemas/HTTPRequest'
+ - type: 'null'
+ default: null
timestamp:
type: number
required:
- cellIds
- codes
- - timestamp
+ title: ExecuteMultipleRequest
type: object
ExecuteScratchpadRequest:
properties:
code:
type: string
request:
- $ref: '#/components/schemas/HTTPRequest'
- nullable: true
+ anyOf:
+ - $ref: '#/components/schemas/HTTPRequest'
+ - type: 'null'
+ default: null
required:
- code
+ title: ExecuteScratchpadRequest
type: object
ExecuteStaleRequest:
properties:
request:
- $ref: '#/components/schemas/HTTPRequest'
- nullable: true
+ anyOf:
+ - $ref: '#/components/schemas/HTTPRequest'
+ - type: 'null'
+ default: null
+ required: []
+ title: ExecuteStaleRequest
type: object
ExecutionRequest:
properties:
@@ -866,20 +1158,24 @@ components:
code:
type: string
request:
- $ref: '#/components/schemas/HTTPRequest'
- nullable: true
+ anyOf:
+ - $ref: '#/components/schemas/HTTPRequest'
+ - type: 'null'
+ default: null
timestamp:
type: number
required:
- cellId
- code
- - timestamp
+ title: ExecutionRequest
type: object
ExportAsHTMLRequest:
properties:
assetUrl:
- nullable: true
- type: string
+ anyOf:
+ - type: string
+ - type: 'null'
+ default: null
download:
type: boolean
files:
@@ -892,6 +1188,7 @@ components:
- download
- files
- includeCode
+ title: ExportAsHTMLRequest
type: object
ExportAsIPYNBRequest:
properties:
@@ -899,6 +1196,7 @@ components:
type: boolean
required:
- download
+ title: ExportAsIPYNBRequest
type: object
ExportAsMarkdownRequest:
properties:
@@ -906,6 +1204,7 @@ components:
type: boolean
required:
- download
+ title: ExportAsMarkdownRequest
type: object
ExportAsScriptRequest:
properties:
@@ -913,38 +1212,46 @@ components:
type: boolean
required:
- download
+ title: ExportAsScriptRequest
type: object
FileCreateRequest:
properties:
contents:
- nullable: true
- type: string
+ anyOf:
+ - type: string
+ - type: 'null'
+ default: null
name:
type: string
path:
type: string
type:
enum:
- - file
- directory
- type: string
+ - file
required:
- path
- type
- name
+ title: FileCreateRequest
type: object
FileCreateResponse:
properties:
info:
- $ref: '#/components/schemas/FileInfo'
- nullable: true
+ anyOf:
+ - type: 'null'
+ - $ref: '#/components/schemas/FileInfo'
+ default: null
message:
- nullable: true
- type: string
+ anyOf:
+ - type: string
+ - type: 'null'
+ default: null
success:
type: boolean
required:
- success
+ title: FileCreateResponse
type: object
FileDeleteRequest:
properties:
@@ -952,16 +1259,20 @@ components:
type: string
required:
- path
+ title: FileDeleteRequest
type: object
FileDeleteResponse:
properties:
message:
- nullable: true
- type: string
+ anyOf:
+ - type: string
+ - type: 'null'
+ default: null
success:
type: boolean
required:
- success
+ title: FileDeleteResponse
type: object
FileDetailsRequest:
properties:
@@ -969,23 +1280,30 @@ components:
type: string
required:
- path
+ title: FileDetailsRequest
type: object
FileDetailsResponse:
properties:
contents:
- nullable: true
- type: string
+ anyOf:
+ - type: string
+ - type: 'null'
+ default: null
file:
$ref: '#/components/schemas/FileInfo'
mimeType:
- nullable: true
- type: string
+ anyOf:
+ - type: string
+ - type: 'null'
+ default: null
required:
- file
+ title: FileDetailsResponse
type: object
FileInfo:
properties:
children:
+ default: []
items:
$ref: '#/components/schemas/FileInfo'
type: array
@@ -996,8 +1314,10 @@ components:
isMarimoFile:
type: boolean
lastModified:
- nullable: true
- type: number
+ anyOf:
+ - type: number
+ - type: 'null'
+ default: null
name:
type: string
path:
@@ -1008,13 +1328,17 @@ components:
- name
- isDirectory
- isMarimoFile
- - children
+ title: FileInfo
type: object
FileListRequest:
properties:
path:
- nullable: true
- type: string
+ anyOf:
+ - type: string
+ - type: 'null'
+ default: null
+ required: []
+ title: FileListRequest
type: object
FileListResponse:
properties:
@@ -1027,6 +1351,7 @@ components:
required:
- files
- root
+ title: FileListResponse
type: object
FileMoveRequest:
properties:
@@ -1037,19 +1362,25 @@ components:
required:
- path
- newPath
+ title: FileMoveRequest
type: object
FileMoveResponse:
properties:
info:
- $ref: '#/components/schemas/FileInfo'
- nullable: true
+ anyOf:
+ - type: 'null'
+ - $ref: '#/components/schemas/FileInfo'
+ default: null
message:
- nullable: true
- type: string
+ anyOf:
+ - type: string
+ - type: 'null'
+ default: null
success:
type: boolean
required:
- success
+ title: FileMoveResponse
type: object
FileOpenRequest:
properties:
@@ -1057,6 +1388,7 @@ components:
type: string
required:
- path
+ title: FileOpenRequest
type: object
FileUpdateRequest:
properties:
@@ -1067,31 +1399,37 @@ components:
required:
- path
- contents
+ title: FileUpdateRequest
type: object
FileUpdateResponse:
properties:
info:
- $ref: '#/components/schemas/FileInfo'
- nullable: true
+ anyOf:
+ - type: 'null'
+ - $ref: '#/components/schemas/FileInfo'
+ default: null
message:
- nullable: true
- type: string
+ anyOf:
+ - type: string
+ - type: 'null'
+ default: null
success:
type: boolean
required:
- success
+ title: FileUpdateResponse
type: object
FocusCell:
properties:
cell_id:
type: string
- name:
+ op:
enum:
- focus-cell
- type: string
required:
+ - op
- cell_id
- - name
+ title: FocusCell
type: object
FormatRequest:
properties:
@@ -1104,6 +1442,7 @@ components:
required:
- codes
- lineLength
+ title: FormatRequest
type: object
FormatResponse:
properties:
@@ -1113,11 +1452,21 @@ components:
type: object
required:
- codes
+ title: FormatResponse
+ type: object
+ FormattingConfig:
+ description: "Configuration for code formatting.\n\n **Keys.**\n\n - `line_length`:\
+ \ max line length"
+ properties:
+ line_length:
+ type: integer
+ required:
+ - line_length
+ title: FormattingConfig
type: object
FunctionCallRequest:
properties:
args:
- additionalProperties: {}
type: object
functionCallId:
type: string
@@ -1130,67 +1479,105 @@ components:
- namespace
- functionName
- args
+ title: FunctionCallRequest
type: object
FunctionCallResult:
+ description: Result of calling a function.
properties:
function_call_id:
type: string
- name:
+ op:
enum:
- function-call-result
- type: string
- return_value:
- nullable: true
- oneOf:
- - additionalProperties:
- $ref: '#/components/schemas/JSONType'
- type: object
- - items:
- $ref: '#/components/schemas/JSONType'
- type: array
- - type: string
- - type: integer
- - type: number
- - type: boolean
- - additionalProperties: true
- type: object
- - $ref: '#/components/schemas/MIME'
+ return_value: {}
status:
$ref: '#/components/schemas/HumanReadableStatus'
required:
+ - op
- function_call_id
+ - return_value
- status
- - name
+ title: FunctionCallResult
type: object
GitHubConfig:
+ description: "Configuration options for GitHub.\n\n **Keys.**\n\n - `api_key`:\
+ \ the GitHub API token\n - `base_url`: the base URL for the API"
properties:
api_key:
type: string
base_url:
type: string
+ required: []
+ title: GitHubConfig
type: object
GoogleAiConfig:
+ description: "Configuration options for Google AI.\n\n **Keys.**\n\n -\
+ \ `api_key`: the Google AI API key"
properties:
api_key:
type: string
+ required: []
+ title: GoogleAiConfig
type: object
HTTPRequest:
- type: 'null'
+ properties:
+ baseUrl:
+ additionalProperties: {}
+ type: object
+ cookies:
+ additionalProperties:
+ type: string
+ type: object
+ headers:
+ additionalProperties:
+ type: string
+ type: object
+ meta:
+ additionalProperties: {}
+ type: object
+ pathParams:
+ additionalProperties: {}
+ type: object
+ queryParams:
+ additionalProperties:
+ items:
+ type: string
+ type: array
+ type: object
+ url:
+ additionalProperties: {}
+ type: object
+ user: {}
+ required:
+ - url
+ - baseUrl
+ - headers
+ - queryParams
+ - pathParams
+ - cookies
+ - meta
+ - user
+ type: object
HumanReadableStatus:
+ description: Human-readable status.
properties:
code:
enum:
- - ok
- error
- type: string
+ - ok
message:
- nullable: true
- type: string
+ anyOf:
+ - type: string
+ - type: 'null'
+ default: null
title:
- nullable: true
- type: string
+ anyOf:
+ - type: string
+ - type: 'null'
+ default: null
required:
- code
+ title: HumanReadableStatus
type: object
ImportStarError:
properties:
@@ -1199,10 +1586,10 @@ components:
type:
enum:
- import-star
- type: string
required:
- - msg
- type
+ - msg
+ title: ImportStarError
type: object
InstallMissingPackagesRequest:
properties:
@@ -1215,67 +1602,70 @@ components:
required:
- manager
- versions
+ title: InstallMissingPackagesRequest
type: object
InstallingPackageAlert:
properties:
- name:
+ op:
enum:
- installing-package-alert
- type: string
packages:
additionalProperties:
enum:
- - queued
- - installing
- - installed
- failed
- type: string
+ - installed
+ - installing
+ - queued
type: object
required:
+ - op
- packages
- - name
+ title: InstallingPackageAlert
type: object
InstantiateRequest:
properties:
autoRun:
+ default: true
type: boolean
objectIds:
items:
type: string
type: array
values:
- items: {}
type: array
required:
- objectIds
- values
- - autoRun
+ title: InstantiateRequest
type: object
Interrupted:
+ description: Written when the kernel is interrupted by the user.
properties:
- name:
+ op:
enum:
- interrupted
- type: string
required:
- - name
+ - op
+ title: Interrupted
type: object
InvokeAiToolRequest:
properties:
arguments:
- additionalProperties: {}
type: object
toolName:
type: string
required:
- toolName
- arguments
+ title: InvokeAiToolRequest
type: object
InvokeAiToolResponse:
properties:
error:
- nullable: true
- type: string
+ anyOf:
+ - type: string
+ - type: 'null'
+ default: null
result: {}
success:
type: boolean
@@ -1285,76 +1675,32 @@ components:
- success
- toolName
- result
+ title: InvokeAiToolResponse
+ type: object
+ KernelCapabilities:
+ properties:
+ basedpyright:
+ default: false
+ type: boolean
+ pylsp:
+ default: false
+ type: boolean
+ terminal:
+ default: false
+ type: boolean
+ ty:
+ default: false
+ type: boolean
+ required: []
+ title: KernelCapabilities
type: object
- JSONType:
- oneOf:
- - type: string
- - type: number
- - type: object
- - type: array
- - type: boolean
- - type: 'null'
KernelReady:
+ description: Kernel is ready for execution.
properties:
app_config:
- properties:
- app_title:
- nullable: true
- type: string
- auto_download:
- items:
- enum:
- - html
- - markdown
- - ipynb
- type: string
- type: array
- css_file:
- nullable: true
- type: string
- html_head_file:
- nullable: true
- type: string
- layout_file:
- nullable: true
- type: string
- sql_output:
- enum:
- - polars
- - lazy-polars
- - pandas
- - native
- - auto
- type: string
- width:
- enum:
- - normal
- - compact
- - medium
- - full
- - columns
- type: string
- required:
- - width
- - auto_download
- - sql_output
- type: object
+ $ref: '#/components/schemas/_AppConfig'
capabilities:
- properties:
- basedpyright:
- type: boolean
- pylsp:
- type: boolean
- terminal:
- type: boolean
- ty:
- type: boolean
- required:
- - terminal
- - pylsp
- - ty
- - basedpyright
- type: object
+ $ref: '#/components/schemas/KernelCapabilities'
cell_ids:
items:
type: string
@@ -1370,94 +1716,208 @@ components:
kiosk:
type: boolean
last_executed_code:
- additionalProperties:
- type: string
- nullable: true
- type: object
+ anyOf:
+ - additionalProperties:
+ type: string
+ type: object
+ - type: 'null'
last_execution_time:
- additionalProperties:
- type: number
- nullable: true
- type: object
+ anyOf:
+ - additionalProperties:
+ type: number
+ type: object
+ - type: 'null'
layout:
- nullable: true
- properties:
- data:
- additionalProperties: {}
- type: object
- type:
- type: string
- required:
- - type
- - data
- type: object
- name:
- enum:
- - kernel-ready
- type: string
+ anyOf:
+ - $ref: '#/components/schemas/LayoutConfig'
+ - type: 'null'
names:
items:
type: string
type: array
+ op:
+ enum:
+ - kernel-ready
resumed:
type: boolean
ui_values:
- additionalProperties:
- nullable: true
- oneOf:
- - additionalProperties:
- nullable: true
- oneOf:
- - additionalProperties:
- $ref: '#/components/schemas/JSONType'
- type: object
- - items:
- $ref: '#/components/schemas/JSONType'
- type: array
- - type: string
- - type: integer
- - type: number
- - type: boolean
- - additionalProperties: true
- type: object
- - $ref: '#/components/schemas/MIME'
- type: object
- - items:
- nullable: true
- oneOf:
- - additionalProperties:
- $ref: '#/components/schemas/JSONType'
- type: object
- - items:
- $ref: '#/components/schemas/JSONType'
- type: array
- - type: string
- - type: integer
- - type: number
- - type: boolean
- - additionalProperties: true
- type: object
- - $ref: '#/components/schemas/MIME'
- type: array
- - type: string
- - type: integer
- - type: number
- - type: boolean
- - additionalProperties: true
- type: object
- - $ref: '#/components/schemas/MIME'
- nullable: true
- type: object
+ anyOf:
+ - type: object
+ - type: 'null'
required:
+ - op
- cell_ids
- codes
- names
+ - layout
- configs
- resumed
+ - ui_values
+ - last_executed_code
+ - last_execution_time
- app_config
- kiosk
- capabilities
- - name
+ title: KernelReady
+ type: object
+ KeymapConfig:
+ description: "Configuration for keymaps.\n\n **Keys.**\n\n - `preset`:\
+ \ one of `\"default\"` or `\"vim\"`\n - `overrides`: a dict of keymap actions\
+ \ to their keymap override\n - `vimrc`: path to a vimrc file to load keymaps\
+ \ from\n - `destructive_delete`: if `True`, allows deleting cells with\
+ \ content."
+ properties:
+ destructive_delete:
+ type: boolean
+ overrides:
+ additionalProperties:
+ type: string
+ type: object
+ preset:
+ enum:
+ - default
+ - vim
+ vimrc:
+ anyOf:
+ - type: string
+ - type: 'null'
+ required:
+ - preset
+ title: KeymapConfig
+ type: object
+ KnownUnions:
+ properties:
+ data_type:
+ enum:
+ - boolean
+ - date
+ - datetime
+ - integer
+ - number
+ - string
+ - time
+ - unknown
+ error:
+ anyOf:
+ - $ref: '#/components/schemas/SetupRootError'
+ - $ref: '#/components/schemas/CycleError'
+ - $ref: '#/components/schemas/MultipleDefinitionError'
+ - $ref: '#/components/schemas/ImportStarError'
+ - $ref: '#/components/schemas/MarimoAncestorStoppedError'
+ - $ref: '#/components/schemas/MarimoAncestorPreventedError'
+ - $ref: '#/components/schemas/MarimoExceptionRaisedError'
+ - $ref: '#/components/schemas/MarimoStrictExecutionError'
+ - $ref: '#/components/schemas/MarimoInterruptionError'
+ - $ref: '#/components/schemas/MarimoSyntaxError'
+ - $ref: '#/components/schemas/MarimoInternalError'
+ - $ref: '#/components/schemas/UnknownError'
+ discriminator:
+ mapping:
+ ancestor-prevented: '#/components/schemas/MarimoAncestorPreventedError'
+ ancestor-stopped: '#/components/schemas/MarimoAncestorStoppedError'
+ cycle: '#/components/schemas/CycleError'
+ exception: '#/components/schemas/MarimoExceptionRaisedError'
+ import-star: '#/components/schemas/ImportStarError'
+ internal: '#/components/schemas/MarimoInternalError'
+ interruption: '#/components/schemas/MarimoInterruptionError'
+ multiple-defs: '#/components/schemas/MultipleDefinitionError'
+ setup-refs: '#/components/schemas/SetupRootError'
+ strict-exception: '#/components/schemas/MarimoStrictExecutionError'
+ syntax: '#/components/schemas/MarimoSyntaxError'
+ unknown: '#/components/schemas/UnknownError'
+ propertyName: type
+ operation:
+ anyOf:
+ - $ref: '#/components/schemas/CellOp'
+ - $ref: '#/components/schemas/FunctionCallResult'
+ - $ref: '#/components/schemas/SendUIElementMessage'
+ - $ref: '#/components/schemas/RemoveUIElements'
+ - $ref: '#/components/schemas/Reload'
+ - $ref: '#/components/schemas/Reconnected'
+ - $ref: '#/components/schemas/Interrupted'
+ - $ref: '#/components/schemas/CompletedRun'
+ - $ref: '#/components/schemas/KernelReady'
+ - $ref: '#/components/schemas/CompletionResult'
+ - $ref: '#/components/schemas/Alert'
+ - $ref: '#/components/schemas/Banner'
+ - $ref: '#/components/schemas/MissingPackageAlert'
+ - $ref: '#/components/schemas/InstallingPackageAlert'
+ - $ref: '#/components/schemas/Variables'
+ - $ref: '#/components/schemas/VariableValues'
+ - $ref: '#/components/schemas/QueryParamsSet'
+ - $ref: '#/components/schemas/QueryParamsAppend'
+ - $ref: '#/components/schemas/QueryParamsDelete'
+ - $ref: '#/components/schemas/QueryParamsClear'
+ - $ref: '#/components/schemas/Datasets'
+ - $ref: '#/components/schemas/DataColumnPreview'
+ - $ref: '#/components/schemas/SQLTablePreview'
+ - $ref: '#/components/schemas/SQLTableListPreview'
+ - $ref: '#/components/schemas/DataSourceConnections'
+ - $ref: '#/components/schemas/SecretKeysResult'
+ - $ref: '#/components/schemas/FocusCell'
+ - $ref: '#/components/schemas/UpdateCellCodes'
+ - $ref: '#/components/schemas/UpdateCellIdsRequest'
+ discriminator:
+ mapping:
+ alert: '#/components/schemas/Alert'
+ banner: '#/components/schemas/Banner'
+ cell-op: '#/components/schemas/CellOp'
+ completed-run: '#/components/schemas/CompletedRun'
+ completion-result: '#/components/schemas/CompletionResult'
+ data-column-preview: '#/components/schemas/DataColumnPreview'
+ data-source-connections: '#/components/schemas/DataSourceConnections'
+ datasets: '#/components/schemas/Datasets'
+ focus-cell: '#/components/schemas/FocusCell'
+ function-call-result: '#/components/schemas/FunctionCallResult'
+ installing-package-alert: '#/components/schemas/InstallingPackageAlert'
+ interrupted: '#/components/schemas/Interrupted'
+ kernel-ready: '#/components/schemas/KernelReady'
+ missing-package-alert: '#/components/schemas/MissingPackageAlert'
+ query-params-append: '#/components/schemas/QueryParamsAppend'
+ query-params-clear: '#/components/schemas/QueryParamsClear'
+ query-params-delete: '#/components/schemas/QueryParamsDelete'
+ query-params-set: '#/components/schemas/QueryParamsSet'
+ reconnected: '#/components/schemas/Reconnected'
+ reload: '#/components/schemas/Reload'
+ remove-ui-elements: '#/components/schemas/RemoveUIElements'
+ secret-keys-result: '#/components/schemas/SecretKeysResult'
+ send-ui-element-message: '#/components/schemas/SendUIElementMessage'
+ sql-table-list-preview: '#/components/schemas/SQLTableListPreview'
+ sql-table-preview: '#/components/schemas/SQLTablePreview'
+ update-cell-codes: '#/components/schemas/UpdateCellCodes'
+ update-cell-ids: '#/components/schemas/UpdateCellIdsRequest'
+ variable-values: '#/components/schemas/VariableValues'
+ variables: '#/components/schemas/Variables'
+ propertyName: op
+ required:
+ - operation
+ - error
+ - data_type
+ title: KnownUnions
+ type: object
+ LanguageServersConfig:
+ description: "Configuration options for language servers.\n\n **Keys.**\n\
+ \n - `pylsp`: the pylsp config"
+ properties:
+ basedpyright:
+ $ref: '#/components/schemas/BasedpyrightServerConfig'
+ pylsp:
+ $ref: '#/components/schemas/PythonLanguageServerConfig'
+ ty:
+ $ref: '#/components/schemas/TyLanguageServerConfig'
+ required: []
+ title: LanguageServersConfig
+ type: object
+ LayoutConfig:
+ properties:
+ data:
+ type: object
+ type:
+ type: string
+ required:
+ - type
+ - data
+ title: LayoutConfig
type: object
ListPackagesResponse:
properties:
@@ -1467,6 +1927,7 @@ components:
type: array
required:
- packages
+ title: ListPackagesResponse
type: object
ListSecretKeysRequest:
properties:
@@ -1474,6 +1935,7 @@ components:
type: string
required:
- requestId
+ title: ListSecretKeysRequest
type: object
ListSecretKeysResponse:
properties:
@@ -1483,15 +1945,22 @@ components:
type: array
required:
- keys
+ title: ListSecretKeysResponse
type: object
MIME:
+ description: "Protocol for instantiating objects using marimo's media viewer.\n\
+ \n To implement this protocol, a class needs to define\n just one method,\
+ \ _mime_."
properties: {}
+ required: []
+ title: MIME
type: object
MarimoAncestorPreventedError:
properties:
blamed_cell:
- nullable: true
- type: string
+ anyOf:
+ - type: string
+ - type: 'null'
msg:
type: string
raising_cell:
@@ -1499,11 +1968,12 @@ components:
type:
enum:
- ancestor-prevented
- type: string
required:
+ - type
- msg
- raising_cell
- - type
+ - blamed_cell
+ title: MarimoAncestorPreventedError
type: object
MarimoAncestorStoppedError:
properties:
@@ -1514,343 +1984,55 @@ components:
type:
enum:
- ancestor-stopped
- type: string
required:
+ - type
- msg
- raising_cell
- - type
+ title: MarimoAncestorStoppedError
type: object
MarimoConfig:
+ description: Configuration for the marimo editor
properties:
ai:
$ref: '#/components/schemas/AiConfig'
completion:
- properties:
- activate_on_typing:
- type: boolean
- api_key:
- nullable: true
- type: string
- base_url:
- nullable: true
- type: string
- codeium_api_key:
- nullable: true
- type: string
- copilot:
- oneOf:
- - type: boolean
- - enum:
- - github
- - codeium
- - custom
- type: string
- model:
- nullable: true
- type: string
- required:
- - activate_on_typing
- - copilot
- type: object
+ $ref: '#/components/schemas/CompletionConfig'
datasources:
- properties:
- auto_discover_columns:
- oneOf:
- - type: boolean
- - enum:
- - auto
- type: string
- auto_discover_schemas:
- oneOf:
- - type: boolean
- - enum:
- - auto
- type: string
- auto_discover_tables:
- oneOf:
- - type: boolean
- - enum:
- - auto
- type: string
- type: object
+ $ref: '#/components/schemas/DatasourcesConfig'
diagnostics:
- properties:
- enabled:
- type: boolean
- type: object
+ $ref: '#/components/schemas/DiagnosticsConfig'
display:
- properties:
- cell_output:
- enum:
- - above
- - below
- type: string
- code_editor_font_size:
- type: integer
- custom_css:
- items:
- type: string
- type: array
- dataframes:
- enum:
- - rich
- - plain
- type: string
- default_table_max_columns:
- type: integer
- default_table_page_size:
- type: integer
- default_width:
- enum:
- - normal
- - compact
- - medium
- - full
- - columns
- type: string
- reference_highlighting:
- type: boolean
- theme:
- enum:
- - light
- - dark
- - system
- type: string
- required:
- - theme
- - code_editor_font_size
- - cell_output
- - default_width
- - dataframes
- - default_table_page_size
- - default_table_max_columns
- type: object
+ $ref: '#/components/schemas/DisplayConfig'
experimental:
- oneOf:
- - additionalProperties: {}
- type: object
- - properties:
- cache:
- oneOf:
- - items:
- properties:
- args:
- additionalProperties: {}
- type: object
- type:
- enum:
- - file
- - redis
- - rest
- - tiered
- type: string
- type: object
- type: array
- - $ref: '#/components/schemas/StoreConfig'
- execution_type:
- enum:
- - relaxed
- - strict
- type: string
- inline_ai_tooltip:
- type: boolean
- markdown:
- type: boolean
- mcp_docs:
- type: boolean
- performant_table_charts:
- type: boolean
- rtc_v2:
- type: boolean
- sql_linter:
- type: boolean
- wasm_layouts:
- type: boolean
- type: object
- formatting:
- properties:
- line_length:
- type: integer
- required:
- - line_length
type: object
+ formatting:
+ $ref: '#/components/schemas/FormattingConfig'
keymap:
- properties:
- destructive_delete:
- type: boolean
- overrides:
- additionalProperties:
- type: string
- type: object
- preset:
- enum:
- - default
- - vim
- type: string
- vimrc:
- nullable: true
- type: string
- required:
- - preset
- type: object
+ $ref: '#/components/schemas/KeymapConfig'
language_servers:
- properties:
- basedpyright:
- properties:
- enabled:
- type: boolean
- type: object
- pylsp:
- properties:
- enable_flake8:
- type: boolean
- enable_mypy:
- type: boolean
- enable_pydocstyle:
- type: boolean
- enable_pyflakes:
- type: boolean
- enable_pylint:
- type: boolean
- enable_ruff:
- type: boolean
- enabled:
- type: boolean
- type: object
- ty:
- properties:
- enabled:
- type: boolean
- type: object
- type: object
+ $ref: '#/components/schemas/LanguageServersConfig'
package_management:
- properties:
- manager:
- enum:
- - pip
- - rye
- - uv
- - poetry
- - pixi
- type: string
- required:
- - manager
- type: object
+ $ref: '#/components/schemas/PackageManagementConfig'
runtime:
- properties:
- auto_instantiate:
- type: boolean
- auto_reload:
- enum:
- - 'off'
- - lazy
- - autorun
- type: string
- default_auto_download:
- items:
- enum:
- - html
- - markdown
- - ipynb
- type: string
- type: array
- default_sql_output:
- enum:
- - polars
- - lazy-polars
- - pandas
- - native
- - auto
- type: string
- dotenv:
- items:
- type: string
- type: array
- on_cell_change:
- enum:
- - lazy
- - autorun
- type: string
- output_max_bytes:
- type: integer
- pythonpath:
- items:
- type: string
- type: array
- reactive_tests:
- type: boolean
- std_stream_max_bytes:
- type: integer
- watcher_on_save:
- enum:
- - lazy
- - autorun
- type: string
- required:
- - auto_instantiate
- - auto_reload
- - reactive_tests
- - on_cell_change
- - watcher_on_save
- - output_max_bytes
- - std_stream_max_bytes
- - default_sql_output
- type: object
+ $ref: '#/components/schemas/RuntimeConfig'
save:
- properties:
- autosave:
- enum:
- - 'off'
- - after_delay
- type: string
- 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
- - type: string
- follow_symlink:
- type: boolean
- required:
- - browser
- - follow_symlink
- type: object
+ $ref: '#/components/schemas/SaveConfig'
+ server:
+ $ref: '#/components/schemas/ServerConfig'
sharing:
- properties:
- html:
- type: boolean
- wasm:
- type: boolean
- type: object
+ $ref: '#/components/schemas/SharingConfig'
snippets:
- properties:
- custom_paths:
- items:
- type: string
- type: array
- include_default_snippets:
- type: boolean
- type: object
+ $ref: '#/components/schemas/SnippetsConfig'
required:
- completion
- display
- formatting
- keymap
+ - package_management
- runtime
- save
- server
- - package_management
+ title: MarimoConfig
type: object
MarimoExceptionRaisedError:
properties:
@@ -1859,65 +2041,83 @@ components:
msg:
type: string
raising_cell:
- nullable: true
- type: string
+ anyOf:
+ - type: string
+ - type: 'null'
type:
enum:
- exception
- type: string
required:
+ - type
- msg
- exception_type
- - type
+ - raising_cell
+ title: MarimoExceptionRaisedError
type: object
MarimoFile:
properties:
initializationId:
- nullable: true
- type: string
+ anyOf:
+ - type: string
+ - type: 'null'
+ default: null
lastModified:
- nullable: true
- type: number
+ anyOf:
+ - type: number
+ - type: 'null'
+ default: null
name:
type: string
path:
type: string
sessionId:
- nullable: true
- type: string
+ anyOf:
+ - type: string
+ - type: 'null'
+ default: null
required:
- name
- path
+ title: MarimoFile
type: object
MarimoInternalError:
+ description: 'An internal error that should be hidden from the user.
+
+ The error is logged to the console and then a new error is broadcasted
+
+ such that the data is hidden.
+
+
+ They can be linked back to the original error by the error_id.'
properties:
error_id:
type: string
msg:
+ default: ''
type: string
type:
enum:
- internal
- type: string
required:
- - error_id
- type
- - msg
+ - error_id
+ title: MarimoInternalError
type: object
MarimoInterruptionError:
properties:
type:
enum:
- interruption
- type: string
required:
- type
+ title: MarimoInterruptionError
type: object
MarimoStrictExecutionError:
properties:
blamed_cell:
- nullable: true
- type: string
+ anyOf:
+ - type: string
+ - type: 'null'
msg:
type: string
ref:
@@ -1925,11 +2125,12 @@ components:
type:
enum:
- strict-exception
- type: string
required:
+ - type
- msg
- ref
- - type
+ - blamed_cell
+ title: MarimoStrictExecutionError
type: object
MarimoSyntaxError:
properties:
@@ -1938,82 +2139,44 @@ components:
type:
enum:
- syntax
- type: string
required:
- - msg
- type
+ - msg
+ title: MarimoSyntaxError
type: object
- MessageOperation:
- oneOf:
- - $ref: '#/components/schemas/CellOp'
- - $ref: '#/components/schemas/FunctionCallResult'
- - $ref: '#/components/schemas/SendUIElementMessage'
- - $ref: '#/components/schemas/RemoveUIElements'
- - $ref: '#/components/schemas/Reload'
- - $ref: '#/components/schemas/Reconnected'
- - $ref: '#/components/schemas/Interrupted'
- - $ref: '#/components/schemas/CompletedRun'
- - $ref: '#/components/schemas/KernelReady'
- - $ref: '#/components/schemas/CompletionResult'
- - $ref: '#/components/schemas/Alert'
- - $ref: '#/components/schemas/Banner'
- - $ref: '#/components/schemas/MissingPackageAlert'
- - $ref: '#/components/schemas/InstallingPackageAlert'
- - $ref: '#/components/schemas/Variables'
- - $ref: '#/components/schemas/VariableValues'
- - $ref: '#/components/schemas/QueryParamsSet'
- - $ref: '#/components/schemas/QueryParamsAppend'
- - $ref: '#/components/schemas/QueryParamsDelete'
- - $ref: '#/components/schemas/QueryParamsClear'
- - $ref: '#/components/schemas/Datasets'
- - $ref: '#/components/schemas/DataColumnPreview'
- - $ref: '#/components/schemas/SQLTablePreview'
- - $ref: '#/components/schemas/SQLTableListPreview'
- - $ref: '#/components/schemas/DataSourceConnections'
- - $ref: '#/components/schemas/SecretKeysResult'
- - $ref: '#/components/schemas/FocusCell'
- - $ref: '#/components/schemas/UpdateCellCodes'
- - $ref: '#/components/schemas/UpdateCellIdsRequest'
- MimeType:
- enum:
- - application/json
- - application/vnd.marimo+error
- - application/vnd.marimo+traceback
- - application/vnd.marimo+mimebundle
- - application/vnd.vega.v5+json
- - application/vnd.vegalite.v5+json
- - application/vnd.jupyter.widget-view+json
- - image/png
- - image/svg+xml
- - image/tiff
- - image/avif
- - image/bmp
- - image/gif
- - image/jpeg
- - video/mp4
- - video/mpeg
- - text/html
- - text/plain
- - text/markdown
- - text/latex
- - text/csv
- type: string
MissingPackageAlert:
properties:
isolated:
type: boolean
- name:
+ op:
enum:
- missing-package-alert
- type: string
packages:
items:
type: string
type: array
required:
+ - op
- packages
- isolated
- - name
+ title: MissingPackageAlert
+ type: object
+ ModelMessage:
+ properties:
+ bufferPaths:
+ items:
+ items:
+ anyOf:
+ - type: string
+ - type: integer
+ type: array
+ type: array
+ state:
+ type: object
+ required:
+ - state
+ - bufferPaths
+ title: ModelMessage
type: object
MultipleDefinitionError:
properties:
@@ -2026,29 +2189,22 @@ components:
type:
enum:
- multiple-defs
- type: string
required:
+ - type
- name
- cells
- - type
+ title: MultipleDefinitionError
type: object
- NonNestedLiteral:
- oneOf:
- - type: integer
- - type: number
- - format: date
- type: string
- - format: time
- type: string
- - format: date-time
- type: string
- - format: duration
- type: string
- - type: string
- - type: boolean
- - format: byte
- type: string
OpenAiConfig:
+ description: "Configuration options for OpenAI or OpenAI-compatible services.\n\
+ \n **Keys.**\n\n - `api_key`: the OpenAI API key\n - `base_url`:\
+ \ the base URL for the API\n - `ssl_verify` : Boolean argument for httpx\
+ \ passed to open ai client. httpx defaults to true, but some use cases to\
+ \ let users override to False in some testing scenarios\n - `ca_bundle_path`:\
+ \ custom ca bundle to be used for verifying SSL certificates. Used to create\
+ \ custom SSL context for httpx client\n - `client_pem` : custom path of\
+ \ a client .pem cert used for verifying identity of client server\n - `extra_headers`:\
+ \ extra headers to be passed to the OpenAI client"
properties:
api_key:
type: string
@@ -2066,27 +2222,28 @@ components:
type: string
ssl_verify:
type: boolean
+ required: []
+ title: OpenAiConfig
type: object
OpenTutorialRequest:
properties:
tutorialId:
- oneOf:
+ anyOf:
- enum:
- - intro
- dataflow
- - ui
+ - fileformat
+ - for-jupyter-users
+ - intro
+ - layout
- markdown
- plots
- sql
- - layout
- - fileformat
- - for-jupyter-users
- type: string
+ - ui
- enum:
- markdown-format
- type: string
required:
- tutorialId
+ title: OpenTutorialRequest
type: object
PackageDescription:
properties:
@@ -2097,50 +2254,75 @@ components:
required:
- name
- version
+ title: PackageDescription
+ type: object
+ PackageManagementConfig:
+ description: "Configuration options for package management.\n\n **Keys.**\n\
+ \n - `manager`: the package manager to use"
+ properties:
+ manager:
+ enum:
+ - pip
+ - pixi
+ - poetry
+ - rye
+ - uv
+ required:
+ - manager
+ title: PackageManagementConfig
type: object
PackageOperationResponse:
properties:
error:
- nullable: true
- type: string
+ anyOf:
+ - type: string
+ - type: 'null'
+ default: null
success:
type: boolean
required:
- success
+ title: PackageOperationResponse
type: object
PdbRequest:
properties:
cellId:
type: string
request:
- $ref: '#/components/schemas/HTTPRequest'
- nullable: true
+ anyOf:
+ - $ref: '#/components/schemas/HTTPRequest'
+ - type: 'null'
+ default: null
required:
- cellId
+ title: PdbRequest
type: object
PreviewDataSourceConnectionRequest:
+ description: Fetch a datasource connection
properties:
engine:
type: string
required:
- engine
+ title: PreviewDataSourceConnectionRequest
type: object
PreviewDatasetColumnRequest:
properties:
columnName:
type: string
fullyQualifiedTableName:
- nullable: true
- type: string
+ anyOf:
+ - type: string
+ - type: 'null'
+ default: null
source:
type: string
sourceType:
enum:
- - local
- - duckdb
- - connection
- catalog
- type: string
+ - connection
+ - duckdb
+ - local
tableName:
type: string
required:
@@ -2148,8 +2330,10 @@ components:
- source
- tableName
- columnName
+ title: PreviewDatasetColumnRequest
type: object
PreviewSQLTableListRequest:
+ description: Preview list of tables in an SQL schema
properties:
database:
type: string
@@ -2164,8 +2348,10 @@ components:
- engine
- database
- schema
+ title: PreviewSQLTableListRequest
type: object
PreviewSQLTableRequest:
+ description: Preview table details in an SQL database
properties:
database:
type: string
@@ -2183,64 +2369,91 @@ components:
- database
- schema
- tableName
+ title: PreviewSQLTableRequest
+ type: object
+ PythonLanguageServerConfig:
+ description: 'Configuration options for Python Language Server.
+
+
+ pylsp handles completion, hover, go-to-definition, and diagnostics.'
+ properties:
+ enable_flake8:
+ type: boolean
+ enable_mypy:
+ type: boolean
+ enable_pydocstyle:
+ type: boolean
+ enable_pyflakes:
+ type: boolean
+ enable_pylint:
+ type: boolean
+ enable_ruff:
+ type: boolean
+ enabled:
+ type: boolean
+ required: []
+ title: PythonLanguageServerConfig
type: object
QueryParamsAppend:
properties:
key:
type: string
- name:
+ op:
enum:
- query-params-append
- type: string
value:
type: string
required:
+ - op
- key
- value
- - name
+ title: QueryParamsAppend
type: object
QueryParamsClear:
properties:
- name:
+ op:
enum:
- query-params-clear
- type: string
required:
- - name
+ - op
+ title: QueryParamsClear
type: object
QueryParamsDelete:
properties:
key:
type: string
- name:
+ op:
enum:
- query-params-delete
- type: string
value:
- nullable: true
- type: string
+ anyOf:
+ - type: string
+ - type: 'null'
required:
+ - op
- key
- - name
+ - value
+ title: QueryParamsDelete
type: object
QueryParamsSet:
+ description: Set query parameters.
properties:
key:
type: string
- name:
+ op:
enum:
- query-params-set
- type: string
value:
- oneOf:
+ anyOf:
- type: string
- items:
type: string
type: array
required:
+ - op
- key
- value
- - name
+ title: QueryParamsSet
type: object
ReadCodeResponse:
properties:
@@ -2248,6 +2461,7 @@ components:
type: string
required:
- contents
+ title: ReadCodeResponse
type: object
RecentFilesResponse:
properties:
@@ -2257,24 +2471,25 @@ components:
type: array
required:
- files
+ title: RecentFilesResponse
type: object
Reconnected:
properties:
- name:
+ op:
enum:
- reconnected
- type: string
required:
- - name
+ - op
+ title: Reconnected
type: object
Reload:
properties:
- name:
+ op:
enum:
- reload
- type: string
required:
- - name
+ - op
+ title: Reload
type: object
RemovePackageRequest:
properties:
@@ -2282,18 +2497,20 @@ components:
type: string
required:
- package
+ title: RemovePackageRequest
type: object
RemoveUIElements:
+ description: Invalidate UI elements for a given cell.
properties:
cell_id:
type: string
- name:
+ op:
enum:
- remove-ui-elements
- type: string
required:
+ - op
- cell_id
- - name
+ title: RemoveUIElements
type: object
RenameFileRequest:
properties:
@@ -2301,6 +2518,7 @@ components:
type: string
required:
- filename
+ title: RenameFileRequest
type: object
RenameRequest:
properties:
@@ -2308,6 +2526,7 @@ components:
type: string
required:
- filename
+ title: RenameRequest
type: object
RunRequest:
properties:
@@ -2320,11 +2539,14 @@ components:
type: string
type: array
request:
- $ref: '#/components/schemas/HTTPRequest'
- nullable: true
+ anyOf:
+ - $ref: '#/components/schemas/HTTPRequest'
+ - type: 'null'
+ default: null
required:
- cellIds
- codes
+ title: RunRequest
type: object
RunningNotebooksResponse:
properties:
@@ -2334,59 +2556,168 @@ components:
type: array
required:
- files
+ title: RunningNotebooksResponse
+ type: object
+ RuntimeConfig:
+ description: "Configuration for runtime.\n\n **Keys.**\n\n - `auto_instantiate`:\
+ \ if `False`, cells won't automatically\n run on startup. This only\
+ \ applies when editing a notebook,\n and not when running as an application.\n\
+ \ The default is `True`.\n - `auto_reload`: if `lazy`, cells importing\
+ \ modified modules will marked\n as stale; if `autorun`, affected cells\
+ \ will be automatically run. similar\n to IPython's %autoreload extension\
+ \ but with more code intelligence.\n - `reactive_tests`: if `True`, marimo\
+ \ will automatically run pytest on cells containing only test functions and\
+ \ test classes.\n execution.\n - `on_cell_change`: if `lazy`, cells\
+ \ will be marked stale when their\n ancestors run but won't autorun;\
+ \ if `autorun`, cells will automatically\n run when their ancestors run.\n\
+ \ - `execution_type`: if `relaxed`, marimo will not clone cell declarations;\n\
+ \ if `strict` marimo will clone cell declarations by default, avoiding\n\
+ \ hidden potential state build up.\n - `watcher_on_save`: how to handle\
+ \ file changes when saving. `\"lazy\"` marks\n affected cells as stale,\
+ \ `\"autorun\"` automatically runs affected cells.\n - `output_max_bytes`:\
+ \ the maximum size in bytes of cell outputs; larger\n values may affect\
+ \ frontend performance\n - `std_stream_max_bytes`: the maximum size in\
+ \ bytes of console outputs;\n larger values may affect frontend performance\n\
+ \ - `pythonpath`: a list of directories to add to the Python search path.\n\
+ \ Directories will be added to the head of sys.path. Similar to the\n\
+ \ `PYTHONPATH` environment variable, the directories will be included\
+ \ in\n where Python will look for imported modules.\n - `dotenv`:\
+ \ a list of paths to `.env` files to load.\n If the file does not exist,\
+ \ it will be silently ignored.\n The default is `[\".env\"]` if a pyproject.toml\
+ \ is found, otherwise `[]`.\n - `default_sql_output`: the default output\
+ \ format for SQL queries. Can be one of:\n `\"auto\"`, `\"native\"\
+ `, `\"polars\"`, `\"lazy-polars\"`, or `\"pandas\"`.\n The default\
+ \ is `\"auto\"`.\n - `default_auto_download`: an Optional list of export\
+ \ types to automatically snapshot your notebook as:\n `html`, `markdown`,\
+ \ `ipynb`.\n The default is None."
+ properties:
+ auto_instantiate:
+ type: boolean
+ auto_reload:
+ enum:
+ - autorun
+ - lazy
+ - 'off'
+ default_auto_download:
+ items:
+ enum:
+ - html
+ - ipynb
+ - markdown
+ type: array
+ default_sql_output:
+ enum:
+ - auto
+ - lazy-polars
+ - native
+ - pandas
+ - polars
+ dotenv:
+ items:
+ type: string
+ type: array
+ on_cell_change:
+ enum:
+ - autorun
+ - lazy
+ output_max_bytes:
+ type: integer
+ pythonpath:
+ items:
+ type: string
+ type: array
+ reactive_tests:
+ type: boolean
+ std_stream_max_bytes:
+ type: integer
+ watcher_on_save:
+ enum:
+ - autorun
+ - lazy
+ required:
+ - auto_instantiate
+ - auto_reload
+ - default_sql_output
+ - on_cell_change
+ - output_max_bytes
+ - reactive_tests
+ - std_stream_max_bytes
+ - watcher_on_save
+ title: RuntimeConfig
type: object
- RuntimeState:
- enum:
- - idle
- - queued
- - running
- - disabled-transitively
- type: string
SQLTableListPreview:
+ description: Preview of a list of tables in a schema.
properties:
error:
- nullable: true
- type: string
- name:
+ anyOf:
+ - type: string
+ - type: 'null'
+ default: null
+ op:
enum:
- sql-table-list-preview
- type: string
request_id:
type: string
tables:
+ default: []
items:
$ref: '#/components/schemas/DataTable'
type: array
required:
+ - op
- request_id
- - tables
- - name
+ title: SQLTableListPreview
type: object
SQLTablePreview:
+ description: Preview of a table in a SQL database.
properties:
error:
- nullable: true
- type: string
- name:
+ anyOf:
+ - type: string
+ - type: 'null'
+ default: null
+ op:
enum:
- sql-table-preview
- type: string
request_id:
type: string
table:
- $ref: '#/components/schemas/DataTable'
- nullable: true
+ anyOf:
+ - type: 'null'
+ - $ref: '#/components/schemas/DataTable'
required:
+ - op
- request_id
- - name
+ - table
+ title: SQLTablePreview
type: object
SaveAppConfigurationRequest:
properties:
config:
- additionalProperties: {}
type: object
required:
- config
+ title: SaveAppConfigurationRequest
+ type: object
+ SaveConfig:
+ description: "Configuration for saving.\n\n **Keys.**\n\n - `autosave`:\
+ \ one of `\"off\"` or `\"after_delay\"`\n - `delay`: number of milliseconds\
+ \ to wait before autosaving\n - `format_on_save`: if `True`, format the\
+ \ code on save"
+ properties:
+ autosave:
+ enum:
+ - after_delay
+ - 'off'
+ autosave_delay:
+ type: integer
+ format_on_save:
+ type: boolean
+ required:
+ - autosave
+ - autosave_delay
+ - format_on_save
+ title: SaveConfig
type: object
SaveNotebookRequest:
properties:
@@ -2405,14 +2736,16 @@ components:
filename:
type: string
layout:
- additionalProperties: {}
- nullable: true
- type: object
+ anyOf:
+ - type: object
+ - type: 'null'
+ default: null
names:
items:
type: string
type: array
persist:
+ default: true
type: boolean
required:
- cellIds
@@ -2420,14 +2753,15 @@ components:
- names
- configs
- filename
- - persist
+ title: SaveNotebookRequest
type: object
SaveUserConfigurationRequest:
properties:
config:
- $ref: '#/components/schemas/MarimoConfig'
+ type: object
required:
- config
+ title: SaveUserConfigurationRequest
type: object
Schema:
properties:
@@ -2440,13 +2774,13 @@ components:
required:
- name
- tables
+ title: Schema
type: object
SchemaColumn:
properties:
name:
type: string
sampleValues:
- items: {}
type: array
type:
type: string
@@ -2454,6 +2788,7 @@ components:
- name
- type
- sampleValues
+ title: SchemaColumn
type: object
SchemaTable:
properties:
@@ -2466,13 +2801,14 @@ components:
required:
- name
- columns
+ title: SchemaTable
type: object
SecretKeysResult:
+ description: Result of listing secret keys.
properties:
- name:
+ op:
enum:
- secret-keys-result
- type: string
request_id:
type: string
secrets:
@@ -2480,9 +2816,10 @@ components:
$ref: '#/components/schemas/SecretKeysWithProvider'
type: array
required:
+ - op
- request_id
- secrets
- - name
+ title: SecretKeysResult
type: object
SecretKeysWithProvider:
properties:
@@ -2494,77 +2831,90 @@ components:
type: string
provider:
enum:
- - env
- dotenv
- type: string
+ - env
required:
- provider
- name
- keys
+ title: SecretKeysWithProvider
type: object
SendUIElementMessage:
+ description: Send a message to a UI element.
properties:
buffers:
- items:
- type: string
- nullable: true
- type: array
+ anyOf:
+ - items:
+ type: string
+ type: array
+ - type: 'null'
+ default: null
message:
- additionalProperties: {}
type: object
model_id:
- nullable: true
- type: string
- name:
+ anyOf:
+ - type: string
+ - type: 'null'
+ op:
enum:
- send-ui-element-message
- type: string
ui_element:
- nullable: true
- type: string
+ anyOf:
+ - type: string
+ - type: 'null'
required:
+ - op
+ - ui_element
+ - model_id
- message
- - name
+ title: SendUIElementMessage
+ type: object
+ ServerConfig:
+ description: "Configuration for the server.\n\n **Keys.**\n\n - `browser`:\
+ \ the web browser to use. `\"default\"` or a browser registered\n with\
+ \ Python's webbrowser module (eg, `\"firefox\"` or `\"chrome\"`)\n - `follow_symlink`:\
+ \ if true, the server will follow symlinks it finds\n inside its static\
+ \ assets directory."
+ properties:
+ browser:
+ anyOf:
+ - enum:
+ - default
+ - type: string
+ follow_symlink:
+ type: boolean
+ required:
+ - browser
+ - follow_symlink
+ title: ServerConfig
type: object
SetCellConfigRequest:
properties:
configs:
additionalProperties:
- additionalProperties: {}
type: object
type: object
required:
- configs
+ title: SetCellConfigRequest
type: object
SetModelMessageRequest:
properties:
buffers:
- items:
- type: string
- nullable: true
- type: array
+ anyOf:
+ - items:
+ type: string
+ type: array
+ - type: 'null'
+ default: null
message:
- properties:
- bufferPaths:
- items:
- items:
- oneOf:
- - type: string
- - type: integer
- type: array
- type: array
- state:
- additionalProperties: {}
- type: object
- required:
- - state
- - bufferPaths
- type: object
+ $ref: '#/components/schemas/ModelMessage'
modelId:
type: string
required:
- modelId
- message
+ title: SetModelMessageRequest
type: object
SetUIElementValueRequest:
properties:
@@ -2573,17 +2923,18 @@ components:
type: string
type: array
request:
- $ref: '#/components/schemas/HTTPRequest'
- nullable: true
+ anyOf:
+ - $ref: '#/components/schemas/HTTPRequest'
+ - type: 'null'
+ default: null
token:
type: string
values:
- items: {}
type: array
required:
- objectIds
- values
- - token
+ title: SetUIElementValueRequest
type: object
SetUserConfigRequest:
properties:
@@ -2591,11 +2942,15 @@ components:
$ref: '#/components/schemas/MarimoConfig'
required:
- config
+ title: SetUserConfigRequest
type: object
SetupRootError:
properties:
edges_with_vars:
items:
+ items: false
+ maxItems: 3
+ minItems: 3
prefixItems:
- type: string
- items:
@@ -2607,10 +2962,23 @@ components:
type:
enum:
- setup-refs
- type: string
required:
- - edges_with_vars
- type
+ - edges_with_vars
+ title: SetupRootError
+ type: object
+ SharingConfig:
+ description: "Configuration for sharing features.\n\n **Keys.**\n\n -\
+ \ `html`: if `False`, HTML sharing options will be hidden from the UI\n \
+ \ - `wasm`: if `False`, WebAssembly sharing options will be hidden from the\
+ \ UI"
+ properties:
+ html:
+ type: boolean
+ wasm:
+ type: boolean
+ required: []
+ title: SharingConfig
type: object
ShutdownSessionRequest:
properties:
@@ -2618,6 +2986,7 @@ components:
type: string
required:
- sessionId
+ title: ShutdownSessionRequest
type: object
Snippet:
properties:
@@ -2630,19 +2999,25 @@ components:
required:
- title
- sections
+ title: Snippet
type: object
SnippetSection:
properties:
code:
- nullable: true
- type: string
+ anyOf:
+ - type: string
+ - type: 'null'
+ default: null
html:
- nullable: true
- type: string
+ anyOf:
+ - type: string
+ - type: 'null'
+ default: null
id:
type: string
required:
- id
+ title: SnippetSection
type: object
Snippets:
properties:
@@ -2652,6 +3027,20 @@ components:
type: array
required:
- snippets
+ title: Snippets
+ type: object
+ SnippetsConfig:
+ description: "Configuration for snippets.\n\n **Keys.**\n\n - `custom_path`:\
+ \ the path to the custom snippets directory"
+ properties:
+ custom_paths:
+ items:
+ type: string
+ type: array
+ include_default_snippets:
+ type: boolean
+ required: []
+ title: SnippetsConfig
type: object
StdinRequest:
properties:
@@ -2659,14 +3048,17 @@ components:
type: string
required:
- text
+ title: StdinRequest
type: object
StopRequest:
properties: {}
+ required: []
+ title: StopRequest
type: object
StoreConfig:
+ description: Configuration for cache stores.
properties:
args:
- additionalProperties: {}
type: object
type:
enum:
@@ -2674,26 +3066,46 @@ components:
- redis
- rest
- tiered
- type: string
+ required: []
+ title: StoreConfig
type: object
SuccessResponse:
properties:
success:
+ default: true
type: boolean
- required:
- - success
+ required: []
+ title: SuccessResponse
+ type: object
+ TyLanguageServerConfig:
+ description: 'Configuration options for Ty Language Server.
+
+
+ ty handles completion, hover, go-to-definition, and diagnostics,
+
+ but we only use it for diagnostics.'
+ properties:
+ enabled:
+ type: boolean
+ required: []
+ title: TyLanguageServerConfig
type: object
UnknownError:
properties:
+ error_type:
+ anyOf:
+ - type: string
+ - type: 'null'
+ default: null
msg:
type: string
type:
enum:
- unknown
- type: string
required:
- - msg
- type
+ - msg
+ title: UnknownError
type: object
UpdateCellCodes:
properties:
@@ -2707,29 +3119,35 @@ components:
items:
type: string
type: array
- name:
+ op:
enum:
- update-cell-codes
- type: string
required:
+ - op
- cell_ids
- codes
- code_is_stale
- - name
+ title: UpdateCellCodes
type: object
UpdateCellIdsRequest:
+ description: 'Update the cell ID ordering of the cells in the notebook.
+
+
+ Right now we send the entire list of cell IDs,
+
+ but in the future we might want to send change-deltas.'
properties:
cell_ids:
items:
type: string
type: array
- name:
+ op:
enum:
- update-cell-ids
- type: string
required:
+ - op
- cell_ids
- - name
+ title: UpdateCellIdsRequest
type: object
UpdateComponentValuesRequest:
properties:
@@ -2738,11 +3156,11 @@ components:
type: string
type: array
values:
- items: {}
type: array
required:
- objectIds
- values
+ title: UpdateComponentValuesRequest
type: object
VariableContext:
properties:
@@ -2755,6 +3173,7 @@ components:
- name
- valueType
- previewValue
+ title: VariableContext
type: object
VariableDeclaration:
properties:
@@ -2772,54 +3191,63 @@ components:
- name
- declared_by
- used_by
+ title: VariableDeclaration
type: object
VariableValue:
properties:
datatype:
- nullable: true
- type: string
+ anyOf:
+ - type: string
+ - type: 'null'
name:
type: string
value:
- nullable: true
- type: string
+ anyOf:
+ - type: string
+ - type: 'null'
required:
- name
+ - value
+ - datatype
+ title: VariableValue
type: object
VariableValues:
+ description: List of variables and their types/values.
properties:
- name:
+ op:
enum:
- variable-values
- type: string
variables:
items:
$ref: '#/components/schemas/VariableValue'
type: array
required:
+ - op
- variables
- - name
+ title: VariableValues
type: object
Variables:
+ description: List of variable declarations.
properties:
- name:
+ op:
enum:
- variables
- type: string
variables:
items:
$ref: '#/components/schemas/VariableDeclaration'
type: array
required:
+ - op
- variables
- - name
+ title: Variables
type: object
WorkspaceFilesRequest:
properties:
includeMarkdown:
+ default: false
type: boolean
- required:
- - includeMarkdown
+ required: []
+ title: WorkspaceFilesRequest
type: object
WorkspaceFilesResponse:
properties:
@@ -2832,10 +3260,61 @@ components:
required:
- root
- files
+ title: WorkspaceFilesResponse
+ type: object
+ _AppConfig:
+ description: "Program-specific configuration.\n\n Configuration for frontends\
+ \ or runtimes that is specific to\n a single marimo program."
+ properties:
+ app_title:
+ anyOf:
+ - type: string
+ - type: 'null'
+ default: null
+ auto_download:
+ items:
+ enum:
+ - html
+ - ipynb
+ - markdown
+ type: array
+ css_file:
+ anyOf:
+ - type: string
+ - type: 'null'
+ default: null
+ html_head_file:
+ anyOf:
+ - type: string
+ - type: 'null'
+ default: null
+ layout_file:
+ anyOf:
+ - type: string
+ - type: 'null'
+ default: null
+ sql_output:
+ default: auto
+ enum:
+ - auto
+ - lazy-polars
+ - native
+ - pandas
+ - polars
+ width:
+ default: compact
+ enum:
+ - columns
+ - compact
+ - full
+ - medium
+ - normal
+ required: []
+ title: _AppConfig
type: object
info:
title: marimo API
- version: 0.15.0
+ version: 0.15.2
openapi: 3.1.0
paths:
/@file/{filename_and_length}:
@@ -2848,13 +3327,13 @@ paths:
schema:
type: string
responses:
- 200:
+ '200':
content:
application/octet-stream:
schema:
type: string
description: Get a virtual file
- 404:
+ '404':
description: Invalid byte length in virtual file request
/api/ai/chat:
post:
@@ -2875,7 +3354,7 @@ paths:
description: The request body for AI completion
required: true
responses:
- 200:
+ '200':
content:
application/json:
schema:
@@ -2892,7 +3371,7 @@ paths:
description: The request body for AI inline completion
required: true
responses:
- 200:
+ '200':
content:
text/plain:
schema:
@@ -2908,7 +3387,7 @@ paths:
description: The request body for tool invocation
required: true
responses:
- 200:
+ '200':
content:
application/json:
schema:
@@ -2922,7 +3401,7 @@ paths:
schema:
$ref: '#/components/schemas/PreviewDatasetColumnRequest'
responses:
- 200:
+ '200':
content:
application/json:
schema:
@@ -2936,7 +3415,7 @@ paths:
schema:
$ref: '#/components/schemas/PreviewDataSourceConnectionRequest'
responses:
- 200:
+ '200':
content:
application/json:
schema:
@@ -2950,7 +3429,7 @@ paths:
schema:
$ref: '#/components/schemas/PreviewSQLTableRequest'
responses:
- 200:
+ '200':
content:
application/json:
schema:
@@ -2964,7 +3443,7 @@ paths:
schema:
$ref: '#/components/schemas/PreviewSQLTableListRequest'
responses:
- 200:
+ '200':
content:
application/json:
schema:
@@ -2973,7 +3452,7 @@ paths:
/api/documentation/snippets:
get:
responses:
- 200:
+ '200':
content:
application/json:
schema:
@@ -2987,13 +3466,13 @@ paths:
schema:
$ref: '#/components/schemas/ExportAsHTMLRequest'
responses:
- 200:
+ '200':
content:
application/json:
schema:
$ref: '#/components/schemas/SuccessResponse'
description: Export the notebook as HTML
- 400:
+ '400':
description: File must be saved before downloading
/api/export/auto_export/ipynb:
post:
@@ -3003,13 +3482,13 @@ paths:
schema:
$ref: '#/components/schemas/ExportAsIPYNBRequest'
responses:
- 200:
+ '200':
content:
application/json:
schema:
$ref: '#/components/schemas/SuccessResponse'
description: Export the notebook as IPYNB
- 400:
+ '400':
description: File must be saved before downloading
/api/export/auto_export/markdown:
post:
@@ -3019,13 +3498,13 @@ paths:
schema:
$ref: '#/components/schemas/ExportAsMarkdownRequest'
responses:
- 200:
+ '200':
content:
application/json:
schema:
$ref: '#/components/schemas/SuccessResponse'
description: Export the notebook as a markdown
- 400:
+ '400':
description: File must be saved before downloading
/api/export/html:
post:
@@ -3035,13 +3514,13 @@ paths:
schema:
$ref: '#/components/schemas/ExportAsHTMLRequest'
responses:
- 200:
+ '200':
content:
text/html:
schema:
type: string
description: Export the notebook as HTML
- 400:
+ '400':
description: File must be saved before downloading
/api/export/markdown:
post:
@@ -3051,13 +3530,13 @@ paths:
schema:
$ref: '#/components/schemas/ExportAsMarkdownRequest'
responses:
- 200:
+ '200':
content:
text/plain:
schema:
type: string
description: Export the notebook as a markdown
- 400:
+ '400':
description: File must be saved before downloading
/api/export/script:
post:
@@ -3067,13 +3546,13 @@ paths:
schema:
$ref: '#/components/schemas/ExportAsScriptRequest'
responses:
- 200:
+ '200':
content:
text/plain:
schema:
type: string
description: Export the notebook as a script
- 400:
+ '400':
description: File must be saved before downloading
/api/files/create:
post:
@@ -3083,7 +3562,7 @@ paths:
schema:
$ref: '#/components/schemas/FileCreateRequest'
responses:
- 200:
+ '200':
content:
application/json:
schema:
@@ -3097,7 +3576,7 @@ paths:
schema:
$ref: '#/components/schemas/FileDeleteRequest'
responses:
- 200:
+ '200':
content:
application/json:
schema:
@@ -3111,7 +3590,7 @@ paths:
schema:
$ref: '#/components/schemas/FileDetailsRequest'
responses:
- 200:
+ '200':
content:
application/json:
schema:
@@ -3125,7 +3604,7 @@ paths:
schema:
$ref: '#/components/schemas/FileListRequest'
responses:
- 200:
+ '200':
content:
application/json:
schema:
@@ -3139,7 +3618,7 @@ paths:
schema:
$ref: '#/components/schemas/FileMoveRequest'
responses:
- 200:
+ '200':
content:
application/json:
schema:
@@ -3153,7 +3632,7 @@ paths:
schema:
$ref: '#/components/schemas/FileOpenRequest'
responses:
- 200:
+ '200':
content:
application/json:
schema:
@@ -3167,7 +3646,7 @@ paths:
schema:
$ref: '#/components/schemas/FileUpdateRequest'
responses:
- 200:
+ '200':
content:
application/json:
schema:
@@ -3176,7 +3655,7 @@ paths:
/api/home/recent_files:
post:
responses:
- 200:
+ '200':
content:
application/json:
schema:
@@ -3185,7 +3664,7 @@ paths:
/api/home/running_notebooks:
post:
responses:
- 200:
+ '200':
content:
application/json:
schema:
@@ -3199,7 +3678,7 @@ paths:
schema:
$ref: '#/components/schemas/ShutdownSessionRequest'
responses:
- 200:
+ '200':
content:
application/json:
schema:
@@ -3213,7 +3692,7 @@ paths:
schema:
$ref: '#/components/schemas/OpenTutorialRequest'
responses:
- 200:
+ '200':
content:
application/json:
schema:
@@ -3227,7 +3706,7 @@ paths:
schema:
$ref: '#/components/schemas/WorkspaceFilesRequest'
responses:
- 200:
+ '200':
content:
application/json:
schema:
@@ -3241,7 +3720,7 @@ paths:
schema:
$ref: '#/components/schemas/CodeCompletionRequest'
responses:
- 200:
+ '200':
content:
application/json:
schema:
@@ -3255,7 +3734,7 @@ paths:
schema:
$ref: '#/components/schemas/CopyNotebookRequest'
responses:
- 200:
+ '200':
content:
text/plain:
schema:
@@ -3269,7 +3748,7 @@ paths:
schema:
$ref: '#/components/schemas/DeleteCellRequest'
responses:
- 200:
+ '200':
content:
application/json:
schema:
@@ -3283,7 +3762,7 @@ paths:
schema:
$ref: '#/components/schemas/FormatRequest'
responses:
- 200:
+ '200':
content:
application/json:
schema:
@@ -3297,7 +3776,7 @@ paths:
schema:
$ref: '#/components/schemas/FunctionCallRequest'
responses:
- 200:
+ '200':
content:
application/json:
schema:
@@ -3311,7 +3790,7 @@ paths:
schema:
$ref: '#/components/schemas/InstallMissingPackagesRequest'
responses:
- 200:
+ '200':
content:
application/json:
schema:
@@ -3325,7 +3804,7 @@ paths:
schema:
$ref: '#/components/schemas/InstantiateRequest'
responses:
- 200:
+ '200':
content:
application/json:
schema:
@@ -3334,7 +3813,7 @@ paths:
/api/kernel/interrupt:
post:
responses:
- 200:
+ '200':
content:
application/json:
schema:
@@ -3348,7 +3827,7 @@ paths:
schema:
$ref: '#/components/schemas/PdbRequest'
responses:
- 200:
+ '200':
content:
application/json:
schema:
@@ -3357,13 +3836,13 @@ paths:
/api/kernel/read_code:
post:
responses:
- 200:
+ '200':
content:
application/json:
schema:
$ref: '#/components/schemas/ReadCodeResponse'
description: Read the code from the server
- 400:
+ '400':
description: File must be saved before downloading
/api/kernel/rename:
post:
@@ -3373,7 +3852,7 @@ paths:
schema:
$ref: '#/components/schemas/RenameFileRequest'
responses:
- 200:
+ '200':
content:
application/json:
schema:
@@ -3382,7 +3861,7 @@ paths:
/api/kernel/restart_session:
post:
responses:
- 200:
+ '200':
content:
application/json:
schema:
@@ -3396,7 +3875,7 @@ paths:
schema:
$ref: '#/components/schemas/RunRequest'
responses:
- 200:
+ '200':
content:
application/json:
schema:
@@ -3411,7 +3890,7 @@ paths:
schema:
$ref: '#/components/schemas/SaveNotebookRequest'
responses:
- 200:
+ '200':
content:
text/plain:
schema:
@@ -3425,7 +3904,7 @@ paths:
schema:
$ref: '#/components/schemas/SaveAppConfigurationRequest'
responses:
- 200:
+ '200':
content:
text/plain:
schema:
@@ -3439,7 +3918,7 @@ paths:
schema:
$ref: '#/components/schemas/SaveUserConfigurationRequest'
responses:
- 200:
+ '200':
content:
application/json:
schema:
@@ -3454,7 +3933,7 @@ paths:
schema:
$ref: '#/components/schemas/ExecuteScratchpadRequest'
responses:
- 200:
+ '200':
content:
application/json:
schema:
@@ -3468,7 +3947,7 @@ paths:
schema:
$ref: '#/components/schemas/SetCellConfigRequest'
responses:
- 200:
+ '200':
content:
application/json:
schema:
@@ -3482,7 +3961,7 @@ paths:
schema:
$ref: '#/components/schemas/SetModelMessageRequest'
responses:
- 200:
+ '200':
content:
application/json:
schema:
@@ -3496,7 +3975,7 @@ paths:
schema:
$ref: '#/components/schemas/UpdateComponentValuesRequest'
responses:
- 200:
+ '200':
content:
application/json:
schema:
@@ -3505,7 +3984,7 @@ paths:
/api/kernel/shutdown:
post:
responses:
- 200:
+ '200':
content:
application/json:
schema:
@@ -3519,7 +3998,7 @@ paths:
schema:
$ref: '#/components/schemas/StdinRequest'
responses:
- 200:
+ '200':
content:
application/json:
schema:
@@ -3533,7 +4012,7 @@ paths:
schema:
$ref: '#/components/schemas/UpdateCellIdsRequest'
responses:
- 200:
+ '200':
content:
application/json:
schema:
@@ -3542,7 +4021,7 @@ paths:
/api/kernel/takeover:
post:
responses:
- 200:
+ '200':
content:
application/json:
schema:
@@ -3559,7 +4038,7 @@ paths:
schema:
$ref: '#/components/schemas/AddPackageRequest'
responses:
- 200:
+ '200':
content:
application/json:
schema:
@@ -3568,7 +4047,7 @@ paths:
/api/packages/list:
get:
responses:
- 200:
+ '200':
content:
application/json:
schema:
@@ -3582,7 +4061,7 @@ paths:
schema:
$ref: '#/components/schemas/RemovePackageRequest'
responses:
- 200:
+ '200':
content:
application/json:
schema:
@@ -3591,7 +4070,7 @@ paths:
/api/packages/tree:
get:
responses:
- 200:
+ '200':
content:
application/json:
schema:
@@ -3606,7 +4085,7 @@ paths:
$ref: '#/components/schemas/CreateSecretRequest'
required: true
responses:
- 200:
+ '200':
content:
application/json:
schema:
@@ -3615,7 +4094,7 @@ paths:
/api/secrets/delete:
post:
responses:
- 200:
+ '200':
content:
application/json:
schema:
@@ -3630,7 +4109,7 @@ paths:
$ref: '#/components/schemas/ListSecretKeysRequest'
required: true
responses:
- 200:
+ '200':
content:
application/json:
schema:
@@ -3639,7 +4118,7 @@ paths:
/api/status:
get:
responses:
- 200:
+ '200':
content:
application/json:
schema:
@@ -3669,7 +4148,7 @@ paths:
/api/status/connections:
get:
responses:
- 200:
+ '200':
content:
application/json:
schema:
@@ -3681,7 +4160,7 @@ paths:
/api/usage:
get:
responses:
- 200:
+ '200':
content:
application/json:
schema:
@@ -3761,7 +4240,7 @@ paths:
/api/version:
get:
responses:
- 200:
+ '200':
content:
text/plain:
schema:
@@ -3779,13 +4258,13 @@ paths:
type: string
type: object
responses:
- 200:
+ '200':
content:
text/html:
schema:
type: string
description: Login page
- 302:
+ '302':
description: Redirect to the next URL
headers:
Location:
diff --git a/packages/openapi/convert_types.sh b/packages/openapi/convert_types.sh
new file mode 100755
index 0000000000..61bbf25f89
--- /dev/null
+++ b/packages/openapi/convert_types.sh
@@ -0,0 +1,34 @@
+#!/usr/bin/env bash
+
+# Usage: ./convert_types.sh <path>
+# Replaces all occurrences of 'Record<string, never>' with 'Record<string, any>' in the given file or recursively in a directory.
+
+set -euo pipefail
+
+if [ $# -ne 1 ]; then
+ echo "Usage: $0 <file-or-directory>"
+ exit 1
+fi
+
+TARGET="$1"
+
+# Detect OS and set sed in-place flag accordingly
+if [[ "$OSTYPE" == "darwin"* ]]; then
+ # macOS requires empty string for backup
+ SED_INPLACE=(-i '')
+else
+ # Linux doesn't use backup extension
+ SED_INPLACE=(-i)
+fi
+
+if [ -d "$TARGET" ]; then
+ # Recursively find .ts files and replace in-place
+ find "$TARGET" -type f -name "*.ts" -print0 | xargs -0 sed "${SED_INPLACE[@]}" -e 's/Record<string, never>/Record<string, any>/g'
+elif [ -f "$TARGET" ]; then
+ sed "${SED_INPLACE[@]}" -e 's/Record<string, never>/Record<string, any>/g' "$TARGET"
+else
+ echo "Error: $TARGET is not a file or directory"
+ exit 1
+fi
+
+echo "Replacement complete."
diff --git a/packages/openapi/package.json b/packages/openapi/package.json
index 45b3d3a91e..8bc2357971 100644
--- a/packages/openapi/package.json
+++ b/packages/openapi/package.json
@@ -11,7 +11,7 @@
],
"scripts": {
"codegen": "pnpm run \"/^codegen:.*/\"",
- "codegen:api": "openapi-typescript ./api.yaml -o ./src/api.ts",
+ "codegen:api": "openapi-typescript ./api.yaml --default-non-nullable=false -o ./src/api.ts && ./convert_types.sh ./src/api.ts",
"codegen:session": "openapi-typescript ../../marimo/_schemas/generated/session.yaml -o ./src/session.ts",
"codegen:notebook": "openapi-typescript ../../marimo/_schemas/generated/notebook.yaml -o ./src/notebook.ts"
},
diff --git a/packages/openapi/src/api.ts b/packages/openapi/src/api.ts
index 65c619e34d..909f08eb37 100644
--- a/packages/openapi/src/api.ts
+++ b/packages/openapi/src/api.ts
@@ -2544,27 +2544,70 @@ export interface paths {
trace?: never;
};
}
-export type webhooks = Record<string, never>;
+export type webhooks = Record<string, any>;
export interface components {
schemas: {
+ /**
+ * AddPackageRequest
+ * @description This can be a remove package or a local package.
+ *
+ * Supported formats:
+ *
+ * httpx
+ * httpx==0.27.0
+ * httpx>=0.27.0
+ * git+https://github.com/encode/httpx
+ * https://files.pythonhosted.org/packages/5c/2d/3da5bdf4408b8b2800061c339f240c1802f2e82d55e50bd39c5a881f47f0/httpx-0.27.0.tar.gz
+ * /example/foo-0.1.0-py3-none-any.whl
+ */
AddPackageRequest: {
package: string;
+ /** @default false */
upgrade?: boolean | null;
};
+ /** AiCompletionContext */
AiCompletionContext: {
- plainText: string;
- schema: components["schemas"]["SchemaTable"][];
- variables: (components["schemas"]["VariableContext"] | string)[];
- };
+ /** @default */
+ plainText?: string;
+ /** @default [] */
+ schema?: components["schemas"]["SchemaTable"][];
+ /** @default [] */
+ variables?: (string | components["schemas"]["VariableContext"])[];
+ };
+ /** AiCompletionRequest */
AiCompletionRequest: {
code: string;
- context?: components["schemas"]["AiCompletionContext"];
+ /** @default null */
+ context?: null | components["schemas"]["AiCompletionContext"];
includeOtherCode: string;
- /** @enum {string} */
- language: "python" | "markdown" | "sql";
+ /**
+ * @default python
+ * @enum {unknown}
+ */
+ language?: "markdown" | "python" | "sql";
prompt: string;
+ /** @default null */
selectedText?: string | null;
};
+ /**
+ * AiConfig
+ * @description Configuration options for AI.
+ *
+ * **Keys.**
+ *
+ * - `rules`: custom rules to include in all AI completion prompts
+ * - `max_tokens`: the maximum number of tokens to use in AI completions
+ * - `mode`: the mode to use for AI completions. Can be one of: `"ask"` or `"manual"`
+ * - `models`: the models to use for AI completions
+ * - `open_ai`: the OpenAI config
+ * - `anthropic`: the Anthropic config
+ * - `google`: the Google AI config
+ * - `bedrock`: the Bedrock config
+ * - `azure`: the Azure config
+ * - `ollama`: the Ollama config
+ * - `github`: the GitHub config
+ * - `open_ai_compatible`: the OpenAI-compatible config
+ */
AiConfig: {
anthropic?: components["schemas"]["AnthropicConfig"];
azure?: components["schemas"]["OpenAiConfig"];
@@ -2572,856 +2615,1139 @@ export interface components {
github?: components["schemas"]["GitHubConfig"];
google?: components["schemas"]["GoogleAiConfig"];
max_tokens?: number;
- /** @enum {string} */
+ /** @enum {unknown} */
mode?: "ask" | "manual";
- models?: {
- autocomplete_model?: string;
- chat_model?: string;
- custom_models: string[];
- displayed_models: string[];
- edit_model?: string;
- };
+ models?: components["schemas"]["AiModelConfig"];
ollama?: components["schemas"]["OpenAiConfig"];
open_ai?: components["schemas"]["OpenAiConfig"];
open_ai_compatible?: components["schemas"]["OpenAiConfig"];
rules?: string;
};
+ /** AiInlineCompletionRequest */
AiInlineCompletionRequest: {
- /** @enum {string} */
- language: "python" | "markdown" | "sql";
+ /**
+ * @default python
+ * @enum {unknown}
+ */
+ language?: "markdown" | "python" | "sql";
prefix: string;
suffix: string;
};
+ /**
+ * AiModelConfig
+ * @description Configuration options for an AI model.
+ *
+ * **Keys.**
+ *
+ * - `chat_model`: the model to use for chat completions
+ * - `edit_model`: the model to use for edit completions
+ * - `autocomplete_model`: the model to use for code completion/autocomplete
+ * - `displayed_models`: a list of models to display in the UI
+ * - `custom_models`: a list of custom models to use that are not from the default list
+ */
+ AiModelConfig: {
+ autocomplete_model?: string;
+ chat_model?: string;
+ custom_models: string[];
+ displayed_models: string[];
+ edit_model?: string;
+ };
+ /** Alert */
Alert: {
description: string;
- /** @enum {string} */
- name: "alert";
+ /** @enum {unknown} */
+ op: "alert";
title: string;
- /** @enum {string|null} */
+ /** @default null */
variant?: "danger" | null;
};
+ /**
+ * AnthropicConfig
+ * @description Configuration options for Anthropic.
+ *
+ * **Keys.**
+ *
+ * - `api_key`: the Anthropic API key
+ */
AnthropicConfig: {
api_key?: string;
};
+ /** Banner */
Banner: {
- /** @enum {string|null} */
+ /** @default null */
action?: "restart" | null;
description: string;
- /** @enum {string} */
- name: "banner";
+ /** @enum {unknown} */
+ op: "banner";
title: string;
- /** @enum {string|null} */
+ /** @default null */
variant?: "danger" | null;
};
+ /** BaseResponse */
BaseResponse: {
success: boolean;
};
+ /**
+ * BasedpyrightServerConfig
+ * @description Configuration options for basedpyright Language Server.
+ *
+ * basedpyright handles completion, hover, go-to-definition, and diagnostics,
+ * but we only use it for diagnostics.
+ */
+ BasedpyrightServerConfig: {
+ enabled?: boolean;
+ };
+ /**
+ * BedrockConfig
+ * @description Configuration options for Bedrock.
+ *
+ * **Keys.**
+ *
+ * - `profile_name`: the AWS profile to use
+ * - `region_name`: the AWS region to use
+ * - `aws_access_key_id`: the AWS access key ID
+ * - `aws_secret_access_key`: the AWS secret access key
+ */
BedrockConfig: {
aws_access_key_id?: string;
aws_secret_access_key?: string;
profile_name?: string;
region_name?: string;
};
- /** @enum {string} */
+ /**
+ * CellChannel
+ * @description The channel of a cell's output.
+ * @enum {unknown}
+ */
CellChannel:
- | "stdout"
+ | "marimo-error"
+ | "media"
+ | "output"
+ | "pdb"
| "stderr"
| "stdin"
- | "pdb"
- | "output"
- | "marimo-error"
- | "media";
+ | "stdout";
+ /**
+ * CellConfig
+ * @description Internal representation of a cell's configuration.
+ * This is not part of the public API.
+ */
CellConfig: {
+ /** @default null */
column?: number | null;
- disabled: boolean;
- hide_code: boolean;
- };
+ /** @default false */
+ disabled?: boolean;
+ /** @default false */
+ hide_code?: boolean;
+ };
+ /**
+ * CellOp
+ * @description Op to transition a cell.
+ *
+ * A CellOp's data has some optional fields:
+ *
+ * output - a CellOutput
+ * console - a CellOutput (console msg to append), or a list of
+ * CellOutputs
+ * status - execution status
+ * stale_inputs - whether the cell has stale inputs (variables, modules, ...)
+ * run_id - the run associated with this cell.
+ * serialization - the serialization status of the cell
+ *
+ * Omitting a field means that its value should be unchanged!
+ *
+ * And one required field:
+ *
+ * cell_id - the cell id
+ */
CellOp: {
cell_id: string;
+ /** @default null */
console?:
- | (
- | components["schemas"]["CellOutput"]
- | components["schemas"]["CellOutput"][]
- )
- | null;
- /** @enum {string} */
- name: "cell-op";
- output?: components["schemas"]["CellOutput"];
+ | components["schemas"]["CellOutput"][]
+ | null
+ | components["schemas"]["CellOutput"];
+ /** @enum {unknown} */
+ op: "cell-op";
+ /** @default null */
+ output?: null | components["schemas"]["CellOutput"];
+ /** @default null */
run_id?: string | null;
+ /** @default null */
serialization?: string | null;
+ /** @default null */
stale_inputs?: boolean | null;
- status?: components["schemas"]["RuntimeState"];
- timestamp: number;
+ /** @default null */
+ status?: ("disabled-transitively" | "idle" | "queued" | "running") | null;
+ timestamp?: number;
};
+ /** CellOutput */
CellOutput: {
channel: components["schemas"]["CellChannel"];
data:
| string
- | components["schemas"]["Error"][]
- | {
- [key: string]: unknown;
- };
- mimetype: components["schemas"]["MimeType"];
- timestamp: number;
- };
+ | (
+ | components["schemas"]["SetupRootError"]
+ | components["schemas"]["CycleError"]
+ | components["schemas"]["MultipleDefinitionError"]
+ | components["schemas"]["ImportStarError"]
+ | components["schemas"]["MarimoAncestorStoppedError"]
+ | components["schemas"]["MarimoAncestorPreventedError"]
+ | components["schemas"]["MarimoExceptionRaisedError"]
+ | components["schemas"]["MarimoStrictExecutionError"]
+ | components["schemas"]["MarimoInterruptionError"]
+ | components["schemas"]["MarimoSyntaxError"]
+ | components["schemas"]["MarimoInternalError"]
+ | components["schemas"]["UnknownError"]
+ )[]
+ | Record<string, any>;
+ /** @enum {unknown} */
+ mimetype:
+ | "application/json"
+ | "application/vnd.jupyter.widget-view+json"
+ | "application/vnd.marimo+error"
+ | "application/vnd.marimo+mimebundle"
+ | "application/vnd.marimo+traceback"
+ | "application/vnd.vega.v5+json"
+ | "application/vnd.vegalite.v5+json"
+ | "image/avif"
+ | "image/bmp"
+ | "image/gif"
+ | "image/jpeg"
+ | "image/png"
+ | "image/svg+xml"
+ | "image/tiff"
+ | "text/csv"
+ | "text/html"
+ | "text/latex"
+ | "text/markdown"
+ | "text/plain"
+ | "video/mp4"
+ | "video/mpeg";
+ timestamp?: number;
+ };
+ /** ChatAttachment */
+ ChatAttachment: {
+ /** @default null */
+ content_type?: string | null;
+ /** @default attachment */
+ name?: string;
+ url: string;
+ };
+ /**
+ * ChatMessage
+ * @description A message in a chat.
+ */
+ ChatMessage: {
+ /** @default null */
+ attachments?: components["schemas"]["ChatAttachment"][] | null;
+ content: unknown;
+ /** @default null */
+ parts?: Record<string, any>[] | null;
+ /** @enum {unknown} */
+ role: "assistant" | "system" | "user";
+ };
+ /** ChatRequest */
ChatRequest: {
context: components["schemas"]["AiCompletionContext"];
includeOtherCode: string;
- messages: {
- attachments?:
- | {
- contentType?: string | null;
- name: string;
- url: string;
- }[]
- | null;
- content: {
- [key: string]: unknown;
- };
- parts?:
- | (
- | {
- text: string;
- /** @enum {string} */
- type: "text";
- }
- | {
- details: {
- signature?: string | null;
- text: string;
- /** @enum {string} */
- type: "text";
- }[];
- reasoning: string;
- /** @enum {string} */
- type: "reasoning";
- }
- | {
- toolInvocation: {
- args: {
- [key: string]: unknown;
- };
- result: unknown;
- /** @enum {string} */
- state: "result";
- step: number;
- toolCallId: string;
- toolName: string;
- };
- /** @enum {string} */
- type: "tool-invocation";
- }
- )[]
- | null;
- /** @enum {string} */
- role: "user" | "assistant" | "system";
- }[];
+ messages: components["schemas"]["ChatMessage"][];
+ /** @default null */
model?: string | null;
- variables?: (components["schemas"]["VariableContext"] | string)[] | null;
+ /** @default null */
+ variables?: (string | components["schemas"]["VariableContext"])[] | null;
};
+ /** CodeCompletionRequest */
CodeCompletionRequest: {
cellId: string;
document: string;
id: string;
};
+ /**
+ * ColumnStats
+ * @description Represents stats for a column in a data table.
+ */
ColumnStats: {
+ /** @default null */
false?: number | null;
- max?: components["schemas"]["NonNestedLiteral"];
- mean?: components["schemas"]["NonNestedLiteral"];
- median?: components["schemas"]["NonNestedLiteral"];
- min?: components["schemas"]["NonNestedLiteral"];
+ /** @default null */
+ max?: unknown | null;
+ /** @default null */
+ mean?: unknown | null;
+ /** @default null */
+ median?: unknown | null;
+ /** @default null */
+ min?: unknown | null;
+ /** @default null */
nulls?: number | null;
- p25?: components["schemas"]["NonNestedLiteral"];
- p5?: components["schemas"]["NonNestedLiteral"];
- p75?: components["schemas"]["NonNestedLiteral"];
- p95?: components["schemas"]["NonNestedLiteral"];
- std?: components["schemas"]["NonNestedLiteral"];
+ /** @default null */
+ p25?: unknown | null;
+ /** @default null */
+ p5?: unknown | null;
+ /** @default null */
+ p75?: unknown | null;
+ /** @default null */
+ p95?: unknown | null;
+ /** @default null */
+ std?: unknown | null;
+ /** @default null */
total?: number | null;
+ /** @default null */
true?: number | null;
+ /** @default null */
unique?: number | null;
};
+ /**
+ * CompletedRun
+ * @description Written on run completion (of submitted cells and their descendants.
+ */
CompletedRun: {
- /** @enum {string} */
- name: "completed-run";
+ /** @enum {unknown} */
+ op: "completed-run";
+ };
+ /**
+ * CompletionConfig
+ * @description Configuration for code completion.
+ *
+ * A dict with key/value pairs configuring code completion in the marimo
+ * editor.
+ *
+ * **Keys.**
+ *
+ * - `activate_on_typing`: if `False`, completion won't activate
+ * until the completion hotkey is entered
+ * - `copilot`: one of `"github"`, `"codeium"`, or `"custom"`
+ * - `codeium_api_key`: the Codeium API key
+ */
+ CompletionConfig: {
+ activate_on_typing: boolean;
+ api_key?: string | null;
+ base_url?: string | null;
+ codeium_api_key?: string | null;
+ copilot: boolean | ("codeium" | "custom" | "github");
+ model?: string | null;
};
+ /** CompletionOption */
+ CompletionOption: {
+ completion_info: string | null;
+ name: string;
+ type: string;
+ };
+ /**
+ * CompletionResult
+ * @description Code completion result.
+ */
CompletionResult: {
completion_id: string;
- /** @enum {string} */
- name: "completion-result";
- options: {
- completion_info?: string | null;
- name: string;
- type: string;
- }[];
+ /** @enum {unknown} */
+ op: "completion-result";
+ options: components["schemas"]["CompletionOption"][];
prefix_length: number;
};
+ /** CopyNotebookRequest */
CopyNotebookRequest: {
destination: string;
source: string;
};
+ /** CreateSecretRequest */
CreateSecretRequest: {
key: string;
name: string;
- /** @enum {string} */
- provider: "env" | "dotenv";
+ /** @enum {unknown} */
+ provider: "dotenv" | "env";
value: string;
};
+ /** CycleError */
CycleError: {
edges_with_vars: [string, string[], string][];
- /** @enum {string} */
+ /** @enum {unknown} */
type: "cycle";
};
+ /**
+ * DataColumnPreview
+ * @description Preview of a column in a dataset.
+ */
DataColumnPreview: {
+ /** @default null */
chart_code?: string | null;
+ /** @default null */
chart_spec?: string | null;
- column_name: string;
+ /** @default */
+ column_name?: string;
+ /** @default null */
error?: string | null;
+ /** @default null */
missing_packages?: string[] | null;
- /** @enum {string} */
- name: "data-column-preview";
- stats?: components["schemas"]["ColumnStats"];
- table_name: string;
- };
+ /** @enum {unknown} */
+ op: "data-column-preview";
+ /** @default null */
+ stats?: null | components["schemas"]["ColumnStats"];
+ /** @default */
+ table_name?: string;
+ };
+ /**
+ * DataSourceConnection
+ * @description Represents a data source connection.
+ *
+ * Attributes:
+ * source (str): The source of the data source connection. E.g 'postgres'.
+ * dialect (str): The dialect of the data source connection. E.g 'postgresql'.
+ * name (str): The name of the data source connection. E.g 'engine'.
+ * display_name (str): The display name of the data source connection. E.g 'PostgresQL (engine)'.
+ * databases (List[Database]): The databases in the data source connection.
+ * default_database (Optional[str]): The default database in the data source connection.
+ * default_schema (Optional[str]): The default schema in the data source connection.
+ */
DataSourceConnection: {
- databases: {
- dialect: string;
- engine?: string | null;
- name: string;
- schemas: {
- name: string;
- tables: components["schemas"]["DataTable"][];
- }[];
- }[];
+ databases: components["schemas"]["Database"][];
+ /** @default null */
default_database?: string | null;
+ /** @default null */
default_schema?: string | null;
dialect: string;
display_name: string;
name: string;
source: string;
};
+ /** DataSourceConnections */
DataSourceConnections: {
connections: components["schemas"]["DataSourceConnection"][];
- /** @enum {string} */
- name: "data-source-connections";
- };
+ /** @enum {unknown} */
+ op: "data-source-connections";
+ };
+ /**
+ * DataTable
+ * @description Represents a data table.
+ *
+ * Attributes:
+ * source_type (DataTableSource): Type of data source ('local', 'duckdb', 'connection').
+ * source (str): Can be dialect, or source db name.
+ * name (str): Name of the data table.
+ * num_rows (Optional[int]): Total number of rows in the table, if known.
+ * num_columns (Optional[int]): Total number of columns in the table, if known.
+ * variable_name (Optional[VariableName]): Variable name referencing this table in code.
+ * columns (List[DataTableColumn]): List of column definitions and metadata.
+ * engine (Optional[VariableName]): Database engine or connection handler, if any.
+ * type (DataTableType): Table type, either 'table' or 'view'. Defaults to 'table'.
+ * primary_keys (Optional[List[str]]): Column names used as primary keys, if any.
+ * indexes (Optional[List[str]]): Column names used as indexes, if any.
+ */
DataTable: {
columns: components["schemas"]["DataTableColumn"][];
+ /** @default null */
engine?: string | null;
+ /** @default null */
indexes?: string[] | null;
name: string;
- num_columns?: number | null;
- num_rows?: number | null;
+ num_columns: number | null;
+ num_rows: number | null;
+ /** @default null */
primary_keys?: string[] | null;
source: string;
- /** @enum {string} */
- source_type: "local" | "duckdb" | "connection" | "catalog";
- /** @enum {string} */
- type: "table" | "view";
- variable_name?: string | null;
- };
+ /** @enum {unknown} */
+ source_type: "catalog" | "connection" | "duckdb" | "local";
+ /**
+ * @default table
+ * @enum {unknown}
+ */
+ type?: "table" | "view";
+ variable_name: string | null;
+ };
+ /**
+ * DataTableColumn
+ * @description Represents a column in a data table.
+ *
+ * Attributes:
+ * name (str): The name of the column.
+ * type (DataType): The data type of the column.
+ * external_type (ExternalDataType): The raw data type of the column.
+ * sample_values (List[Any]): The sample values of the column.
+ */
DataTableColumn: {
external_type: string;
name: string;
sample_values: unknown[];
- type: components["schemas"]["DataType"];
- };
- /** @enum {string} */
- DataType:
- | "string"
- | "boolean"
- | "integer"
- | "number"
- | "date"
- | "datetime"
- | "time"
- | "unknown";
+ /** @enum {unknown} */
+ type:
+ | "boolean"
+ | "date"
+ | "datetime"
+ | "integer"
+ | "number"
+ | "string"
+ | "time"
+ | "unknown";
+ };
+ /**
+ * Database
+ * @description Represents a collection of schemas.
+ *
+ * Attributes:
+ * name (str): The name of the database
+ * dialect (str): The dialect of the database
+ * schemas (List[Schema]): List of schemas in the database
+ * engine (Optional[VariableName]): Database engine or connection handler, if any.
+ */
Database: {
dialect: string;
+ /** @default null */
engine?: string | null;
name: string;
schemas: components["schemas"]["Schema"][];
};
+ /**
+ * Datasets
+ * @description List of datasets.
+ */
Datasets: {
- /** @enum {string|null} */
- clear_channel?: "local" | "duckdb" | "connection" | "catalog" | null;
- /** @enum {string} */
- name: "datasets";
+ /** @default null */
+ clear_channel?: ("catalog" | "connection" | "duckdb" | "local") | null;
+ /** @enum {unknown} */
+ op: "datasets";
tables: components["schemas"]["DataTable"][];
};
+ /**
+ * DatasourcesConfig
+ * @description Configuration for datasources panel.
+ *
+ * **Keys.**
+ *
+ * - `auto_discover_schemas`: if `True`, include schemas in the datasource
+ * - `auto_discover_tables`: if `True`, include tables in the datasource
+ * - `auto_discover_columns`: if `True`, include columns & table metadata in the datasource
+ */
+ DatasourcesConfig: {
+ auto_discover_columns?: boolean | "auto";
+ auto_discover_schemas?: boolean | "auto";
+ auto_discover_tables?: boolean | "auto";
+ };
+ /** DeleteCellRequest */
DeleteCellRequest: {
cellId: string;
};
+ /** DeleteSecretRequest */
DeleteSecretRequest: {
key: string;
};
+ /** DependencyTreeNode */
DependencyTreeNode: {
dependencies: components["schemas"]["DependencyTreeNode"][];
name: string;
tags: {
[key: string]: string;
}[];
- version?: string | null;
+ version: string | null;
};
+ /** DependencyTreeResponse */
DependencyTreeResponse: {
- tree?: components["schemas"]["DependencyTreeNode"];
- };
- Error:
- | components["schemas"]["SetupRootError"]
- | components["schemas"]["CycleError"]
- | components["schemas"]["MultipleDefinitionError"]
- | components["schemas"]["ImportStarError"]
- | components["schemas"]["MarimoAncestorStoppedError"]
- | components["schemas"]["MarimoAncestorPreventedError"]
- | components["schemas"]["MarimoExceptionRaisedError"]
- | components["schemas"]["MarimoStrictExecutionError"]
- | components["schemas"]["MarimoInterruptionError"]
- | components["schemas"]["MarimoSyntaxError"]
- | components["schemas"]["MarimoInternalError"]
- | components["schemas"]["UnknownError"];
+ tree: null | components["schemas"]["DependencyTreeNode"];
+ };
+ /**
+ * DiagnosticsConfig
+ * @description Configuration options for diagnostics.
+ *
+ * **Keys.**
+ *
+ * - `enabled`: if `True`, diagnostics will be shown in the editor
+ */
+ DiagnosticsConfig: {
+ enabled?: boolean;
+ };
+ /**
+ * DisplayConfig
+ * @description Configuration for display.
+ *
+ * **Keys.**
+ *
+ * - `theme`: `"light"`, `"dark"`, or `"system"`
+ * - `code_editor_font_size`: font size for the code editor
+ * - `cell_output`: `"above"` or `"below"`
+ * - `dataframes`: `"rich"` or `"plain"`
+ * - `custom_css`: list of paths to custom CSS files
+ * - `default_table_page_size`: default number of rows to display in tables
+ * - `default_table_max_columns`: default maximum number of columns to display in tables
+ * - `reference_highlighting`: if `True`, highlight reactive variable references
+ */
+ DisplayConfig: {
+ /** @enum {unknown} */
+ cell_output: "above" | "below";
+ code_editor_font_size: number;
+ custom_css?: string[];
+ /** @enum {unknown} */
+ dataframes: "plain" | "rich";
+ default_table_max_columns: number;
+ default_table_page_size: number;
+ /** @enum {unknown} */
+ default_width: "columns" | "compact" | "full" | "medium" | "normal";
+ reference_highlighting?: boolean;
+ /** @enum {unknown} */
+ theme: "dark" | "light" | "system";
+ };
+ /** ExecuteMultipleRequest */
ExecuteMultipleRequest: {
cellIds: string[];
codes: string[];
- request?: components["schemas"]["HTTPRequest"];
- timestamp: number;
+ /** @default null */
+ request?: components["schemas"]["HTTPRequest"] | null;
+ timestamp?: number;
};
+ /** ExecuteScratchpadRequest */
ExecuteScratchpadRequest: {
code: string;
- request?: components["schemas"]["HTTPRequest"];
+ /** @default null */
+ request?: components["schemas"]["HTTPRequest"] | null;
};
+ /** ExecuteStaleRequest */
ExecuteStaleRequest: {
- request?: components["schemas"]["HTTPRequest"];
+ /** @default null */
+ request?: components["schemas"]["HTTPRequest"] | null;
};
+ /** ExecutionRequest */
ExecutionRequest: {
cellId: string;
code: string;
- request?: components["schemas"]["HTTPRequest"];
- timestamp: number;
+ /** @default null */
+ request?: components["schemas"]["HTTPRequest"] | null;
+ timestamp?: number;
};
+ /** ExportAsHTMLRequest */
ExportAsHTMLRequest: {
+ /** @default null */
assetUrl?: string | null;
download: boolean;
files: string[];
includeCode: boolean;
};
+ /** ExportAsIPYNBRequest */
ExportAsIPYNBRequest: {
download: boolean;
};
+ /** ExportAsMarkdownRequest */
ExportAsMarkdownRequest: {
download: boolean;
};
+ /** ExportAsScriptRequest */
ExportAsScriptRequest: {
download: boolean;
};
+ /** FileCreateRequest */
FileCreateRequest: {
+ /** @default null */
contents?: string | null;
name: string;
path: string;
- /** @enum {string} */
- type: "file" | "directory";
+ /** @enum {unknown} */
+ type: "directory" | "file";
};
+ /** FileCreateResponse */
FileCreateResponse: {
- info?: components["schemas"]["FileInfo"];
+ /** @default null */
+ info?: null | components["schemas"]["FileInfo"];
+ /** @default null */
message?: string | null;
success: boolean;
};
+ /** FileDeleteRequest */
FileDeleteRequest: {
path: string;
};
+ /** FileDeleteResponse */
FileDeleteResponse: {
+ /** @default null */
message?: string | null;
success: boolean;
};
+ /** FileDetailsRequest */
FileDetailsRequest: {
path: string;
};
+ /** FileDetailsResponse */
FileDetailsResponse: {
+ /** @default null */
contents?: string | null;
file: components["schemas"]["FileInfo"];
+ /** @default null */
mimeType?: string | null;
};
+ /** FileInfo */
FileInfo: {
- children: components["schemas"]["FileInfo"][];
+ /** @default [] */
+ children?: components["schemas"]["FileInfo"][];
id: string;
isDirectory: boolean;
isMarimoFile: boolean;
+ /** @default null */
lastModified?: number | null;
name: string;
path: string;
};
+ /** FileListRequest */
FileListRequest: {
+ /** @default null */
path?: string | null;
};
+ /** FileListResponse */
FileListResponse: {
files: components["schemas"]["FileInfo"][];
root: string;
};
+ /** FileMoveRequest */
FileMoveRequest: {
newPath: string;
path: string;
};
+ /** FileMoveResponse */
FileMoveResponse: {
- info?: components["schemas"]["FileInfo"];
+ /** @default null */
+ info?: null | components["schemas"]["FileInfo"];
+ /** @default null */
message?: string | null;
success: boolean;
};
+ /** FileOpenRequest */
FileOpenRequest: {
path: string;
};
+ /** FileUpdateRequest */
FileUpdateRequest: {
contents: string;
path: string;
};
+ /** FileUpdateResponse */
FileUpdateResponse: {
- info?: components["schemas"]["FileInfo"];
+ /** @default null */
+ info?: null | components["schemas"]["FileInfo"];
+ /** @default null */
message?: string | null;
success: boolean;
};
+ /** FocusCell */
FocusCell: {
cell_id: string;
- /** @enum {string} */
- name: "focus-cell";
+ /** @enum {unknown} */
+ op: "focus-cell";
};
+ /** FormatRequest */
FormatRequest: {
codes: {
[key: string]: string;
};
lineLength: number;
};
+ /** FormatResponse */
FormatResponse: {
codes: {
[key: string]: string;
};
};
+ /**
+ * FormattingConfig
+ * @description Configuration for code formatting.
+ *
+ * **Keys.**
+ *
+ * - `line_length`: max line length
+ */
+ FormattingConfig: {
+ line_length: number;
+ };
+ /** FunctionCallRequest */
FunctionCallRequest: {
- args: {
- [key: string]: unknown;
- };
+ args: Record<string, any>;
functionCallId: string;
functionName: string;
namespace: string;
};
+ /**
+ * FunctionCallResult
+ * @description Result of calling a function.
+ */
FunctionCallResult: {
function_call_id: string;
- /** @enum {string} */
- name: "function-call-result";
- return_value?:
- | (
- | {
- [key: string]: components["schemas"]["JSONType"];
- }
- | components["schemas"]["JSONType"][]
- | string
- | number
- | boolean
- | {
- [key: string]: unknown;
- }
- | components["schemas"]["MIME"]
- )
- | null;
+ /** @enum {unknown} */
+ op: "function-call-result";
+ return_value: unknown;
status: components["schemas"]["HumanReadableStatus"];
};
+ /**
+ * GitHubConfig
+ * @description Configuration options for GitHub.
+ *
+ * **Keys.**
+ *
+ * - `api_key`: the GitHub API token
+ * - `base_url`: the base URL for the API
+ */
GitHubConfig: {
api_key?: string;
base_url?: string;
};
+ /**
+ * GoogleAiConfig
+ * @description Configuration options for Google AI.
+ *
+ * **Keys.**
+ *
+ * - `api_key`: the Google AI API key
+ */
GoogleAiConfig: {
api_key?: string;
};
- HTTPRequest: null;
+ HTTPRequest: {
+ baseUrl: {
+ [key: string]: unknown;
+ };
+ cookies: {
+ [key: string]: string;
+ };
+ headers: {
+ [key: string]: string;
+ };
+ meta: {
+ [key: string]: unknown;
+ };
+ pathParams: {
+ [key: string]: unknown;
+ };
+ queryParams: {
+ [key: string]: string[];
+ };
+ url: {
+ [key: string]: unknown;
+ };
+ user: unknown;
+ };
+ /**
+ * HumanReadableStatus
+ * @description Human-readable status.
+ */
HumanReadableStatus: {
- /** @enum {string} */
- code: "ok" | "error";
+ /** @enum {unknown} */
+ code: "error" | "ok";
+ /** @default null */
message?: string | null;
+ /** @default null */
title?: string | null;
};
+ /** ImportStarError */
ImportStarError: {
msg: string;
- /** @enum {string} */
+ /** @enum {unknown} */
type: "import-star";
};
+ /** InstallMissingPackagesRequest */
InstallMissingPackagesRequest: {
manager: string;
versions: {
[key: string]: string;
};
};
+ /** InstallingPackageAlert */
InstallingPackageAlert: {
- /** @enum {string} */
- name: "installing-package-alert";
+ /** @enum {unknown} */
+ op: "installing-package-alert";
packages: {
- [key: string]: "queued" | "installing" | "installed" | "failed";
+ [key: string]: "failed" | "installed" | "installing" | "queued";
};
};
+ /** InstantiateRequest */
InstantiateRequest: {
- autoRun: boolean;
+ /** @default true */
+ autoRun?: boolean;
objectIds: string[];
values: unknown[];
};
+ /**
+ * Interrupted
+ * @description Written when the kernel is interrupted by the user.
+ */
Interrupted: {
- /** @enum {string} */
- name: "interrupted";
+ /** @enum {unknown} */
+ op: "interrupted";
};
+ /** InvokeAiToolRequest */
InvokeAiToolRequest: {
- arguments: {
- [key: string]: unknown;
- };
+ arguments: Record<string, any>;
toolName: string;
};
+ /** InvokeAiToolResponse */
InvokeAiToolResponse: {
+ /** @default null */
error?: string | null;
result: unknown;
success: boolean;
toolName: string;
};
- JSONType:
- | string
- | number
- | Record<string, never>
- | unknown[]
- | boolean
- | null;
+ /** KernelCapabilities */
+ KernelCapabilities: {
+ /** @default false */
+ basedpyright?: boolean;
+ /** @default false */
+ pylsp?: boolean;
+ /** @default false */
+ terminal?: boolean;
+ /** @default false */
+ ty?: boolean;
+ };
+ /**
+ * KernelReady
+ * @description Kernel is ready for execution.
+ */
KernelReady: {
- app_config: {
- app_title?: string | null;
- auto_download: ("html" | "markdown" | "ipynb")[];
- css_file?: string | null;
- html_head_file?: string | null;
- layout_file?: string | null;
- /** @enum {string} */
- sql_output: "polars" | "lazy-polars" | "pandas" | "native" | "auto";
- /** @enum {string} */
- width: "normal" | "compact" | "medium" | "full" | "columns";
- };
- capabilities: {
- basedpyright: boolean;
- pylsp: boolean;
- terminal: boolean;
- ty: boolean;
- };
+ app_config: components["schemas"]["_AppConfig"];
+ capabilities: components["schemas"]["KernelCapabilities"];
cell_ids: string[];
codes: string[];
configs: components["schemas"]["CellConfig"][];
kiosk: boolean;
- last_executed_code?: {
+ last_executed_code: {
[key: string]: string;
} | null;
- last_execution_time?: {
+ last_execution_time: {
[key: string]: number;
} | null;
- layout?: {
- data: {
- [key: string]: unknown;
- };
- type: string;
- } | null;
- /** @enum {string} */
- name: "kernel-ready";
+ layout: components["schemas"]["LayoutConfig"] | null;
names: string[];
+ /** @enum {unknown} */
+ op: "kernel-ready";
resumed: boolean;
- ui_values?: {
- [key: string]:
- | (
- | {
- [key: string]:
- | (
- | {
- [key: string]: components["schemas"]["JSONType"];
- }
- | components["schemas"]["JSONType"][]
- | string
- | number
- | boolean
- | {
- [key: string]: unknown;
- }
- | components["schemas"]["MIME"]
- )
- | null;
- }
- | (
- | (
- | {
- [key: string]: components["schemas"]["JSONType"];
- }
- | components["schemas"]["JSONType"][]
- | string
- | number
- | boolean
- | {
- [key: string]: unknown;
- }
- | components["schemas"]["MIME"]
- )
- | null
- )[]
- | string
- | number
- | boolean
- | {
- [key: string]: unknown;
- }
- | components["schemas"]["MIME"]
- )
- | null;
- } | null;
+ ui_values: Record<string, any> | null;
+ };
+ /**
+ * KeymapConfig
+ * @description Configuration for keymaps.
+ *
+ * **Keys.**
+ *
+ * - `preset`: one of `"default"` or `"vim"`
+ * - `overrides`: a dict of keymap actions to their keymap override
+ * - `vimrc`: path to a vimrc file to load keymaps from
+ * - `destructive_delete`: if `True`, allows deleting cells with content.
+ */
+ KeymapConfig: {
+ destructive_delete?: boolean;
+ overrides?: {
+ [key: string]: string;
+ };
+ /** @enum {unknown} */
+ preset: "default" | "vim";
+ vimrc?: string | null;
+ };
+ /** KnownUnions */
+ KnownUnions: {
+ /** @enum {unknown} */
+ data_type:
+ | "boolean"
+ | "date"
+ | "datetime"
+ | "integer"
+ | "number"
+ | "string"
+ | "time"
+ | "unknown";
+ error:
+ | components["schemas"]["SetupRootError"]
+ | components["schemas"]["CycleError"]
+ | components["schemas"]["MultipleDefinitionError"]
+ | components["schemas"]["ImportStarError"]
+ | components["schemas"]["MarimoAncestorStoppedError"]
+ | components["schemas"]["MarimoAncestorPreventedError"]
+ | components["schemas"]["MarimoExceptionRaisedError"]
+ | components["schemas"]["MarimoStrictExecutionError"]
+ | components["schemas"]["MarimoInterruptionError"]
+ | components["schemas"]["MarimoSyntaxError"]
+ | components["schemas"]["MarimoInternalError"]
+ | components["schemas"]["UnknownError"];
+ operation:
+ | components["schemas"]["CellOp"]
+ | components["schemas"]["FunctionCallResult"]
+ | components["schemas"]["SendUIElementMessage"]
+ | components["schemas"]["RemoveUIElements"]
+ | components["schemas"]["Reload"]
+ | components["schemas"]["Reconnected"]
+ | components["schemas"]["Interrupted"]
+ | components["schemas"]["CompletedRun"]
+ | components["schemas"]["KernelReady"]
+ | components["schemas"]["CompletionResult"]
+ | components["schemas"]["Alert"]
+ | components["schemas"]["Banner"]
+ | components["schemas"]["MissingPackageAlert"]
+ | components["schemas"]["InstallingPackageAlert"]
+ | components["schemas"]["Variables"]
+ | components["schemas"]["VariableValues"]
+ | components["schemas"]["QueryParamsSet"]
+ | components["schemas"]["QueryParamsAppend"]
+ | components["schemas"]["QueryParamsDelete"]
+ | components["schemas"]["QueryParamsClear"]
+ | components["schemas"]["Datasets"]
+ | components["schemas"]["DataColumnPreview"]
+ | components["schemas"]["SQLTablePreview"]
+ | components["schemas"]["SQLTableListPreview"]
+ | components["schemas"]["DataSourceConnections"]
+ | components["schemas"]["SecretKeysResult"]
+ | components["schemas"]["FocusCell"]
+ | components["schemas"]["UpdateCellCodes"]
+ | components["schemas"]["UpdateCellIdsRequest"];
+ };
+ /**
+ * LanguageServersConfig
+ * @description Configuration options for language servers.
+ *
+ * **Keys.**
+ *
+ * - `pylsp`: the pylsp config
+ */
+ LanguageServersConfig: {
+ basedpyright?: components["schemas"]["BasedpyrightServerConfig"];
+ pylsp?: components["schemas"]["PythonLanguageServerConfig"];
+ ty?: components["schemas"]["TyLanguageServerConfig"];
+ };
+ /** LayoutConfig */
+ LayoutConfig: {
+ data: Record<string, any>;
+ type: string;
};
+ /** ListPackagesResponse */
ListPackagesResponse: {
packages: components["schemas"]["PackageDescription"][];
};
+ /** ListSecretKeysRequest */
ListSecretKeysRequest: {
requestId: string;
};
+ /** ListSecretKeysResponse */
ListSecretKeysResponse: {
keys: components["schemas"]["SecretKeysWithProvider"][];
};
- MIME: Record<string, never>;
+ /**
+ * MIME
+ * @description Protocol for instantiating objects using marimo's media viewer.
+ *
+ * To implement this protocol, a class needs to define
+ * just one method, _mime_.
+ */
+ MIME: Record<string, any>;
+ /** MarimoAncestorPreventedError */
MarimoAncestorPreventedError: {
- blamed_cell?: string | null;
+ blamed_cell: string | null;
msg: string;
raising_cell: string;
- /** @enum {string} */
+ /** @enum {unknown} */
type: "ancestor-prevented";
};
+ /** MarimoAncestorStoppedError */
MarimoAncestorStoppedError: {
msg: string;
raising_cell: string;
- /** @enum {string} */
+ /** @enum {unknown} */
type: "ancestor-stopped";
};
+ /**
+ * MarimoConfig
+ * @description Configuration for the marimo editor
+ */
MarimoConfig: {
ai?: components["schemas"]["AiConfig"];
- completion: {
- activate_on_typing: boolean;
- api_key?: string | null;
- base_url?: string | null;
- codeium_api_key?: string | null;
- copilot: boolean | ("github" | "codeium" | "custom");
- model?: string | null;
- };
- datasources?: {
- auto_discover_columns?: boolean | "auto";
- auto_discover_schemas?: boolean | "auto";
- auto_discover_tables?: boolean | "auto";
- };
- diagnostics?: {
- enabled?: boolean;
- };
- display: {
- /** @enum {string} */
- cell_output: "above" | "below";
- code_editor_font_size: number;
- custom_css?: string[];
- /** @enum {string} */
- dataframes: "rich" | "plain";
- default_table_max_columns: number;
- default_table_page_size: number;
- /** @enum {string} */
- default_width: "normal" | "compact" | "medium" | "full" | "columns";
- reference_highlighting?: boolean;
- /** @enum {string} */
- theme: "light" | "dark" | "system";
- };
- experimental?:
- | {
- [key: string]: unknown;
- }
- | {
- cache?:
- | {
- args?: {
- [key: string]: unknown;
- };
- /** @enum {string} */
- type?: "file" | "redis" | "rest" | "tiered";
- }[]
- | components["schemas"]["StoreConfig"];
- /** @enum {string} */
- execution_type?: "relaxed" | "strict";
- inline_ai_tooltip?: boolean;
- markdown?: boolean;
- mcp_docs?: boolean;
- performant_table_charts?: boolean;
- rtc_v2?: boolean;
- sql_linter?: boolean;
- wasm_layouts?: boolean;
- };
- formatting: {
- line_length: number;
- };
- keymap: {
- destructive_delete?: boolean;
- overrides?: {
- [key: string]: string;
- };
- /** @enum {string} */
- preset: "default" | "vim";
- vimrc?: string | null;
- };
- language_servers?: {
- basedpyright?: {
- enabled?: boolean;
- };
- pylsp?: {
- enable_flake8?: boolean;
- enable_mypy?: boolean;
- enable_pydocstyle?: boolean;
- enable_pyflakes?: boolean;
- enable_pylint?: boolean;
- enable_ruff?: boolean;
- enabled?: boolean;
- };
- ty?: {
- enabled?: boolean;
- };
- };
- package_management: {
- /** @enum {string} */
- manager: "pip" | "rye" | "uv" | "poetry" | "pixi";
- };
- runtime: {
- auto_instantiate: boolean;
- /** @enum {string} */
- auto_reload: "off" | "lazy" | "autorun";
- default_auto_download?: ("html" | "markdown" | "ipynb")[];
- /** @enum {string} */
- default_sql_output:
- | "polars"
- | "lazy-polars"
- | "pandas"
- | "native"
- | "auto";
- dotenv?: string[];
- /** @enum {string} */
- on_cell_change: "lazy" | "autorun";
- output_max_bytes: number;
- pythonpath?: string[];
- reactive_tests: boolean;
- std_stream_max_bytes: number;
- /** @enum {string} */
- watcher_on_save: "lazy" | "autorun";
- };
- save: {
- /** @enum {string} */
- autosave: "off" | "after_delay";
- autosave_delay: number;
- format_on_save: boolean;
- };
- server: {
- browser: "default" | string;
- follow_symlink: boolean;
- };
- sharing?: {
- html?: boolean;
- wasm?: boolean;
- };
- snippets?: {
- custom_paths?: string[];
- include_default_snippets?: boolean;
- };
- };
+ completion: components["schemas"]["CompletionConfig"];
+ datasources?: components["schemas"]["DatasourcesConfig"];
+ diagnostics?: components["schemas"]["DiagnosticsConfig"];
+ display: components["schemas"]["DisplayConfig"];
+ experimental?: Record<string, any>;
+ formatting: components["schemas"]["FormattingConfig"];
+ keymap: components["schemas"]["KeymapConfig"];
+ language_servers?: components["schemas"]["LanguageServersConfig"];
+ package_management: components["schemas"]["PackageManagementConfig"];
+ runtime: components["schemas"]["RuntimeConfig"];
+ save: components["schemas"]["SaveConfig"];
+ server: components["schemas"]["ServerConfig"];
+ sharing?: components["schemas"]["SharingConfig"];
+ snippets?: components["schemas"]["SnippetsConfig"];
+ };
+ /** MarimoExceptionRaisedError */
MarimoExceptionRaisedError: {
exception_type: string;
msg: string;
- raising_cell?: string | null;
- /** @enum {string} */
+ raising_cell: string | null;
+ /** @enum {unknown} */
type: "exception";
};
+ /** MarimoFile */
MarimoFile: {
+ /** @default null */
initializationId?: string | null;
+ /** @default null */
lastModified?: number | null;
name: string;
path: string;
+ /** @default null */
sessionId?: string | null;
};
+ /**
+ * MarimoInternalError
+ * @description An internal error that should be hidden from the user.
+ * The error is logged to the console and then a new error is broadcasted
+ * such that the data is hidden.
+ *
+ * They can be linked back to the original error by the error_id.
+ */
MarimoInternalError: {
error_id: string;
- msg: string;
- /** @enum {string} */
+ /** @default */
+ msg?: string;
+ /** @enum {unknown} */
type: "internal";
};
+ /** MarimoInterruptionError */
MarimoInterruptionError: {
- /** @enum {string} */
+ /** @enum {unknown} */
type: "interruption";
};
+ /** MarimoStrictExecutionError */
MarimoStrictExecutionError: {
- blamed_cell?: string | null;
+ blamed_cell: string | null;
msg: string;
ref: string;
- /** @enum {string} */
+ /** @enum {unknown} */
type: "strict-exception";
};
+ /** MarimoSyntaxError */
MarimoSyntaxError: {
msg: string;
- /** @enum {string} */
+ /** @enum {unknown} */
type: "syntax";
};
- MessageOperation:
- | components["schemas"]["CellOp"]
- | components["schemas"]["FunctionCallResult"]
- | components["schemas"]["SendUIElementMessage"]
- | components["schemas"]["RemoveUIElements"]
- | components["schemas"]["Reload"]
- | components["schemas"]["Reconnected"]
- | components["schemas"]["Interrupted"]
- | components["schemas"]["CompletedRun"]
- | components["schemas"]["KernelReady"]
- | components["schemas"]["CompletionResult"]
- | components["schemas"]["Alert"]
- | components["schemas"]["Banner"]
- | components["schemas"]["MissingPackageAlert"]
- | components["schemas"]["InstallingPackageAlert"]
- | components["schemas"]["Variables"]
- | components["schemas"]["VariableValues"]
- | components["schemas"]["QueryParamsSet"]
- | components["schemas"]["QueryParamsAppend"]
- | components["schemas"]["QueryParamsDelete"]
- | components["schemas"]["QueryParamsClear"]
- | components["schemas"]["Datasets"]
- | components["schemas"]["DataColumnPreview"]
- | components["schemas"]["SQLTablePreview"]
- | components["schemas"]["SQLTableListPreview"]
- | components["schemas"]["DataSourceConnections"]
- | components["schemas"]["SecretKeysResult"]
- | components["schemas"]["FocusCell"]
- | components["schemas"]["UpdateCellCodes"]
- | components["schemas"]["UpdateCellIdsRequest"];
- /** @enum {string} */
- MimeType:
- | "application/json"
- | "application/vnd.marimo+error"
- | "application/vnd.marimo+traceback"
- | "application/vnd.marimo+mimebundle"
- | "application/vnd.vega.v5+json"
- | "application/vnd.vegalite.v5+json"
- | "application/vnd.jupyter.widget-view+json"
- | "image/png"
- | "image/svg+xml"
- | "image/tiff"
- | "image/avif"
- | "image/bmp"
- | "image/gif"
- | "image/jpeg"
- | "video/mp4"
- | "video/mpeg"
- | "text/html"
- | "text/plain"
- | "text/markdown"
- | "text/latex"
- | "text/csv";
+ /** MissingPackageAlert */
MissingPackageAlert: {
isolated: boolean;
- /** @enum {string} */
- name: "missing-package-alert";
+ /** @enum {unknown} */
+ op: "missing-package-alert";
packages: string[];
};
+ /** ModelMessage */
+ ModelMessage: {
+ bufferPaths: (string | number)[][];
+ state: Record<string, any>;
+ };
+ /** MultipleDefinitionError */
MultipleDefinitionError: {
cells: string[];
name: string;
- /** @enum {string} */
+ /** @enum {unknown} */
type: "multiple-defs";
};
- NonNestedLiteral: number | string | boolean;
+ /**
+ * OpenAiConfig
+ * @description Configuration options for OpenAI or OpenAI-compatible services.
+ *
+ * **Keys.**
+ *
+ * - `api_key`: the OpenAI API key
+ * - `base_url`: the base URL for the API
+ * - `ssl_verify` : Boolean argument for httpx passed to open ai client. httpx defaults to true, but some use cases to let users override to False in some testing scenarios
+ * - `ca_bundle_path`: custom ca bundle to be used for verifying SSL certificates. Used to create custom SSL context for httpx client
+ * - `client_pem` : custom path of a client .pem cert used for verifying identity of client server
+ * - `extra_headers`: extra headers to be passed to the OpenAI client
+ */
OpenAiConfig: {
api_key?: string;
base_url?: string;
@@ -3433,50 +3759,82 @@ export interface components {
model?: string;
ssl_verify?: boolean;
};
+ /** OpenTutorialRequest */
OpenTutorialRequest: {
tutorialId:
| (
- | "intro"
| "dataflow"
- | "ui"
+ | "fileformat"
+ | "for-jupyter-users"
+ | "intro"
+ | "layout"
| "markdown"
| "plots"
| "sql"
- | "layout"
- | "fileformat"
- | "for-jupyter-users"
+ | "ui"
)
| "markdown-format";
};
+ /** PackageDescription */
PackageDescription: {
name: string;
version: string;
};
+ /**
+ * PackageManagementConfig
+ * @description Configuration options for package management.
+ *
+ * **Keys.**
+ *
+ * - `manager`: the package manager to use
+ */
+ PackageManagementConfig: {
+ /** @enum {unknown} */
+ manager: "pip" | "pixi" | "poetry" | "rye" | "uv";
+ };
+ /** PackageOperationResponse */
PackageOperationResponse: {
+ /** @default null */
error?: string | null;
success: boolean;
};
+ /** PdbRequest */
PdbRequest: {
cellId: string;
- request?: components["schemas"]["HTTPRequest"];
+ /** @default null */
+ request?: components["schemas"]["HTTPRequest"] | null;
};
+ /**
+ * PreviewDataSourceConnectionRequest
+ * @description Fetch a datasource connection
+ */
PreviewDataSourceConnectionRequest: {
engine: string;
};
+ /** PreviewDatasetColumnRequest */
PreviewDatasetColumnRequest: {
columnName: string;
+ /** @default null */
fullyQualifiedTableName?: string | null;
source: string;
- /** @enum {string} */
- sourceType: "local" | "duckdb" | "connection" | "catalog";
+ /** @enum {unknown} */
+ sourceType: "catalog" | "connection" | "duckdb" | "local";
tableName: string;
};
+ /**
+ * PreviewSQLTableListRequest
+ * @description Preview list of tables in an SQL schema
+ */
PreviewSQLTableListRequest: {
database: string;
engine: string;
requestId: string;
schema: string;
};
+ /**
+ * PreviewSQLTableRequest
+ * @description Preview table details in an SQL database
+ */
PreviewSQLTableRequest: {
database: string;
engine: string;
@@ -3484,247 +3842,499 @@ export interface components {
schema: string;
tableName: string;
};
+ /**
+ * PythonLanguageServerConfig
+ * @description Configuration options for Python Language Server.
+ *
+ * pylsp handles completion, hover, go-to-definition, and diagnostics.
+ */
+ PythonLanguageServerConfig: {
+ enable_flake8?: boolean;
+ enable_mypy?: boolean;
+ enable_pydocstyle?: boolean;
+ enable_pyflakes?: boolean;
+ enable_pylint?: boolean;
+ enable_ruff?: boolean;
+ enabled?: boolean;
+ };
+ /** QueryParamsAppend */
QueryParamsAppend: {
key: string;
- /** @enum {string} */
- name: "query-params-append";
+ /** @enum {unknown} */
+ op: "query-params-append";
value: string;
};
+ /** QueryParamsClear */
QueryParamsClear: {
- /** @enum {string} */
- name: "query-params-clear";
+ /** @enum {unknown} */
+ op: "query-params-clear";
};
+ /** QueryParamsDelete */
QueryParamsDelete: {
key: string;
- /** @enum {string} */
- name: "query-params-delete";
- value?: string | null;
- };
+ /** @enum {unknown} */
+ op: "query-params-delete";
+ value: string | null;
+ };
+ /**
+ * QueryParamsSet
+ * @description Set query parameters.
+ */
QueryParamsSet: {
key: string;
- /** @enum {string} */
- name: "query-params-set";
+ /** @enum {unknown} */
+ op: "query-params-set";
value: string | string[];
};
+ /** ReadCodeResponse */
ReadCodeResponse: {
contents: string;
};
+ /** RecentFilesResponse */
RecentFilesResponse: {
files: components["schemas"]["MarimoFile"][];
};
+ /** Reconnected */
Reconnected: {
- /** @enum {string} */
- name: "reconnected";
+ /** @enum {unknown} */
+ op: "reconnected";
};
+ /** Reload */
Reload: {
- /** @enum {string} */
- name: "reload";
+ /** @enum {unknown} */
+ op: "reload";
};
+ /** RemovePackageRequest */
RemovePackageRequest: {
package: string;
};
+ /**
+ * RemoveUIElements
+ * @description Invalidate UI elements for a given cell.
+ */
RemoveUIElements: {
cell_id: string;
- /** @enum {string} */
- name: "remove-ui-elements";
+ /** @enum {unknown} */
+ op: "remove-ui-elements";
};
+ /** RenameFileRequest */
RenameFileRequest: {
filename: string;
};
+ /** RenameRequest */
RenameRequest: {
filename: string;
};
+ /** RunRequest */
RunRequest: {
cellIds: string[];
codes: string[];
- request?: components["schemas"]["HTTPRequest"];
+ /** @default null */
+ request?: components["schemas"]["HTTPRequest"] | null;
};
+ /** RunningNotebooksResponse */
RunningNotebooksResponse: {
files: components["schemas"]["MarimoFile"][];
};
- /** @enum {string} */
- RuntimeState: "idle" | "queued" | "running" | "disabled-transitively";
+ /**
+ * RuntimeConfig
+ * @description Configuration for runtime.
+ *
+ * **Keys.**
+ *
+ * - `auto_instantiate`: if `False`, cells won't automatically
+ * run on startup. This only applies when editing a notebook,
+ * and not when running as an application.
+ * The default is `True`.
+ * - `auto_reload`: if `lazy`, cells importing modified modules will marked
+ * as stale; if `autorun`, affected cells will be automatically run. similar
+ * to IPython's %autoreload extension but with more code intelligence.
+ * - `reactive_tests`: if `True`, marimo will automatically run pytest on cells containing only test functions and test classes.
+ * execution.
+ * - `on_cell_change`: if `lazy`, cells will be marked stale when their
+ * ancestors run but won't autorun; if `autorun`, cells will automatically
+ * run when their ancestors run.
+ * - `execution_type`: if `relaxed`, marimo will not clone cell declarations;
+ * if `strict` marimo will clone cell declarations by default, avoiding
+ * hidden potential state build up.
+ * - `watcher_on_save`: how to handle file changes when saving. `"lazy"` marks
+ * affected cells as stale, `"autorun"` automatically runs affected cells.
+ * - `output_max_bytes`: the maximum size in bytes of cell outputs; larger
+ * values may affect frontend performance
+ * - `std_stream_max_bytes`: the maximum size in bytes of console outputs;
+ * larger values may affect frontend performance
+ * - `pythonpath`: a list of directories to add to the Python search path.
+ * Directories will be added to the head of sys.path. Similar to the
+ * `PYTHONPATH` environment variable, the directories will be included in
+ * where Python will look for imported modules.
+ * - `dotenv`: a list of paths to `.env` files to load.
+ * If the file does not exist, it will be silently ignored.
+ * The default is `[".env"]` if a pyproject.toml is found, otherwise `[]`.
+ * - `default_sql_output`: the default output format for SQL queries. Can be one of:
+ * `"auto"`, `"native"`, `"polars"`, `"lazy-polars"`, or `"pandas"`.
+ * The default is `"auto"`.
+ * - `default_auto_download`: an Optional list of export types to automatically snapshot your notebook as:
+ * `html`, `markdown`, `ipynb`.
+ * The default is None.
+ */
+ RuntimeConfig: {
+ auto_instantiate: boolean;
+ /** @enum {unknown} */
+ auto_reload: "autorun" | "lazy" | "off";
+ default_auto_download?: ("html" | "ipynb" | "markdown")[];
+ /** @enum {unknown} */
+ default_sql_output:
+ | "auto"
+ | "lazy-polars"
+ | "native"
+ | "pandas"
+ | "polars";
+ dotenv?: string[];
+ /** @enum {unknown} */
+ on_cell_change: "autorun" | "lazy";
+ output_max_bytes: number;
+ pythonpath?: string[];
+ reactive_tests: boolean;
+ std_stream_max_bytes: number;
+ /** @enum {unknown} */
+ watcher_on_save: "autorun" | "lazy";
+ };
+ /**
+ * SQLTableListPreview
+ * @description Preview of a list of tables in a schema.
+ */
SQLTableListPreview: {
+ /** @default null */
error?: string | null;
- /** @enum {string} */
- name: "sql-table-list-preview";
+ /** @enum {unknown} */
+ op: "sql-table-list-preview";
request_id: string;
- tables: components["schemas"]["DataTable"][];
+ /** @default [] */
+ tables?: components["schemas"]["DataTable"][];
};
+ /**
+ * SQLTablePreview
+ * @description Preview of a table in a SQL database.
+ */
SQLTablePreview: {
+ /** @default null */
error?: string | null;
- /** @enum {string} */
- name: "sql-table-preview";
+ /** @enum {unknown} */
+ op: "sql-table-preview";
request_id: string;
- table?: components["schemas"]["DataTable"];
+ table: null | components["schemas"]["DataTable"];
};
+ /** SaveAppConfigurationRequest */
SaveAppConfigurationRequest: {
- config: {
- [key: string]: unknown;
- };
- };
+ config: Record<string, any>;
+ };
+ /**
+ * SaveConfig
+ * @description Configuration for saving.
+ *
+ * **Keys.**
+ *
+ * - `autosave`: one of `"off"` or `"after_delay"`
+ * - `delay`: number of milliseconds to wait before autosaving
+ * - `format_on_save`: if `True`, format the code on save
+ */
+ SaveConfig: {
+ /** @enum {unknown} */
+ autosave: "after_delay" | "off";
+ autosave_delay: number;
+ format_on_save: boolean;
+ };
+ /** SaveNotebookRequest */
SaveNotebookRequest: {
cellIds: string[];
codes: string[];
configs: components["schemas"]["CellConfig"][];
filename: string;
- layout?: {
- [key: string]: unknown;
- } | null;
+ /** @default null */
+ layout?: Record<string, any> | null;
names: string[];
- persist: boolean;
+ /** @default true */
+ persist?: boolean;
};
+ /** SaveUserConfigurationRequest */
SaveUserConfigurationRequest: {
- config: components["schemas"]["MarimoConfig"];
+ config: Record<string, any>;
};
+ /** Schema */
Schema: {
name: string;
tables: components["schemas"]["DataTable"][];
};
+ /** SchemaColumn */
SchemaColumn: {
name: string;
sampleValues: unknown[];
type: string;
};
+ /** SchemaTable */
SchemaTable: {
columns: components["schemas"]["SchemaColumn"][];
name: string;
};
+ /**
+ * SecretKeysResult
+ * @description Result of listing secret keys.
+ */
SecretKeysResult: {
- /** @enum {string} */
- name: "secret-keys-result";
+ /** @enum {unknown} */
+ op: "secret-keys-result";
request_id: string;
secrets: components["schemas"]["SecretKeysWithProvider"][];
};
+ /** SecretKeysWithProvider */
SecretKeysWithProvider: {
keys: string[];
name: string;
- /** @enum {string} */
- provider: "env" | "dotenv";
+ /** @enum {unknown} */
+ provider: "dotenv" | "env";
};
+ /**
+ * SendUIElementMessage
+ * @description Send a message to a UI element.
+ */
SendUIElementMessage: {
+ /** @default null */
buffers?: string[] | null;
- message: {
- [key: string]: unknown;
- };
- model_id?: string | null;
- /** @enum {string} */
- name: "send-ui-element-message";
- ui_element?: string | null;
- };
+ message: Record<string, any>;
+ model_id: string | null;
+ /** @enum {unknown} */
+ op: "send-ui-element-message";
+ ui_element: string | null;
+ };
+ /**
+ * ServerConfig
+ * @description Configuration for the server.
+ *
+ * **Keys.**
+ *
+ * - `browser`: the web browser to use. `"default"` or a browser registered
+ * with Python's webbrowser module (eg, `"firefox"` or `"chrome"`)
+ * - `follow_symlink`: if true, the server will follow symlinks it finds
+ * inside its static assets directory.
+ */
+ ServerConfig: {
+ browser: "default" | string;
+ follow_symlink: boolean;
+ };
+ /** SetCellConfigRequest */
SetCellConfigRequest: {
configs: {
- [key: string]: {
- [key: string]: unknown;
- };
+ [key: string]: Record<string, any>;
};
};
+ /** SetModelMessageRequest */
SetModelMessageRequest: {
+ /** @default null */
buffers?: string[] | null;
- message: {
- bufferPaths: (string | number)[][];
- state: {
- [key: string]: unknown;
- };
- };
+ message: components["schemas"]["ModelMessage"];
modelId: string;
};
+ /** SetUIElementValueRequest */
SetUIElementValueRequest: {
objectIds: string[];
- request?: components["schemas"]["HTTPRequest"];
- token: string;
+ /** @default null */
+ request?: components["schemas"]["HTTPRequest"] | null;
+ token?: string;
values: unknown[];
};
+ /** SetUserConfigRequest */
SetUserConfigRequest: {
config: components["schemas"]["MarimoConfig"];
};
+ /** SetupRootError */
SetupRootError: {
edges_with_vars: [string, string[], string][];
- /** @enum {string} */
+ /** @enum {unknown} */
type: "setup-refs";
};
+ /**
+ * SharingConfig
+ * @description Configuration for sharing features.
+ *
+ * **Keys.**
+ *
+ * - `html`: if `False`, HTML sharing options will be hidden from the UI
+ * - `wasm`: if `False`, WebAssembly sharing options will be hidden from the UI
+ */
+ SharingConfig: {
+ html?: boolean;
+ wasm?: boolean;
+ };
+ /** ShutdownSessionRequest */
ShutdownSessionRequest: {
sessionId: string;
};
+ /** Snippet */
Snippet: {
sections: components["schemas"]["SnippetSection"][];
title: string;
};
+ /** SnippetSection */
SnippetSection: {
+ /** @default null */
code?: string | null;
+ /** @default null */
html?: string | null;
id: string;
};
+ /** Snippets */
Snippets: {
snippets: components["schemas"]["Snippet"][];
};
+ /**
+ * SnippetsConfig
+ * @description Configuration for snippets.
+ *
+ * **Keys.**
+ *
+ * - `custom_path`: the path to the custom snippets directory
+ */
+ SnippetsConfig: {
+ custom_paths?: string[];
+ include_default_snippets?: boolean;
+ };
+ /** StdinRequest */
StdinRequest: {
text: string;
};
- StopRequest: Record<string, never>;
+ /** StopRequest */
+ StopRequest: Record<string, any>;
+ /**
+ * StoreConfig
+ * @description Configuration for cache stores.
+ */
StoreConfig: {
- args?: {
- [key: string]: unknown;
- };
- /** @enum {string} */
+ args?: Record<string, any>;
+ /** @enum {unknown} */
type?: "file" | "redis" | "rest" | "tiered";
};
+ /** SuccessResponse */
SuccessResponse: {
- success: boolean;
- };
+ /** @default true */
+ success?: boolean;
+ };
+ /**
+ * TyLanguageServerConfig
+ * @description Configuration options for Ty Language Server.
+ *
+ * ty handles completion, hover, go-to-definition, and diagnostics,
+ * but we only use it for diagnostics.
+ */
+ TyLanguageServerConfig: {
+ enabled?: boolean;
+ };
+ /** UnknownError */
UnknownError: {
+ /** @default null */
+ error_type?: string | null;
msg: string;
- /** @enum {string} */
+ /** @enum {unknown} */
type: "unknown";
};
+ /** UpdateCellCodes */
UpdateCellCodes: {
cell_ids: string[];
code_is_stale: boolean;
codes: string[];
- /** @enum {string} */
- name: "update-cell-codes";
- };
+ /** @enum {unknown} */
+ op: "update-cell-codes";
+ };
+ /**
+ * UpdateCellIdsRequest
+ * @description Update the cell ID ordering of the cells in the notebook.
+ *
+ * Right now we send the entire list of cell IDs,
+ * but in the future we might want to send change-deltas.
+ */
UpdateCellIdsRequest: {
cell_ids: string[];
- /** @enum {string} */
- name: "update-cell-ids";
+ /** @enum {unknown} */
+ op: "update-cell-ids";
};
+ /** UpdateComponentValuesRequest */
UpdateComponentValuesRequest: {
objectIds: string[];
values: unknown[];
};
+ /** VariableContext */
VariableContext: {
name: string;
previewValue: unknown;
valueType: string;
};
+ /** VariableDeclaration */
VariableDeclaration: {
declared_by: string[];
name: string;
used_by: string[];
};
+ /** VariableValue */
VariableValue: {
- datatype?: string | null;
+ datatype: string | null;
name: string;
- value?: string | null;
+ value: string | null;
};
+ /**
+ * VariableValues
+ * @description List of variables and their types/values.
+ */
VariableValues: {
- /** @enum {string} */
- name: "variable-values";
+ /** @enum {unknown} */
+ op: "variable-values";
variables: components["schemas"]["VariableValue"][];
};
+ /**
+ * Variables
+ * @description List of variable declarations.
+ */
Variables: {
- /** @enum {string} */
- name: "variables";
+ /** @enum {unknown} */
+ op: "variables";
variables: components["schemas"]["VariableDeclaration"][];
};
+ /** WorkspaceFilesRequest */
WorkspaceFilesRequest: {
- includeMarkdown: boolean;
+ /** @default false */
+ includeMarkdown?: boolean;
};
+ /** WorkspaceFilesResponse */
WorkspaceFilesResponse: {
files: components["schemas"]["FileInfo"][];
root: string;
};
+ /**
+ * _AppConfig
+ * @description Program-specific configuration.
+ *
+ * Configuration for frontends or runtimes that is specific to
+ * a single marimo program.
+ */
+ _AppConfig: {
+ /** @default null */
+ app_title?: string | null;
+ auto_download?: ("html" | "ipynb" | "markdown")[];
+ /** @default null */
+ css_file?: string | null;
+ /** @default null */
+ html_head_file?: string | null;
+ /** @default null */
+ layout_file?: string | null;
+ /**
+ * @default auto
+ * @enum {unknown}
+ */
+ sql_output?: "auto" | "lazy-polars" | "native" | "pandas" | "polars";
+ /**
+ * @default compact
+ * @enum {unknown}
+ */
+ width?: "columns" | "compact" | "full" | "medium" | "normal";
+ };
};
responses: never;
parameters: never;
@@ -3732,5 +4342,5 @@ export interface components {
headers: never;
pathItems: never;
}
-export type $defs = Record<string, never>;
-export type operations = Record<string, never>;
+export type $defs = Record<string, any>;
+export type operations = Record<string, any>;
diff --git a/pixi.lock b/pixi.lock
index bdb608cfc4..8825232276 100644
--- a/pixi.lock
+++ b/pixi.lock
@@ -111,6 +111,7 @@ environments:
- pypi: https://files.pythonhosted.org/packages/c0/5a/9cac0c82afec3d09ccd97c8b6502d48f165f9124db81b4bcb90b4af974ee/jedi-0.19.2-py2.py3-none-any.whl
- pypi: https://files.pythonhosted.org/packages/a3/48/f97f0920c20bc522c34f1eaec4c62d7a03c95c37da2dec858f65c8cb4325/loro-1.5.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- pypi: https://files.pythonhosted.org/packages/51/3f/afe76f8e2246ffbc867440cbcf90525264df0e658f8a5ca1f872b3f6192a/markdown-3.8-py3-none-any.whl
+ - pypi: https://files.pythonhosted.org/packages/d0/ef/c5422ce8af73928d194a6606f8ae36e93a52fd5e8df5abd366903a5ca8da/msgspec-0.19.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- pypi: https://files.pythonhosted.org/packages/22/58/a12a534269aa5ba9abdf73a9e0deb600297b71cbf7291bca212944663143/narwhals-1.39.0-py3-none-any.whl
- pypi: https://files.pythonhosted.org/packages/c6/ac/dac4a63f978e4dcb3c6d3a78c4d8e0192a113d288502a1216950c41b1027/parso-0.8.4-py2.py3-none-any.whl
- pypi: https://files.pythonhosted.org/packages/bf/b9/b0eb3f3cbcb734d930fdf839431606844a825b23eaf9a6ab371edac8162c/psutil-7.0.0-cp36-abi3-manylinux_2_12_x86_64.manylinux2010_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
@@ -206,6 +207,7 @@ environments:
- pypi: https://files.pythonhosted.org/packages/c0/5a/9cac0c82afec3d09ccd97c8b6502d48f165f9124db81b4bcb90b4af974ee/jedi-0.19.2-py2.py3-none-any.whl
- pypi: https://files.pythonhosted.org/packages/32/ee/7e042a13e93f09c24618dc804f01849735d81740f8b74827124ff7fc8396/loro-1.5.0-cp312-cp312-macosx_11_0_arm64.whl
- pypi: https://files.pythonhosted.org/packages/3f/08/83871f3c50fc983b88547c196d11cf8c3340e37c32d2e9d6152abe2c61f7/Markdown-3.7-py3-none-any.whl
+ - pypi: https://files.pythonhosted.org/packages/89/b0/1b9763938cfae12acf14b682fcf05c92855974d921a5a985ecc197d1c672/msgspec-0.19.0-cp312-cp312-macosx_11_0_arm64.whl
- pypi: https://files.pythonhosted.org/packages/7d/81/1cf7a468ef2f8e88266d5c3e5ab026a045aa76150e6640bfe9c5450a8c11/narwhals-2.3.0-py3-none-any.whl
- pypi: https://files.pythonhosted.org/packages/c6/ac/dac4a63f978e4dcb3c6d3a78c4d8e0192a113d288502a1216950c41b1027/parso-0.8.4-py2.py3-none-any.whl
- pypi: https://files.pythonhosted.org/packages/04/8b/30f930733afe425e3cbfc0e1468a30a18942350c1a8816acfade80c005c4/psutil-7.0.0-cp36-abi3-macosx_11_0_arm64.whl
@@ -1160,6 +1162,80 @@ packages:
- pkg:pypi/more-itertools?source=hash-mapping
size: 61359
timestamp: 1745349566387
+- pypi: https://files.pythonhosted.org/packages/89/b0/1b9763938cfae12acf14b682fcf05c92855974d921a5a985ecc197d1c672/msgspec-0.19.0-cp312-cp312-macosx_11_0_arm64.whl
+ name: msgspec
+ version: 0.19.0
+ sha256: 43bbb237feab761b815ed9df43b266114203f53596f9b6e6f00ebd79d178cdf2
+ requires_dist:
+ - pyyaml ; extra == 'yaml'
+ - tomli ; python_full_version < '3.11' and extra == 'toml'
+ - tomli-w ; extra == 'toml'
+ - sphinx ; extra == 'doc'
+ - furo ; extra == 'doc'
+ - sphinx-copybutton ; extra == 'doc'
+ - sphinx-design ; extra == 'doc'
+ - ipython ; extra == 'doc'
+ - pytest ; extra == 'test'
+ - msgpack ; extra == 'test'
+ - attrs ; extra == 'test'
+ - eval-type-backport ; python_full_version < '3.10' and extra == 'test'
+ - pyyaml ; extra == 'test'
+ - tomli ; python_full_version < '3.11' and extra == 'test'
+ - tomli-w ; extra == 'test'
+ - pre-commit ; extra == 'dev'
+ - coverage ; extra == 'dev'
+ - mypy ; extra == 'dev'
+ - pyright ; extra == 'dev'
+ - sphinx ; extra == 'dev'
+ - furo ; extra == 'dev'
+ - sphinx-copybutton ; extra == 'dev'
+ - sphinx-design ; extra == 'dev'
+ - ipython ; extra == 'dev'
+ - pytest ; extra == 'dev'
+ - msgpack ; extra == 'dev'
+ - attrs ; extra == 'dev'
+ - eval-type-backport ; python_full_version < '3.10' and extra == 'dev'
+ - pyyaml ; extra == 'dev'
+ - tomli ; python_full_version < '3.11' and extra == 'dev'
+ - tomli-w ; extra == 'dev'
+ requires_python: '>=3.9'
+- pypi: https://files.pythonhosted.org/packages/d0/ef/c5422ce8af73928d194a6606f8ae36e93a52fd5e8df5abd366903a5ca8da/msgspec-0.19.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
+ name: msgspec
+ version: 0.19.0
+ sha256: d911c442571605e17658ca2b416fd8579c5050ac9adc5e00c2cb3126c97f73bc
+ requires_dist:
+ - pyyaml ; extra == 'yaml'
+ - tomli ; python_full_version < '3.11' and extra == 'toml'
+ - tomli-w ; extra == 'toml'
+ - sphinx ; extra == 'doc'
+ - furo ; extra == 'doc'
+ - sphinx-copybutton ; extra == 'doc'
+ - sphinx-design ; extra == 'doc'
+ - ipython ; extra == 'doc'
+ - pytest ; extra == 'test'
+ - msgpack ; extra == 'test'
+ - attrs ; extra == 'test'
+ - eval-type-backport ; python_full_version < '3.10' and extra == 'test'
+ - pyyaml ; extra == 'test'
+ - tomli ; python_full_version < '3.11' and extra == 'test'
+ - tomli-w ; extra == 'test'
+ - pre-commit ; extra == 'dev'
+ - coverage ; extra == 'dev'
+ - mypy ; extra == 'dev'
+ - pyright ; extra == 'dev'
+ - sphinx ; extra == 'dev'
+ - furo ; extra == 'dev'
+ - sphinx-copybutton ; extra == 'dev'
+ - sphinx-design ; extra == 'dev'
+ - ipython ; extra == 'dev'
+ - pytest ; extra == 'dev'
+ - msgpack ; extra == 'dev'
+ - attrs ; extra == 'dev'
+ - eval-type-backport ; python_full_version < '3.10' and extra == 'dev'
+ - pyyaml ; extra == 'dev'
+ - tomli ; python_full_version < '3.11' and extra == 'dev'
+ - tomli-w ; extra == 'dev'
+ requires_python: '>=3.9'
- pypi: https://files.pythonhosted.org/packages/22/58/a12a534269aa5ba9abdf73a9e0deb600297b71cbf7291bca212944663143/narwhals-1.39.0-py3-none-any.whl
name: narwhals
version: 1.39.0
diff --git a/pyproject.toml b/pyproject.toml
index 74bad6b5f6..d44ab1b383 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -48,6 +48,7 @@ dependencies = [
"narwhals>=1.34.1",
# for packaging.version; not sure what the lower bound is.
"packaging",
+ "msgspec>=0.19.0",
]
readme = "README.md"
license = { file = "LICENSE" }
diff --git a/tests/_islands/snapshots/island-mimetypes.txt b/tests/_islands/snapshots/island-mimetypes.txt
index 3c08203e59..94e72dedf5 100644
--- a/tests/_islands/snapshots/island-mimetypes.txt
+++ b/tests/_islands/snapshots/island-mimetypes.txt
@@ -24,7 +24,7 @@
data-reactive="true"
>
<marimo-cell-output>
- <marimo-json-output data-json-data='{&quot;key&quot;: &quot;value&quot;}' data-value-types='&quot;python&quot;'></marimo-json-output>
+ <marimo-json-output data-json-data='{&quot;key&quot;:&quot;value&quot;}' data-value-types='&quot;python&quot;'></marimo-json-output>
</marimo-cell-output>
<marimo-cell-code hidden>%7B'key'%3A%20'value'%7D</marimo-cell-code>
</marimo-island>
@@ -34,7 +34,7 @@
data-reactive="true"
>
<marimo-cell-output>
- <marimo-json-output data-json-data='[1, &quot;text/html:&lt;span class=&#92;&quot;markdown prose dark:prose-invert&#92;&quot;&gt;&lt;span class=&#92;&quot;paragraph&#92;&quot;&gt;Hello&lt;/span&gt;&lt;/span&gt;&quot;]' data-value-types='&quot;python&quot;'></marimo-json-output>
+ <marimo-json-output data-json-data='[1,&quot;text/html:&lt;span class=&#92;&quot;markdown prose dark:prose-invert&#92;&quot;&gt;&lt;span class=&#92;&quot;paragraph&#92;&quot;&gt;Hello&lt;/span&gt;&lt;/span&gt;&quot;]' data-value-types='&quot;python&quot;'></marimo-json-output>
</marimo-cell-output>
<marimo-cell-code hidden>%5B1%2C%20mo.md('Hello')%5D</marimo-cell-code>
</marimo-island>
\ No newline at end of file
diff --git a/tests/_messaging/mocks.py b/tests/_messaging/mocks.py
new file mode 100644
index 0000000000..4ecf58a351
--- /dev/null
+++ b/tests/_messaging/mocks.py
@@ -0,0 +1,38 @@
+from __future__ import annotations
+
+from typing import Any, Optional
+
+from marimo._messaging.mimetypes import ConsoleMimeType
+from marimo._messaging.types import KernelMessage, Stderr, Stream
+
+
+class MockStream(Stream):
+ def __init__(self, stream: Optional[Stream] = None) -> None:
+ self.messages: list[KernelMessage] = []
+
+ if stream is not None and hasattr(stream, "messages"):
+ self.messages = stream.messages
+
+ def write(self, op: str, data: bytes) -> None:
+ self.messages.append((op, data))
+
+ @property
+ def operations(self) -> list[dict[str, Any]]:
+ import json
+
+ return [json.loads(op_data) for _op_name, op_data in self.messages]
+
+
+class MockStderr(Stderr):
+ def __init__(self, stream: Optional[Stderr] = None) -> None:
+ self.messages: list[str] = []
+
+ if stream is not None and hasattr(stream, "messages"):
+ self.messages = stream.messages
+
+ def _write_with_mimetype(
+ self, data: str, mimetype: ConsoleMimeType
+ ) -> int:
+ del mimetype
+ self.messages.append(data)
+ return len(data)
diff --git a/tests/_messaging/test_cell_output.py b/tests/_messaging/test_cell_output.py
index 47a6923cd6..dffddb30f3 100644
--- a/tests/_messaging/test_cell_output.py
+++ b/tests/_messaging/test_cell_output.py
@@ -1,20 +1,12 @@
from __future__ import annotations
-from typing import Any
-
import pytest
from marimo._messaging.cell_output import CellChannel, CellOutput
from marimo._messaging.errors import MarimoSyntaxError
-from marimo._messaging.ops import serialize
-from marimo._plugins.core.json_encoder import WebComponentEncoder
+from marimo._messaging.msgspec_encoder import asdict as serialize
from marimo._utils.parse_dataclass import parse_raw
-
-def as_json(obj: Any):
- return WebComponentEncoder.json_dumps(obj)
-
-
timestamp = 0
stderr_output = CellOutput(
diff --git a/tests/_messaging/test_console_output_worker.py b/tests/_messaging/test_console_output_worker.py
index d52aeb9615..12cb87314b 100644
--- a/tests/_messaging/test_console_output_worker.py
+++ b/tests/_messaging/test_console_output_worker.py
@@ -15,15 +15,7 @@ from marimo._messaging.console_output_worker import (
_write_console_output,
buffered_writer,
)
-from marimo._messaging.types import Stream
-
-
-class MockStream(Stream):
- def __init__(self) -> None:
- self.messages: list[tuple[str, dict]] = []
-
- def write(self, op: str, data: dict) -> None:
- self.messages.append((op, data))
+from tests._messaging.mocks import MockStream
class TestConsoleOutputWorker:
@@ -137,12 +129,12 @@ class TestConsoleOutputWorker:
"text/plain",
)
- assert len(stream.messages) == 1
+ assert len(stream.operations) == 1
assert stream.messages[0][0] == "cell-op" # op
- assert stream.messages[0][1]["cell_id"] == "cell1"
- assert stream.messages[0][1]["console"]["channel"] == "stdout"
- assert stream.messages[0][1]["console"]["mimetype"] == "text/plain"
- assert stream.messages[0][1]["console"]["data"] == "Hello"
+ assert stream.operations[0]["cell_id"] == "cell1"
+ assert stream.operations[0]["console"]["channel"] == "stdout"
+ assert stream.operations[0]["console"]["mimetype"] == "text/plain"
+ assert stream.operations[0]["console"]["data"] == "Hello"
def test_buffered_writer_basic(self) -> None:
# Test basic functionality of buffered writer
@@ -176,12 +168,12 @@ class TestConsoleOutputWorker:
for _ in range(10):
time.sleep(0.1)
- if len(stream.messages) == 1:
+ if len(stream.operations) == 1:
break
# Check that the message was written to the stream
- assert len(stream.messages) == 1
- assert stream.messages[0][1]["console"]["data"] == "Hello"
+ assert len(stream.operations) == 1
+ assert stream.operations[0]["console"]["data"] == "Hello"
finally:
# Signal the writer to terminate
@@ -245,12 +237,14 @@ class TestConsoleOutputWorker:
assert len(stream.messages) == 2 # Merged stdout messages + stderr
# First message should be the merged stdout messages
- assert stream.messages[0][1]["console"]["channel"] == "stdout"
- assert stream.messages[0][1]["console"]["data"] == "Hello World"
+ first_message = stream.operations[0]
+ assert first_message["console"]["channel"] == "stdout"
+ assert first_message["console"]["data"] == "Hello World"
# Second message should be the stderr message
- assert stream.messages[1][1]["console"]["channel"] == "stderr"
- assert stream.messages[1][1]["console"]["data"] == "Error"
+ second_message = stream.operations[1]
+ assert second_message["console"]["channel"] == "stderr"
+ assert second_message["console"]["data"] == "Error"
finally:
# Signal the writer to terminate
diff --git a/tests/_messaging/test_messaging_errors.py b/tests/_messaging/test_messaging_errors.py
index ec5b3a9986..ca3633339a 100644
--- a/tests/_messaging/test_messaging_errors.py
+++ b/tests/_messaging/test_messaging_errors.py
@@ -1,6 +1,8 @@
# Copyright 2024 Marimo. All rights reserved.
from __future__ import annotations
+import msgspec
+
from marimo._messaging.errors import (
CycleError,
ImportStarError,
@@ -28,7 +30,8 @@ class TestErrorClasses:
error = CycleError(edges_with_vars=(edge1, edge2))
# Test properties
- assert error.type == "cycle"
+ serialized = msgspec.to_builtins(error)
+ assert serialized["type"] == "cycle"
assert "cycle" in error.describe().lower()
assert isinstance(error.describe(), str)
@@ -38,7 +41,8 @@ class TestErrorClasses:
)
# Test properties
- assert error.type == "multiple-defs"
+ serialized = msgspec.to_builtins(error)
+ assert serialized["type"] == "multiple-defs"
assert "test_var" in error.describe()
assert "defined by another cell" in error.describe()
@@ -46,14 +50,16 @@ class TestErrorClasses:
error = ImportStarError(msg="Cannot use import * in this context")
# Test properties
- assert error.type == "import-star"
+ serialized = msgspec.to_builtins(error)
+ assert serialized["type"] == "import-star"
assert error.describe() == "Cannot use import * in this context"
def test_marimo_interruption_error(self) -> None:
error = MarimoInterruptionError()
# Test properties
- assert error.type == "interruption"
+ serialized = msgspec.to_builtins(error)
+ assert serialized["type"] == "interruption"
assert "interrupted" in error.describe().lower()
assert "re-run" in error.describe().lower()
@@ -65,7 +71,8 @@ class TestErrorClasses:
)
# Test properties
- assert error.type == "ancestor-prevented"
+ serialized = msgspec.to_builtins(error)
+ assert serialized["type"] == "ancestor-prevented"
assert error.describe() == "Execution prevented by ancestor"
assert error.raising_cell == "cell1"
assert error.blamed_cell == "cell2"
@@ -77,7 +84,8 @@ class TestErrorClasses:
)
# Test properties
- assert error.type == "ancestor-stopped"
+ serialized = msgspec.to_builtins(error)
+ assert serialized["type"] == "ancestor-stopped"
assert error.describe() == "Execution stopped by ancestor"
assert error.raising_cell == "cell1"
@@ -89,7 +97,8 @@ class TestErrorClasses:
)
# Test properties
- assert error.type == "exception"
+ serialized = msgspec.to_builtins(error)
+ assert serialized["type"] == "exception"
assert error.describe() == "ValueError: invalid value"
assert error.raising_cell == "cell1"
assert error.exception_type == "ValueError"
@@ -98,14 +107,16 @@ class TestErrorClasses:
error = MarimoSyntaxError(msg="Invalid syntax")
# Test properties
- assert error.type == "syntax"
+ serialized = msgspec.to_builtins(error)
+ assert serialized["type"] == "syntax"
assert error.describe() == "Invalid syntax"
def test_unknown_error(self) -> None:
error = UnknownError(msg="Something went wrong")
# Test properties
- assert error.type == "unknown"
+ serialized = msgspec.to_builtins(error)
+ assert serialized["type"] == "unknown"
assert error.describe() == "Something went wrong"
def test_marimo_strict_execution_error(self) -> None:
@@ -116,7 +127,8 @@ class TestErrorClasses:
)
# Test properties
- assert error.type == "strict-exception"
+ serialized = msgspec.to_builtins(error)
+ assert serialized["type"] == "strict-exception"
assert error.describe() == "Strict execution error"
assert error.ref == "some_reference"
assert error.blamed_cell == "cell1"
@@ -128,7 +140,8 @@ class TestErrorClasses:
)
# Test properties
- assert error.type == "internal"
+ serialized = msgspec.to_builtins(error)
+ assert serialized["type"] == "internal"
assert "An internal error occurred" in error.describe()
assert "test-error-id" in error.describe()
# The original message should be replaced with a generic one
diff --git a/tests/_messaging/test_ops.py b/tests/_messaging/test_ops.py
index 8d26a435e9..30ec70e704 100644
--- a/tests/_messaging/test_ops.py
+++ b/tests/_messaging/test_ops.py
@@ -9,17 +9,20 @@ from marimo._output.hypertext import Html
from marimo._plugins.ui._impl.input import slider
from marimo._types.ids import CellId_t
from marimo._utils.parse_dataclass import parse_raw
+from tests._messaging.mocks import MockStream
def test_value_ui_element() -> None:
- variable_value = VariableValue(name="s", value=slider(1, 10, value=5))
+ variable_value = VariableValue.create(
+ name="s", value=slider(1, 10, value=5)
+ )
assert variable_value.datatype == "slider"
assert variable_value.value == "5"
def test_value_html() -> None:
h = Html("<span></span>")
- variable_value = VariableValue(name="h", value=h)
+ variable_value = VariableValue.create(name="h", value=h)
assert variable_value.datatype == "Html"
assert variable_value.value == h.text
@@ -29,7 +32,7 @@ def test_variable_value_broken_str() -> None:
def __str__(self) -> str:
raise BaseException # noqa: TRY002
- variable_value = VariableValue(name="o", value=Broken())
+ variable_value = VariableValue.create(name="o", value=Broken())
assert variable_value.datatype == "Broken"
assert variable_value.value is not None
assert variable_value.value.startswith("<Broken object at")
@@ -38,8 +41,7 @@ def test_variable_value_broken_str() -> None:
def test_broadcast_serialization() -> None:
cell_id = CellId_t("test_cell_id")
- stream = MagicMock()
- stream.write = MagicMock()
+ stream = MockStream()
status = MagicMock(TopLevelStatus)
status.hint = HINT_UNPARSABLE
@@ -47,8 +49,8 @@ def test_broadcast_serialization() -> None:
cell_id=cell_id, serialization=status, stream=stream
)
- stream.write.assert_called_once()
- cell_op = stream.write.call_args.kwargs["data"]
- assert cell_op["serialization"] == str(HINT_UNPARSABLE)
+ assert len(stream.messages) == 1
+ assert stream.operations[0]["serialization"] == str(HINT_UNPARSABLE)
+ cell_op = stream.operations[0]
assert isinstance(parse_raw(cell_op, CellOp), CellOp)
diff --git a/tests/_messaging/test_print_override.py b/tests/_messaging/test_print_override.py
index 66b0ffe9ee..9da5c38e11 100644
--- a/tests/_messaging/test_print_override.py
+++ b/tests/_messaging/test_print_override.py
@@ -5,21 +5,13 @@ import threading
from unittest.mock import MagicMock, patch
from marimo._messaging.print_override import print_override
-from marimo._messaging.types import Stream
from marimo._runtime.context.types import (
ContextNotInitializedError,
ExecutionContext,
RuntimeContext,
)
from marimo._runtime.threads import THREADS
-
-
-class MockStream(Stream):
- def __init__(self) -> None:
- self.messages: list[tuple[str, dict]] = []
-
- def write(self, op: str, data: dict) -> None:
- self.messages.append((op, data))
+from tests._messaging.mocks import MockStream
class TestPrintOverride:
@@ -82,16 +74,16 @@ class TestPrintOverride:
# Message should be sent to the stream
assert len(stream.messages) == 1
assert stream.messages[0][0] == "cell-op" # op
- assert stream.messages[0][1]["cell_id"] == "cell1"
+ assert stream.operations[0]["cell_id"] == "cell1"
assert (
- stream.messages[0][1]["console"]["channel"] == "stdout"
+ stream.operations[0]["console"]["channel"] == "stdout"
)
assert (
- stream.messages[0][1]["console"]["mimetype"]
+ stream.operations[0]["console"]["mimetype"]
== "text/plain"
)
assert (
- stream.messages[0][1]["console"]["data"]
+ stream.operations[0]["console"]["data"]
== "Hello, world!\n"
)
finally:
@@ -152,9 +144,9 @@ class TestPrintOverride:
mock_print.assert_not_called()
# Message should be sent to the stream with custom sep and end
- assert len(stream.messages) == 1
+ assert len(stream.operations) == 1
assert (
- stream.messages[0][1]["console"]["data"]
+ stream.operations[0]["console"]["data"]
== "Hello-world!"
)
finally:
@@ -189,9 +181,9 @@ class TestPrintOverride:
mock_print.assert_not_called()
# Message should be sent to the stream with all args converted to strings
- assert len(stream.messages) == 1
+ assert len(stream.operations) == 1
assert (
- stream.messages[0][1]["console"]["data"]
+ stream.operations[0]["console"]["data"]
== "Hello 123 True None\n"
)
finally:
diff --git a/tests/_output/formatters/test_formatters.py b/tests/_output/formatters/test_formatters.py
index 0248bd4055..8841484613 100644
--- a/tests/_output/formatters/test_formatters.py
+++ b/tests/_output/formatters/test_formatters.py
@@ -625,7 +625,7 @@ def test_as_html_basic_types() -> None:
result = as_html([1, 2, 3])
assert (
result.text
- == "<marimo-json-output data-json-data='[1, 2, 3]' data-value-types='&quot;python&quot;'></marimo-json-output>"
+ == "<marimo-json-output data-json-data='[1,2,3]' data-value-types='&quot;python&quot;'></marimo-json-output>"
)
# Dict
@@ -748,7 +748,7 @@ def test_as_html_with_plain_wrapper() -> None:
result = as_html(plain_list)
assert (
result.text
- == "<marimo-json-output data-json-data='[1, 2, 3]' data-value-types='&quot;python&quot;'></marimo-json-output>"
+ == "<marimo-json-output data-json-data='[1,2,3]' data-value-types='&quot;python&quot;'></marimo-json-output>"
)
# Test with a dict that would normally get marimo-json formatting
@@ -756,7 +756,7 @@ def test_as_html_with_plain_wrapper() -> None:
result = as_html(plain_dict)
assert (
result.text
- == "<marimo-json-output data-json-data='{&quot;key&quot;: &quot;value&quot;}' data-value-types='&quot;python&quot;'></marimo-json-output>"
+ == "<marimo-json-output data-json-data='{&quot;key&quot;:&quot;value&quot;}' data-value-types='&quot;python&quot;'></marimo-json-output>"
)
diff --git a/tests/_plugins/core/test_json_encoder.py b/tests/_plugins/core/test_json_encoder.py
deleted file mode 100644
index 5a575827e9..0000000000
--- a/tests/_plugins/core/test_json_encoder.py
+++ /dev/null
@@ -1,470 +0,0 @@
-# Copyright 2024 Marimo. All rights reserved.
-from __future__ import annotations
-
-import dataclasses
-import json
-from collections import namedtuple
-from dataclasses import dataclass
-from typing import Any, Optional
-
-import pytest
-
-from marimo._dependencies.dependencies import DependencyManager
-from marimo._output.mime import MIME
-from marimo._plugins.core.json_encoder import WebComponentEncoder
-
-HAS_DEPS = (
- DependencyManager.pandas.has()
- and DependencyManager.altair.has()
- and DependencyManager.polars.has()
-)
-
-
[email protected](not HAS_DEPS, reason="optional dependencies not installed")
-def test_numpy_encoding() -> None:
- import numpy as np
-
- arr = np.array([1, 2, 3])
- encoded = json.dumps(arr, cls=WebComponentEncoder)
- assert encoded == "[1, 2, 3]"
-
- dt64 = np.datetime64("2021-01-01T12:00:00")
- encoded_dt64 = json.dumps(dt64, cls=WebComponentEncoder)
- assert encoded_dt64 == '"2021-01-01T12:00:00"'
-
- dt64_arr = np.array([dt64, dt64])
- encoded_dt64_arr = json.dumps(dt64_arr, cls=WebComponentEncoder)
- assert encoded_dt64_arr == '["2021-01-01T12:00:00", "2021-01-01T12:00:00"]'
-
- complex_arr = np.array([1 + 2j, 3 + 4j])
- encoded_complex_arr = json.dumps(complex_arr, cls=WebComponentEncoder)
- assert encoded_complex_arr == '["(1+2j)", "(3+4j)"]'
-
-
[email protected](not HAS_DEPS, reason="optional dependencies not installed")
-def test_pandas_encoding() -> None:
- import pandas as pd
-
- # DF
- df = pd.DataFrame({"a": [1, 2], "b": [3, 4]})
- encoded = json.dumps(df, cls=WebComponentEncoder)
- assert encoded == '[{"a": 1, "b": 3}, {"a": 2, "b": 4}]'
-
- # Series
- series = pd.Series([1, 2, 3])
- encoded_series = json.dumps(series, cls=WebComponentEncoder)
- assert encoded_series == "[1, 2, 3]"
-
- # Timestamp
- timestamp = pd.Timestamp("2021-01-01T12:00:00")
- encoded_timestamp = json.dumps(timestamp, cls=WebComponentEncoder)
- assert encoded_timestamp == '"2021-01-01T12:00:00"'
-
- # DatetimeTZDtype
- datetime_with_tz = pd.Series(
- pd.date_range("2021-01-01", periods=3, tz="UTC")
- )
- encoded_datetime_with_tz = json.dumps(
- datetime_with_tz, cls=WebComponentEncoder
- )
- assert '"2021-01-01T00:00:00+00:00"' in encoded_datetime_with_tz
-
- # Categorical
- cat = pd.Categorical(["test", "train", "test", "train"])
- encoded_cat = json.dumps(cat, cls=WebComponentEncoder)
- assert encoded_cat == '["test", "train", "test", "train"]'
-
- # Interval
- interval = pd.Interval(left=0, right=5)
- encoded_interval = json.dumps(interval, cls=WebComponentEncoder)
- assert encoded_interval == '"(0, 5]"'
-
- # Timedelta
- timedelta = pd.Timedelta("1 days")
- encoded_timedelta = json.dumps(timedelta, cls=WebComponentEncoder)
- assert encoded_timedelta == '"1 days 00:00:00"'
-
- timedelta_arr = pd.to_timedelta(["1 days", "2 days", "3 days"])
- encoded_timedelta_arr = json.dumps(timedelta_arr, cls=WebComponentEncoder)
- assert encoded_timedelta_arr == '["1 days", "2 days", "3 days"]'
-
- # Catch-all
- other = pd.Series(["a", "b", "c"])
- encoded_other = json.dumps(other, cls=WebComponentEncoder)
- assert encoded_other == '["a", "b", "c"]'
-
-
[email protected](not HAS_DEPS, reason="optional dependencies not installed")
-def test_polars_encoding() -> None:
- import polars as pl
-
- df = pl.DataFrame({"a": [1, 2], "b": [3, 4]})
- encoded = json.dumps(df, cls=WebComponentEncoder)
- assert encoded == '{"a": [1, 2], "b": [3, 4]}'
-
- series = pl.Series([1, 2, 3])
- encoded_series = json.dumps(series, cls=WebComponentEncoder)
- assert encoded_series == "[1, 2, 3]"
-
-
-@dataclass
-class MockMIMEObject:
- def _mime_(self) -> tuple[str, str]:
- return "text/plain", "data"
-
-
-def test_mime_encoding() -> None:
- mime_obj = MockMIMEObject()
- encoded = json.dumps(mime_obj, cls=WebComponentEncoder)
- assert encoded == '{"mimetype": "text/plain", "data": "data"}'
-
-
-def test_list_mime_encoding() -> None:
- mime_obj = [MockMIMEObject(), MockMIMEObject()]
- encoded = json.dumps(mime_obj, cls=WebComponentEncoder)
- assert (
- encoded
- == '[{"mimetype": "text/plain", "data": "data"}, {"mimetype": "text/plain", "data": "data"}]' # noqa: E501
- )
-
-
-def test_dict_mime_encoding() -> None:
- mime_obj = {"key": MockMIMEObject()}
- encoded = json.dumps(mime_obj, cls=WebComponentEncoder)
- assert encoded == '{"key": {"mimetype": "text/plain", "data": "data"}}'
-
-
-def test_nested_mime_encoding() -> None:
- mime_obj = {"key": [MockMIMEObject(), MockMIMEObject()]}
- encoded = json.dumps(mime_obj, cls=WebComponentEncoder)
- assert (
- encoded
- == '{"key": [{"mimetype": "text/plain", "data": "data"}, {"mimetype": "text/plain", "data": "data"}]}' # noqa: E501
- )
-
-
-@dataclass
-class MockDataclass:
- a: int
- b: str
- items: Optional[list[Any]] = None
- other_items: Optional[dict[str, Any]] = None
-
-
-class Button(MIME):
- def _mime_(self) -> tuple[str, str]:
- return "text/html", "<button>Click me!</button>"
-
-
-def test_dataclass_encoding() -> None:
- dataclass_obj = MockDataclass(1, "hello")
- encoded = json.dumps(dataclass_obj, cls=WebComponentEncoder)
- assert (
- encoded == '{"a": 1, "b": "hello", "items": null, "other_items": null}'
- )
-
-
-def test_dataclass_with_list_encoding() -> None:
- dataclass_obj = MockDataclass(
- 1, "hello", items=[1, "2", MockMIMEObject(), Button()]
- )
- # as dict
- assert dataclasses.asdict(dataclass_obj) == {
- "a": 1,
- "b": "hello",
- "items": [1, "2", {}, {}], # asdict will convert to empty dictionaries
- "other_items": None,
- }
-
- # But our encoder handles nested dataclasses back through the encoder
- encoded = json.dumps(dataclass_obj, cls=WebComponentEncoder)
- assert (
- encoded
- == '{"a": 1, "b": "hello", "items": [1, "2", {"mimetype": "text/plain", "data": "data"}, {"mimetype": "text/html", "data": "<button>Click me!</button>"}], "other_items": null}' # noqa: E501
- )
-
-
-def test_dataclass_with_dict_encoding() -> None:
- dataclass_obj = MockDataclass(
- 1, "hello", other_items={"key": MockMIMEObject()}
- )
- encoded = json.dumps(dataclass_obj, cls=WebComponentEncoder)
- assert (
- encoded
- == '{"a": 1, "b": "hello", "items": null, "other_items": {"key": {"mimetype": "text/plain", "data": "data"}}}' # noqa: E501
- )
-
-
-def test_dict_encoding() -> None:
- dict_obj = {"key": "value"}
- encoded = json.dumps(dict_obj, cls=WebComponentEncoder)
- assert encoded == '{"key": "value"}'
-
-
-def test_bytes_encoding() -> None:
- bytes_obj = b"hello"
- encoded = json.dumps(bytes_obj, cls=WebComponentEncoder)
- assert encoded == '"hello"'
-
-
-def test_memoryview_encoding() -> None:
- bytes_obj = b"hello"
- memview = memoryview(bytes_obj)
- encoded = json.dumps(memview, cls=WebComponentEncoder)
- assert encoded == '"hello"'
-
-
-def test_set_encoding() -> None:
- set_obj = set(["a", "b"])
- encoded = json.dumps(set_obj, cls=WebComponentEncoder)
- assert encoded == '["a", "b"]' or encoded == '["b", "a"]'
- empty_set = set()
- encoded_empty = json.dumps(empty_set, cls=WebComponentEncoder)
- assert encoded_empty == "[]"
- number_set = set([1, 2])
- encoded_number = json.dumps(number_set, cls=WebComponentEncoder)
- assert encoded_number == "[1, 2]" or encoded_number == "[2, 1]"
-
-
-def test_tuple_encoding() -> None:
- tuple_obj = ("a", "b")
- encoded = json.dumps(tuple_obj, cls=WebComponentEncoder)
- assert encoded == '["a", "b"]'
- empty_tuple = ()
- encoded_empty = json.dumps(empty_tuple, cls=WebComponentEncoder)
- assert encoded_empty == "[]"
-
-
-def test_frozen_set_encoding() -> None:
- frozen_set_obj = frozenset(["a", "b"])
- encoded = json.dumps(frozen_set_obj, cls=WebComponentEncoder)
- assert encoded == '["a", "b"]' or encoded == '["b", "a"]'
- empty_frozen_set = frozenset()
- encoded_empty = json.dumps(empty_frozen_set, cls=WebComponentEncoder)
- assert encoded_empty == "[]"
- number_frozen_set = frozenset([1, 2])
- encoded_number = json.dumps(number_frozen_set, cls=WebComponentEncoder)
- assert encoded_number == "[1, 2]" or encoded_number == "[2, 1]"
-
-
-def test_null_encoding() -> None:
- null = None
- encoded = json.dumps(null, cls=WebComponentEncoder)
- assert encoded == "null"
-
-
-def test_inf_encoding() -> None:
- inf = float("inf")
- encoded = json.dumps(inf, cls=WebComponentEncoder)
- assert encoded == "Infinity"
-
-
-def test_nan_encoding() -> None:
- nan = float("nan")
- encoded = json.dumps(nan, cls=WebComponentEncoder)
- assert encoded == "NaN"
-
-
-def test_empty_encoding() -> None:
- empty = ""
- encoded = json.dumps(empty, cls=WebComponentEncoder)
- assert encoded == '""'
- empty_list = []
- encoded_list = json.dumps(empty_list, cls=WebComponentEncoder)
- assert encoded_list == "[]"
- empty_dict = {}
- encoded_dict = json.dumps(empty_dict, cls=WebComponentEncoder)
- assert encoded_dict == "{}"
- empty_tuple = ()
- encoded_tuple = json.dumps(empty_tuple, cls=WebComponentEncoder)
- assert encoded_tuple == "[]"
- empty_nested = [[], [], []]
- encoded_nested = json.dumps(empty_nested, cls=WebComponentEncoder)
- assert encoded_nested == "[[], [], []]"
-
-
-def test_complex_number_encoding() -> None:
- complex_num = 3 + 4j
- encoded = json.dumps(complex_num, cls=WebComponentEncoder)
- assert encoded == '"(3+4j)"'
-
-
-def test_custom_class_encoding() -> None:
- @dataclass
- class CustomClass:
- name: str
- value: int
-
- custom_obj = CustomClass(name="test", value=42)
- encoded = json.dumps(custom_obj, cls=WebComponentEncoder)
- assert encoded == '{"name": "test", "value": 42}'
-
-
-def test_nested_structure_encoding() -> None:
- nested_structure = {
- "list": [1, 2, 3],
- "dict": {"a": 1, "b": 2},
- "tuple": (4, 5, 6),
- "set": {7, 8, 9},
- }
- encoded = json.dumps(nested_structure, cls=WebComponentEncoder)
- decoded = json.loads(encoded)
- assert decoded["list"] == [1, 2, 3]
- assert decoded["dict"] == {"a": 1, "b": 2}
- assert decoded["tuple"] == [4, 5, 6] # Tuples are converted to lists
- assert set(decoded["set"]) == {7, 8, 9}
-
-
-def test_date_time_encoding() -> None:
- import datetime
-
- date_obj = datetime.date(2023, 1, 1)
- time_obj = datetime.time(12, 30, 45)
- datetime_obj = datetime.datetime(2023, 1, 1, 12, 30, 45)
-
- encoded_date = json.dumps(date_obj, cls=WebComponentEncoder)
- encoded_time = json.dumps(time_obj, cls=WebComponentEncoder)
- encoded_datetime = json.dumps(datetime_obj, cls=WebComponentEncoder)
-
- assert encoded_date == '"2023-01-01"'
- assert encoded_time == '"12:30:45"'
- assert encoded_datetime == '"2023-01-01T12:30:45"'
-
-
-def test_timedelta_encoding() -> None:
- import datetime
-
- timedelta_obj = datetime.timedelta(days=1, seconds=2, microseconds=3)
- encoded = json.dumps(timedelta_obj, cls=WebComponentEncoder)
- assert encoded == '"1 day, 0:00:02.000003"'
-
-
-def test_enum_encoding() -> None:
- from enum import Enum
-
- class Color(Enum):
- RED = 1
- GREEN = 2
- BLUE = 3
-
- encoded = json.dumps(Color.RED, cls=WebComponentEncoder)
- assert encoded == '"RED"'
-
-
-def test_uuid_encoding() -> None:
- import uuid
-
- uuid_obj = uuid.uuid4()
- encoded = json.dumps(uuid_obj, cls=WebComponentEncoder)
- assert encoded == f'"{str(uuid_obj)}"'
-
-
-def test_circular_reference_encoding():
- circular_dict = {}
- circular_dict["self"] = circular_dict
- with pytest.raises(ValueError):
- json.dumps(circular_dict, cls=WebComponentEncoder)
-
-
-def test_custom_object_with_dict():
- class CustomObject:
- def __init__(self):
- self.attr = "value"
-
- obj = CustomObject()
- encoded = json.dumps(obj, cls=WebComponentEncoder)
- assert encoded == '{"attr": "value"}'
-
-
-def test_object_with_slots():
- class SlottedObject:
- __slots__ = ["x", "y"]
-
- def __init__(self, x, y):
- self.x = x
- self.y = y
-
- obj = SlottedObject(1, 2)
- encoded = json.dumps(obj, cls=WebComponentEncoder)
- assert encoded == '{"x": 1, "y": 2}'
-
-
-def test_named_tuple_encoding():
- Point = namedtuple("Point", ["x", "y"])
- p = Point(1, 2)
- encoded = json.dumps(p, cls=WebComponentEncoder)
- assert encoded == "[1, 2]"
-
-
-def test_complex_nested_structure():
- complex_obj = {
- "list": [1, {"a": 2}, (3, 4)],
- "dict": {"b": [5, 6], "c": {"d": 7}},
- "set": {8, 9, 10},
- "tuple": (11, [12, 13], {"e": 14}),
- }
- encoded = json.dumps(complex_obj, cls=WebComponentEncoder)
- decoded = json.loads(encoded)
- assert decoded["list"] == [1, {"a": 2}, [3, 4]]
- assert decoded["dict"] == {"b": [5, 6], "c": {"d": 7}}
- assert set(decoded["set"]) == {8, 9, 10}
- assert decoded["tuple"] == [11, [12, 13], {"e": 14}]
-
-
-def test_png_encoding() -> None:
- purple_square = "b'\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x14\x00\x00\x00\x14\x08\x02\x00\x00\x00\x02\xeb\x8aZ\x00\x00\x00\tpHYs\x00\x00.#\x00\x00.#\x01x\xa5?v\x00\x00\x00\x1dIDAT8\xcbc\xac\x11\xa9g \x1701P\x00F5\x8fj\x1e\xd5<\xaa\x99r\xcd\x00m\xba\x017\xd3\x00\xdf\xcb\x00\x00\x00\x00IEND\xaeB`\x82'" # noqa: E501
- encoded = json.dumps(purple_square, cls=WebComponentEncoder)
- assert isinstance(encoded, str)
-
-
-def test_range_encoding() -> None:
- r = range(10)
- encoded = json.dumps(r, cls=WebComponentEncoder)
- assert encoded == "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]"
-
-
-def test_error_encoding() -> None:
- from marimo._messaging.errors import MultipleDefinitionError
- from marimo._types.ids import CellId_t
-
- error_obj = MultipleDefinitionError(
- "This is a custom error", (CellId_t("test"), CellId_t("test2"))
- )
- encoded = json.dumps(error_obj, cls=WebComponentEncoder)
- assert (
- encoded
- == '{"name": "This is a custom error", "cells": ["test", "test2"], "type": "multiple-defs"}'
- )
-
-
-def test_invalid_class() -> None:
- class InvalidClass: ...
-
- invalid_obj = InvalidClass()
- invalid_obj.__slots__ = None
-
- encoded = json.dumps(invalid_obj, cls=WebComponentEncoder)
- assert encoded == '{"__slots__": null}'
-
-
-def test_empty_slots() -> None:
- class ExClass:
- __slots__ = []
-
- # With a property (as sanity check)
- @property
- def one(self):
- return 1
-
- obj = ExClass()
-
- encoded = json.dumps(obj, cls=WebComponentEncoder)
- assert encoded == "{}"
-
-
-def test_decimal_encoding() -> None:
- from decimal import Decimal
-
- decimal_obj = Decimal("123.45")
- encoded = json.dumps(decimal_obj, cls=WebComponentEncoder)
- assert encoded == "123.45"
diff --git a/tests/_plugins/stateless/test_routes.py b/tests/_plugins/stateless/test_routes.py
index c21a7ea8d0..379a47daa6 100644
--- a/tests/_plugins/stateless/test_routes.py
+++ b/tests/_plugins/stateless/test_routes.py
@@ -74,6 +74,4 @@ async def test_routes_non_lazy(k: Kernel, exec_req: ExecReqProvider) -> None:
routes = k.globals["routes"]
children = "<span>42</span><span>45</span>"
assert children in routes.text
- assert (
- "data-routes='[&quot;#/&quot;, &quot;{/*path}&quot;]'" in routes.text
- )
+ assert "data-routes='[&quot;#/&quot;,&quot;{/*path}&quot;]'" in routes.text
diff --git a/tests/_plugins/ui/_impl/tables/test_default_table.py b/tests/_plugins/ui/_impl/tables/test_default_table.py
index 80358e3a9a..6afbaea2db 100644
--- a/tests/_plugins/ui/_impl/tables/test_default_table.py
+++ b/tests/_plugins/ui/_impl/tables/test_default_table.py
@@ -749,7 +749,7 @@ class TestColumnarDefaultTable(unittest.TestCase):
"b": [3, 4],
}
)
- assert manager.to_json() == b'[{"a": 1, "b": 3}, {"a": 2, "b": 4}]'
+ assert manager.to_json() == b'[{"a":1,"b":3},{"a":2,"b":4}]'
@pytest.mark.skipif(
not HAS_DEPS, reason="optional dependencies not installed"
@@ -957,7 +957,7 @@ class TestDictionaryDefaultTable(unittest.TestCase):
def test_to_json(self) -> None:
assert (
self.manager.to_json()
- == b'[{"key": "a", "value": 1}, {"key": "b", "value": 2}]'
+ == b'[{"key":"a","value":1},{"key":"b","value":2}]'
)
diff --git a/tests/_plugins/ui/_impl/tables/test_narwhals.py b/tests/_plugins/ui/_impl/tables/test_narwhals.py
index 2e82047d05..5f805bd030 100644
--- a/tests/_plugins/ui/_impl/tables/test_narwhals.py
+++ b/tests/_plugins/ui/_impl/tables/test_narwhals.py
@@ -414,6 +414,71 @@ class TestNarwhalsTableManagerFactory(unittest.TestCase):
for column in complex_data.get_column_names():
assert complex_data.get_stats(column) is not None
+ def test_get_stats_unwraps_scalars_properly(self) -> None:
+ """Test that get_stats properly unwraps narwhals scalars to Python primitives.
+
+ This test ensures that the values returned in ColumnStats are proper Python
+ primitives, not wrapped narwhals scalar objects. The unwrapping happens via
+ unwrap_py_scalar in narwhals_table.py get_stats method.
+ """
+ import polars as pl
+
+ data = pl.DataFrame(
+ {
+ "int_col": [1, 2, 3, 4, 5],
+ "float_col": [1.5, 2.5, 3.5, 4.5, 5.5],
+ "bool_col": [True, False, True, True, False],
+ }
+ )
+ manager = NarwhalsTableManager.from_dataframe(data)
+
+ int_stats = manager.get_stats("int_col")
+ assert int_stats == ColumnStats(
+ total=5,
+ nulls=0,
+ unique=5,
+ min=1,
+ max=5,
+ mean=3.0,
+ median=3.0,
+ std=1.5811388300841898,
+ p5=1.0,
+ p25=2.0,
+ p75=4.0,
+ p95=5.0,
+ )
+ assert isinstance(int_stats.min, int)
+ assert isinstance(int_stats.max, int)
+ assert isinstance(int_stats.mean, float)
+
+ float_stats = manager.get_stats("float_col")
+ assert float_stats == ColumnStats(
+ total=5,
+ nulls=0,
+ min=1.5,
+ max=5.5,
+ mean=3.5,
+ median=3.5,
+ std=1.5811388300841898,
+ p5=1.5,
+ p25=2.5,
+ p75=4.5,
+ p95=5.5,
+ )
+ assert isinstance(float_stats.min, float)
+ assert isinstance(float_stats.max, float)
+ assert isinstance(float_stats.mean, float)
+
+ bool_stats = manager.get_stats("bool_col")
+ assert bool_stats == ColumnStats(
+ total=5,
+ nulls=0,
+ true=3,
+ false=2,
+ )
+ assert isinstance(bool_stats.true, int)
+ assert isinstance(bool_stats.false, int)
+
def test_sort_values(self) -> None:
sorted_df = self.manager.sort_values("A", descending=True).data
expected_df = self.data.sort("A", descending=True)
diff --git a/tests/_plugins/ui/_impl/test_table.py b/tests/_plugins/ui/_impl/test_table.py
index ee786f8218..312167ab8b 100644
--- a/tests/_plugins/ui/_impl/test_table.py
+++ b/tests/_plugins/ui/_impl/test_table.py
@@ -892,7 +892,7 @@ def test_with_too_many_rows_column_charts_disabled() -> None:
@pytest.mark.skipif(is_windows(), reason=r"windows returns \r instead")
-def test__get_column_summaries_after_search() -> None:
+def test_get_column_summaries_after_search() -> None:
data = {"a": list(range(20))}
table = ui.table(data)
@@ -910,7 +910,7 @@ def test__get_column_summaries_after_search() -> None:
assert summaries.is_disabled is False
summaries_data = from_data_uri(summaries.data)[1].decode("utf-8")
# Result is csv or json
- assert summaries_data in ["a\n2\n12\n", '[{"a": 2}, {"a": 12}]']
+ assert summaries_data in ["a\n2\n12\n", '[{"a":2},{"a":12}]']
# We don't have column summaries for non-dataframe data
assert summaries.stats["a"].min is None
assert summaries.stats["a"].max is None
@@ -919,7 +919,7 @@ def test__get_column_summaries_after_search() -> None:
@pytest.mark.skipif(
not DependencyManager.pandas.has(), reason="Pandas not installed"
)
-def test__get_column_summaries_after_search_df() -> None:
+def test_get_column_summaries_after_search_df() -> None:
import pandas as pd
table = ui.table(pd.DataFrame({"a": list(range(20))}))
diff --git a/tests/_pyodide/test_bootstrap.py b/tests/_pyodide/test_bootstrap.py
index 1f5e970b92..acb38556b6 100644
--- a/tests/_pyodide/test_bootstrap.py
+++ b/tests/_pyodide/test_bootstrap.py
@@ -1,12 +1,12 @@
# Copyright 2024 Marimo. All rights reserved.
from __future__ import annotations
-import json
from typing import TYPE_CHECKING, Any, Callable
import pytest
from marimo._config.config import DEFAULT_CONFIG
+from marimo._messaging.msgspec_encoder import encode_json_str
from marimo._pyodide.bootstrap import create_session, save_file
from marimo._pyodide.pyodide_session import PyodideSession
from marimo._server.model import SessionMode
@@ -169,7 +169,7 @@ def test_save_file(
# Save the file
save_file(
- request=json.dumps(request.__dict__),
+ request=encode_json_str(request),
filename=str(mock_app_file),
)
diff --git a/tests/_pyodide/test_pyodide_streams.py b/tests/_pyodide/test_pyodide_streams.py
index 93f1cf6ea7..5f051f9969 100644
--- a/tests/_pyodide/test_pyodide_streams.py
+++ b/tests/_pyodide/test_pyodide_streams.py
@@ -1,4 +1,5 @@
import asyncio
+import json
from unittest.mock import Mock
import pytest
@@ -73,8 +74,9 @@ class TestPyodideStdout:
data = "test output"
pyodide_stdout.write(data)
assert pyodide_pipe.call_count == 1
- op, msg = pyodide_pipe.call_args[0][0]
+ op, msg_bytes = pyodide_pipe.call_args[0][0]
assert op == "cell-op"
+ msg = json.loads(msg_bytes)
assert msg["cell_id"] == pyodide_stdout.stream.cell_id
assert msg["console"]["mimetype"] == "text/plain"
assert msg["console"]["data"] == data
@@ -103,8 +105,9 @@ class TestPyodideStderr:
data = "test error"
pyodide_stderr.write(data)
assert pyodide_pipe.call_count == 1
- op, msg = pyodide_pipe.call_args[0][0]
+ op, msg_bytes = pyodide_pipe.call_args[0][0]
assert op == "cell-op"
+ msg = json.loads(msg_bytes)
assert msg["cell_id"] == pyodide_stderr.stream.cell_id
assert msg["console"]["mimetype"] == "text/plain"
assert msg["console"]["data"] == data
@@ -137,8 +140,9 @@ class TestPyodideStdin:
assert result == "test input\n"
# Verify prompt was sent
assert pyodide_pipe.call_count == 1
- op, msg = pyodide_pipe.call_args[0][0]
+ op, msg_bytes = pyodide_pipe.call_args[0][0]
assert op == "cell-op"
+ msg = json.loads(msg_bytes)
assert msg["cell_id"] == pyodide_stdin.stream.cell_id
assert msg["console"]["mimetype"] == "text/plain"
assert msg["console"]["data"] == ""
@@ -156,8 +160,9 @@ class TestPyodideStdin:
assert result == "test input\n"
# Verify prompt was sent
assert pyodide_pipe.call_count == 1
- op, msg = pyodide_pipe.call_args[0][0]
+ op, msg_bytes = pyodide_pipe.call_args[0][0]
assert op == "cell-op"
+ msg = json.loads(msg_bytes)
assert msg["cell_id"] == pyodide_stdin.stream.cell_id
assert msg["console"]["mimetype"] == "text/plain"
assert msg["console"]["data"] == "Enter: "
@@ -179,8 +184,9 @@ class TestPyodideStdin:
assert result == ["line1", "line2", "line3", ""]
# Verify prompt was sent
assert pyodide_pipe.call_count == 1
- op, msg = pyodide_pipe.call_args[0][0]
+ op, msg_bytes = pyodide_pipe.call_args[0][0]
assert op == "cell-op"
+ msg = json.loads(msg_bytes)
assert msg["cell_id"] == pyodide_stdin.stream.cell_id
assert msg["console"]["mimetype"] == "text/plain"
assert msg["console"]["data"] == ""
diff --git a/tests/_pyodide/test_restartable_task.py b/tests/_pyodide/test_restartable_task.py
index 7550b36e55..1843d29fd6 100644
--- a/tests/_pyodide/test_restartable_task.py
+++ b/tests/_pyodide/test_restartable_task.py
@@ -1,5 +1,7 @@
import asyncio
+import pytest
+
from marimo._pyodide.restartable_task import RestartableTask
@@ -122,3 +124,145 @@ async def test_restartable_task_cancellation():
await start_task
except asyncio.CancelledError:
pass
+
+
+async def test_stop_before_start_assertion():
+ """Test stopping a task before it's started should raise assertion error."""
+
+ async def dummy_coro():
+ await asyncio.sleep(0.1)
+
+ task = RestartableTask(dummy_coro)
+
+ # Stop before start should raise assertion error due to task being None
+ with pytest.raises(AssertionError):
+ task.stop()
+
+
+async def test_restart_before_start_assertion():
+ """Test restarting a task before it's started should raise assertion error."""
+
+ async def dummy_coro():
+ await asyncio.sleep(0.1)
+
+ task = RestartableTask(dummy_coro)
+
+ # Restart before start should raise assertion error
+ with pytest.raises(AssertionError):
+ task.restart()
+
+
+async def test_exception_in_coro_stops_task():
+ """Test that exceptions in the coroutine stop the task loop."""
+ counter = 0
+ exception_occurred = False
+
+ async def failing_coro():
+ nonlocal counter, exception_occurred
+ counter += 1
+ exception_occurred = True
+ raise ValueError("Test error")
+
+ task = RestartableTask(failing_coro)
+ start_task = asyncio.create_task(task.start())
+
+ # Let it fail
+ await asyncio.sleep(0.05)
+
+ # Should have tried once and then stopped due to exception
+ assert counter == 1
+ assert exception_occurred
+ assert start_task.done()
+
+ # Cleanup
+ start_task.cancel()
+ try:
+ await start_task
+ except (asyncio.CancelledError, ValueError):
+ pass
+
+
+async def test_task_state_consistency():
+ """Test that task state remains consistent through operations."""
+ call_count = 0
+
+ async def state_coro():
+ nonlocal call_count
+ call_count += 1
+ await asyncio.sleep(0.05)
+
+ task = RestartableTask(state_coro)
+
+ # Initial state
+ assert task.task is None
+ assert not task.stopped
+
+ # Start task
+ start_task = asyncio.create_task(task.start())
+ await asyncio.sleep(0.01)
+
+ # After start
+ assert task.task is not None
+ assert not task.stopped
+ assert not task.task.done()
+
+ # Restart
+ old_task = task.task
+ task.restart()
+ await asyncio.sleep(0.01)
+
+ # After restart
+ assert task.task is not None
+ assert task.task != old_task # New task created
+ assert not task.stopped
+ assert old_task.cancelled()
+
+ # Stop
+ task.stop()
+ await asyncio.sleep(0.01)
+
+ # After stop
+ assert task.stopped
+ assert task.task.cancelled()
+
+ # Cleanup
+ start_task.cancel()
+ try:
+ await start_task
+ except asyncio.CancelledError:
+ pass
+
+
+async def test_zero_delay_coro():
+ """Test with a coroutine that completes immediately."""
+ completion_count = 0
+
+ async def instant_coro():
+ nonlocal completion_count
+ completion_count += 1
+ # Complete immediately, no await
+
+ task = RestartableTask(instant_coro)
+ start_task = asyncio.create_task(task.start())
+
+ # Let it run for a bit - should complete multiple times rapidly
+ await asyncio.sleep(0.01)
+
+ # Should have completed multiple times
+ initial_count = completion_count
+ assert initial_count > 0
+
+ # Stop and verify it stops
+ task.stop()
+ await asyncio.sleep(0.01)
+ final_count = completion_count
+
+ # Should have stopped running
+ assert final_count >= initial_count
+
+ # Cleanup
+ start_task.cancel()
+ try:
+ await start_task
+ except asyncio.CancelledError:
+ pass
diff --git a/tests/_runtime/output/test_output.py b/tests/_runtime/output/test_output.py
index 6c6e94a317..cccbfbc77c 100644
--- a/tests/_runtime/output/test_output.py
+++ b/tests/_runtime/output/test_output.py
@@ -1,6 +1,7 @@
# Copyright 2024 Marimo. All rights reserved.
from __future__ import annotations
+from marimo._messaging.ops import CellOp
from marimo._runtime import output
from tests.conftest import ExecReqProvider, MockedKernel
@@ -22,19 +23,17 @@ async def test_spinner_removed(
]
)
found_progress = False
- for i, msg in enumerate(mocked_kernel.stream.messages):
+ for i, msg in enumerate(mocked_kernel.stream.operations):
if (
- msg[0] == "cell-op"
- and msg[1]["output"] is not None
- and "marimo-progress" in msg[1]["output"]["data"]
+ isinstance(msg, CellOp)
+ and msg.output is not None
+ and "marimo-progress" in msg.output.data
):
# the spinner should be cleared immediately after the context
# manager exits
found_progress = True
# kernel uses text/plain + empty string to denote empty output
- assert (
- mocked_kernel.stream.messages[i + 1][1]["output"]["data"] == ""
- )
+ assert mocked_kernel.stream.operations[i + 1].output.data == ""
assert found_progress
@@ -59,9 +58,9 @@ async def test_mutating_appended_outputs(
]
)
outputs: list[str] = []
- for msg in mocked_kernel.stream.messages:
- if msg[0] == "cell-op" and msg[1]["output"] is not None:
- outputs.append(msg[1]["output"]["data"])
+ for msg in mocked_kernel.stream.operations:
+ if isinstance(msg, CellOp) and msg.output is not None:
+ outputs.append(str(msg.output.data))
assert len(outputs) == 2
assert "before" in outputs[0]
assert "before" in outputs[1]
@@ -84,9 +83,9 @@ async def test_nested_output(
]
)
outputs: list[str] = []
- for msg in mocked_kernel.stream.messages:
- if msg[0] == "cell-op" and msg[1]["output"] is not None:
- outputs.append(msg[1]["output"]["data"])
+ for msg in mocked_kernel.stream.operations:
+ if isinstance(msg, CellOp) and msg.output is not None:
+ outputs.append(str(msg.output.data))
assert len(outputs) == 1
assert outputs[0] == "['hi', [...], [...], [...], [...], [...]]"
diff --git a/tests/_runtime/test_capture.py b/tests/_runtime/test_capture.py
index d1c21a60e5..a92c7aace1 100644
--- a/tests/_runtime/test_capture.py
+++ b/tests/_runtime/test_capture.py
@@ -1,16 +1,16 @@
# Copyright 2024 Marimo. All rights reserved.
from __future__ import annotations
+import json
import re
-from typing import Any
+from marimo._messaging.types import KernelMessage
from tests.conftest import ExecReqProvider, MockedKernel
-def _has_output(
- messages: list[tuple[str, dict[Any, Any]]], pattern: str
-) -> bool:
+def _has_output(messages: list[KernelMessage], pattern: str) -> bool:
for op, data in messages:
+ data = json.loads(data)
if (
op == "cell-op"
and data["output"] is not None
diff --git a/tests/_runtime/test_complete.py b/tests/_runtime/test_complete.py
index 44ccf788bb..f665cfc036 100644
--- a/tests/_runtime/test_complete.py
+++ b/tests/_runtime/test_complete.py
@@ -14,7 +14,7 @@ import pytest
import marimo
from marimo._dependencies.dependencies import DependencyManager
from marimo._messaging.ops import CompletionResult
-from marimo._messaging.types import Stream
+from marimo._messaging.types import KernelMessage, Stream
from marimo._runtime.complete import (
_build_docstring_cached,
_maybe_get_key_options,
@@ -195,6 +195,10 @@ def test_parameter_descriptions(obj: Any, runtime_inference: bool):
)
if path.endswith("dummy_func"):
pytest.skip("Not picking up parameters for dummy_func")
+ if path.endswith("ChatMessage"):
+ pytest.skip(
+ "ChatMessage is a msgspec struct which does not support Jedi dict completions"
+ )
call = f"{path}("
code = f"import {import_name};{call}"
jedi.settings.auto_import_modules = ["marimo"] if runtime_inference else []
@@ -211,7 +215,7 @@ def test_parameter_descriptions(obj: Any, runtime_inference: bool):
if param.kind in {param.VAR_KEYWORD, param.VAR_POSITIONAL}:
continue
assert param_name in param_completions, (
- f"Jedi did not suggest {param_name} in {call}"
+ f"Jedi did not suggest {param_name} in {call}. It suggested {param_completions.keys()}"
)
jedi_param = param_completions[param_name]
docstring = jedi_param.docstring()
@@ -359,11 +363,17 @@ def test_maybe_get_key_options_pandas_dataframe(
class CaptureStream(Stream):
def __init__(self):
- self.messages: list[tuple[str, dict[Any, Any]]] = []
+ self.messages: list[KernelMessage] = []
- def write(self, op: str, data: dict[Any, Any]) -> None:
+ def write(self, op: str, data: bytes) -> None:
self.messages.append((op, data))
+ @property
+ def operations(self) -> list[dict[str, Any]]:
+ import json
+
+ return [json.loads(op_data) for _op_name, op_data in self.messages]
+
# TODO add test cases for all other completion modalities
# TODO improve coupling between variable name, source code, and assertions
@@ -470,14 +480,14 @@ mixed_keys = {"static_key": "foo", str(random.randint(0, 10)): "bar"}
stream=local_stream,
)
- messages = local_stream.messages
- message_name, content = messages[0]
+ message_name = local_stream.messages[0]
+ content = local_stream.operations[0]
prefix_length = content["prefix_length"]
options = content["options"]
options_values = [option["name"] for option in options]
- assert len(messages) == 1
- assert message_name == CompletionResult.name
+ assert len(local_stream.messages) == 1
+ assert message_name[0] == CompletionResult.name
# TODO if `expects_completions=False`, something else than `_maybe_get_key_options()`
# could be returning values
if expects_key_completion is False:
@@ -487,7 +497,7 @@ mixed_keys = {"static_key": "foo", str(random.randint(0, 10)): "bar"}
assert all(option["type"] == "property" for option in options)
assert all(option["completion_info"] == "key" for option in options)
- expected_keys: list[str]
+ expected_keys: list[str] = []
if object_name == "static_key":
# from source code in variable `other_cells_code`
expected_keys = ["static_key"]
diff --git a/tests/_runtime/test_patches.py b/tests/_runtime/test_patches.py
index 878d4363bd..f16d543af3 100644
--- a/tests/_runtime/test_patches.py
+++ b/tests/_runtime/test_patches.py
@@ -13,6 +13,7 @@ from marimo._runtime.capture import capture_stderr
from marimo._runtime.patches import patch_polars_write_json
from marimo._runtime.runtime import Kernel
from marimo._utils.platform import is_pyodide
+from tests._messaging.mocks import MockStream
from tests.conftest import ExecReqProvider
if TYPE_CHECKING:
@@ -168,9 +169,10 @@ async def test_webbrowser_injection(
)
assert "webbrowser" in mocked_kernel.k.globals
outputs: list[str] = []
- for msg in mocked_kernel.stream.messages:
- if msg[0] == "cell-op" and msg[1]["output"] is not None:
- outputs.append(msg[1]["output"]["data"])
+ stream = MockStream(mocked_kernel.stream)
+ for msg in stream.operations:
+ if msg["op"] == "cell-op" and msg["output"] is not None:
+ outputs.append(msg["output"]["data"])
assert "<iframe" in outputs[-1]
@@ -196,9 +198,10 @@ async def test_webbrowser_easter_egg(
)
assert "antigravity" in mocked_kernel.k.globals
outputs: list[str] = []
- for msg in mocked_kernel.stream.messages:
- if msg[0] == "cell-op" and msg[1]["output"] is not None:
- outputs.append(msg[1]["output"]["data"])
+ stream = MockStream(mocked_kernel.stream)
+ for msg in stream.operations:
+ if msg["op"] == "cell-op" and msg["output"] is not None:
+ outputs.append(msg["output"]["data"])
assert "<iframe" not in outputs[-1]
assert "<img" in outputs[-1]
diff --git a/tests/_runtime/test_query_params.py b/tests/_runtime/test_query_params.py
index 5213a40cc6..8fcdfb1efc 100644
--- a/tests/_runtime/test_query_params.py
+++ b/tests/_runtime/test_query_params.py
@@ -63,7 +63,7 @@ class TestQueryParams(unittest.TestCase):
assert self.mock_stream.write.call_count == 1
assert self.mock_stream.write.call_args[1] == {
"op": "query-params-set",
- "data": {"key": "key3", "value": "value4"},
+ "data": b'{"op":"query-params-set","key":"key3","value":"value4"}',
}
def test_setitem_null(self) -> None:
@@ -73,7 +73,7 @@ class TestQueryParams(unittest.TestCase):
assert self.mock_stream.write.call_count == 1
assert self.mock_stream.write.call_args[1] == {
"op": "query-params-delete",
- "data": {"key": "key1", "value": None},
+ "data": b'{"op":"query-params-delete","key":"key1","value":null}',
}
def test_setitem_empty(self) -> None:
@@ -83,7 +83,7 @@ class TestQueryParams(unittest.TestCase):
assert self.mock_stream.write.call_count == 1
assert self.mock_stream.write.call_args[1] == {
"op": "query-params-delete",
- "data": {"key": "key1", "value": None},
+ "data": b'{"op":"query-params-delete","key":"key1","value":null}',
}
def test_set(self) -> None:
@@ -93,7 +93,7 @@ class TestQueryParams(unittest.TestCase):
assert self.mock_stream.write.call_count == 1
assert self.mock_stream.write.call_args[1] == {
"op": "query-params-set",
- "data": {"key": "key1", "value": "value5"},
+ "data": b'{"op":"query-params-set","key":"key1","value":"value5"}',
}
def test_set_null(self) -> None:
@@ -103,7 +103,7 @@ class TestQueryParams(unittest.TestCase):
assert self.mock_stream.write.call_count == 1
assert self.mock_stream.write.call_args[1] == {
"op": "query-params-delete",
- "data": {"key": "key1", "value": None},
+ "data": b'{"op":"query-params-delete","key":"key1","value":null}',
}
def test_set_empty(self) -> None:
@@ -113,7 +113,7 @@ class TestQueryParams(unittest.TestCase):
assert self.mock_stream.write.call_count == 1
assert self.mock_stream.write.call_args[1] == {
"op": "query-params-delete",
- "data": {"key": "key1", "value": None},
+ "data": b'{"op":"query-params-delete","key":"key1","value":null}',
}
def test_append(self) -> None:
@@ -125,11 +125,11 @@ class TestQueryParams(unittest.TestCase):
assert self.mock_stream.write.call_count == 2
assert self.mock_stream.write.call_args_list[0][1] == {
"op": "query-params-append",
- "data": {"key": "key1", "value": "value5"},
+ "data": b'{"op":"query-params-append","key":"key1","value":"value5"}',
}
assert self.mock_stream.write.call_args_list[1][1] == {
"op": "query-params-append",
- "data": {"key": "key4", "value": "value6"},
+ "data": b'{"op":"query-params-append","key":"key4","value":"value6"}',
}
def test_delete(self) -> None:
@@ -151,15 +151,15 @@ class TestQueryParams(unittest.TestCase):
assert self.mock_stream.write.call_count == 3
assert self.mock_stream.write.call_args_list[0][1] == {
"op": "query-params-delete",
- "data": {"key": "key1", "value": None},
+ "data": b'{"op":"query-params-delete","key":"key1","value":null}',
}
assert self.mock_stream.write.call_args_list[1][1] == {
"op": "query-params-append",
- "data": {"key": "key2", "value": "value4"},
+ "data": b'{"op":"query-params-append","key":"key2","value":"value4"}',
}
assert self.mock_stream.write.call_args_list[2][1] == {
"op": "query-params-delete",
- "data": {"key": "key2", "value": None},
+ "data": b'{"op":"query-params-delete","key":"key2","value":null}',
}
def test_remove(self) -> None:
@@ -173,11 +173,11 @@ class TestQueryParams(unittest.TestCase):
assert self.mock_stream.write.call_count == 2
assert self.mock_stream.write.call_args_list[0][1] == {
"op": "query-params-delete",
- "data": {"key": "key2", "value": "value2"},
+ "data": b'{"op":"query-params-delete","key":"key2","value":"value2"}',
}
assert self.mock_stream.write.call_args_list[1][1] == {
"op": "query-params-delete",
- "data": {"key": "key2", "value": None},
+ "data": b'{"op":"query-params-delete","key":"key2","value":null}',
}
def test_clear(self) -> None:
@@ -189,7 +189,7 @@ class TestQueryParams(unittest.TestCase):
assert self.mock_stream.write.call_count == 1
assert self.mock_stream.write.call_args_list[0][1] == {
"op": "query-params-clear",
- "data": {},
+ "data": b'{"op":"query-params-clear"}',
}
diff --git a/tests/_runtime/test_runtime.py b/tests/_runtime/test_runtime.py
index 26e83a097d..2f4e3e260b 100644
--- a/tests/_runtime/test_runtime.py
+++ b/tests/_runtime/test_runtime.py
@@ -4,8 +4,7 @@ from __future__ import annotations
import pathlib
import sys
import textwrap
-from dataclasses import dataclass
-from typing import TYPE_CHECKING
+from typing import TYPE_CHECKING, cast
from unittest.mock import Mock, patch
import pytest
@@ -17,6 +16,8 @@ from marimo._messaging.cell_output import CellChannel
from marimo._messaging.errors import (
CycleError,
Error,
+ MarimoExceptionRaisedError,
+ MarimoInternalError,
MarimoStrictExecutionError,
MarimoSyntaxError,
MultipleDefinitionError,
@@ -42,6 +43,7 @@ from marimo._runtime.scratch import SCRATCH_CELL_ID
from marimo._server.model import SessionMode
from marimo._utils import parse_dataclass
from marimo._utils.parse_dataclass import parse_raw
+from tests._messaging.mocks import MockStderr, MockStream
from tests.conftest import ExecReqProvider, MockedKernel
if TYPE_CHECKING:
@@ -1501,22 +1503,24 @@ except NameError:
)
# Runtime error expected- since not a kernel error check stderr
assert "C" not in k.globals
+ stream = MockStream(k.stream)
+ stderr = MockStderr(k.stderr)
if k.execution_type == "strict":
assert (
"name `R` is referenced before definition."
- in k.stream.messages[-4][1]["output"]["data"][0]["msg"]
+ in stream.operations[-4]["output"]["data"][0]["msg"]
)
assert (
"This cell wasn't run"
- in k.stream.messages[-1][1]["output"]["data"][0]["msg"]
+ in stream.operations[-1]["output"]["data"][0]["msg"]
)
else:
assert (
"Name `C` is not defined. It was expected to be defined in"
- in k.stream.messages[-2][1]["output"]["data"][0]["msg"]
+ in stream.operations[-2]["output"]["data"][0]["msg"]
)
- assert "NameError" in k.stderr.messages[0]
- assert "NameError" in k.stderr.messages[-1]
+ assert "NameError" in stderr.messages[0]
+ assert "NameError" in stderr.messages[-1]
@staticmethod
async def test_run_scratch(mocked_kernel: MockedKernel) -> None:
@@ -1524,17 +1528,15 @@ except NameError:
await k.run_scratchpad("x = 1; x")
# Has no errors
assert not k.errors
- messages = mocked_kernel.stream.messages
- (m1, m2, m3, m4) = messages
- assert all(m[0] == "cell-op" for m in messages)
- assert all(m[1]["cell_id"] == SCRATCH_CELL_ID for m in messages)
- assert m1[1]["status"] == "queued"
- assert m2[1]["status"] == "running"
- assert m3[1]["status"] is None
- assert (
- m3[1]["output"]["data"] == "<pre style='font-size: 12px'>1</pre>"
- )
- assert m4[1]["status"] == "idle"
+ stream = MockStream(mocked_kernel.stream)
+ (m1, m2, m3, m4) = stream.operations
+ assert all(m["op"] == "cell-op" for m in stream.operations)
+ assert all(m["cell_id"] == SCRATCH_CELL_ID for m in stream.operations)
+ assert m1["status"] == "queued"
+ assert m2["status"] == "running"
+ assert m3["status"] is None
+ assert m3["output"]["data"] == "<pre style='font-size: 12px'>1</pre>"
+ assert m4["status"] == "idle"
# Does not pollute globals
assert "x" not in k.globals
@@ -1556,10 +1558,11 @@ except NameError:
await k.run_scratchpad("y = z * 2; y")
# Has no errors
assert not k.errors
- messages = mocked_kernel.stream.messages
+ stream = MockStream(mocked_kernel.stream)
+ messages = stream.operations
output_message = messages[-2]
assert (
- output_message[1]["output"]["data"]
+ output_message["output"]["data"]
== "<pre style='font-size: 12px'>20</pre>"
)
assert "z" in k.globals
@@ -1584,10 +1587,11 @@ except NameError:
await k.run_scratchpad("z = 20; z")
# Has no errors
assert not k.errors
- messages = mocked_kernel.stream.messages
+ stream = MockStream(mocked_kernel.stream)
+ messages = stream.operations
output_message = messages[-2]
assert (
- output_message[1]["output"]["data"]
+ output_message["output"]["data"]
== "<pre style='font-size: 12px'>20</pre>"
)
assert "z" in k.globals
@@ -1621,10 +1625,11 @@ except NameError:
k = mocked_kernel.k
await k.run([exec_req.get("print(2)")])
+ stream = MockStream(mocked_kernel.stream)
cell_ops = [
parse_raw(op_data, CellOp)
- for op_name, op_data in mocked_kernel.stream.messages
- if op_name == "cell-op"
+ for op_data in stream.operations
+ if op_data["op"] == "cell-op"
]
assert len(cell_ops) == 4 # queued -> running -> output -> idle
@@ -3002,7 +3007,7 @@ class TestStateTransitions:
from an imported module wouldn't update the frontend's dependency info.
"""
k = mocked_kernel.k
- stream = mocked_kernel.stream
+ stream = MockStream(mocked_kernel.stream)
# Cell 1: Define multiple variables
await k.run([exec_req.get("a = 1\nb = 2")])
@@ -3012,13 +3017,15 @@ class TestStateTransitions:
er_2 = exec_req.get("print(a)\nprint(b)")
await k.run([er_2])
variables_msg_count = sum(
- 1 for m in stream.messages if m[0] == "variables"
+ 1 for m in stream.operations if m["op"] == "variables"
)
assert variables_msg_count == 1
# Check that both a and b show cell 2 in their used_by
- variables_msg = next(m for m in stream.messages if m[0] == "variables")
- variables = variables_msg[1]["variables"]
+ variables_msg = next(
+ m for m in stream.operations if m["op"] == "variables"
+ )
+ variables = variables_msg["variables"]
var_a = next(v for v in variables if v["name"] == "a")
var_b = next(v for v in variables if v["name"] == "b")
assert er_2.cell_id in var_a["used_by"]
@@ -3030,13 +3037,15 @@ class TestStateTransitions:
# Should broadcast Variables because usage changed
variables_msg_count = sum(
- 1 for m in stream.messages if m[0] == "variables"
+ 1 for m in stream.operations if m["op"] == "variables"
)
assert variables_msg_count == 1
# Check that only a shows cell 2 in used_by now
- variables_msg = next(m for m in stream.messages if m[0] == "variables")
- variables = variables_msg[1]["variables"]
+ variables_msg = next(
+ m for m in stream.operations if m["op"] == "variables"
+ )
+ variables = variables_msg["variables"]
var_a = next(v for v in variables if v["name"] == "a")
var_b = next(v for v in variables if v["name"] == "b")
assert er_2.cell_id in var_a["used_by"]
@@ -3055,7 +3064,7 @@ class TestErrorHandling:
errors = _parse_error_output(error_cell_op[0])
assert len(errors) == 1
- assert errors[0].type == "exception"
+ assert isinstance(errors[0], MarimoExceptionRaisedError)
assert errors[0].msg == "some secret error"
assert errors[0].exception_type == "ValueError"
@@ -3070,7 +3079,7 @@ class TestErrorHandling:
errors = _parse_error_output(error_cell_op[0])
assert len(errors) == 1
- assert errors[0].type == "internal"
+ assert isinstance(errors[0], MarimoInternalError)
assert errors[0].msg.startswith("An internal error occurred: ")
async def test_error_handling_in_run_mode_stop(
@@ -3089,7 +3098,7 @@ class TestErrorHandling:
for op in error_cell_op:
errors = _parse_error_output(op)
assert len(errors) == 1
- assert errors[0].type == "internal"
+ assert isinstance(errors[0], MarimoInternalError)
assert errors[0].msg.startswith("An internal error occurred: ")
@@ -3123,12 +3132,7 @@ def _parse_error_output(cell_op: CellOp) -> list[Error]:
assert error_output.channel == CellChannel.MARIMO_ERROR
assert error_output.mimetype == "application/vnd.marimo+error"
data = error_output.data
-
- @dataclass
- class Container:
- errors: list[Error]
-
- return parse_raw({"errors": data}, Container).errors
+ return cast(list[Error], data)
def _filter_to_error_ops(cell_ops: list[CellOp]) -> list[CellOp]:
diff --git a/tests/_runtime/test_threads.py b/tests/_runtime/test_threads.py
index 7df085ef68..86029b3dad 100644
--- a/tests/_runtime/test_threads.py
+++ b/tests/_runtime/test_threads.py
@@ -1,10 +1,19 @@
import time
+from typing import Any, cast
+from marimo._messaging.types import KernelMessage
from marimo._runtime.requests import DeleteCellRequest
from marimo._runtime.runtime import Kernel
+from tests._messaging.mocks import MockStream
from tests.conftest import ExecReqProvider
+def _msg_as_dict(msg: KernelMessage) -> dict[str, Any]:
+ import json
+
+ return json.loads(msg[1].decode("utf-8"))
+
+
# Doesn't work with strict kernel ...
async def test_thread_set_global(k: Kernel, exec_req: ExecReqProvider) -> None:
"""Test that a thread starts and runs."""
@@ -89,15 +98,17 @@ async def test_thread_output_append(
assert not k.errors
time.sleep(0.01) # noqa: ASYNC251
# The main thread should not have any output, but the new thread should
- stream = k.globals["stream"]
- for m in stream.messages:
- if m[0] == "cell-op" and m[1]["output"] is not None:
- assert "hello" not in m[1]["output"]["data"]
- assert "world" not in m[1]["output"]["data"]
- thread_stream = k.globals["thread_stream"]
- assert len(thread_stream.messages) == 2
- assert "hello" in thread_stream.messages[0][1]["output"]["data"]
- assert "world" in thread_stream.messages[1][1]["output"]["data"]
+ messages = cast(list[KernelMessage], k.globals["stream"].messages)
+ for m in messages:
+ if m[0] == "cell-op" and _msg_as_dict(m)["output"] is not None:
+ assert "hello" not in _msg_as_dict(m)["output"]["data"]
+ assert "world" not in _msg_as_dict(m)["output"]["data"]
+ thread_stream_messages = cast(
+ list[KernelMessage], k.globals["thread_stream"].messages
+ )
+ assert len(thread_stream_messages) == 2
+ assert "hello" in _msg_as_dict(thread_stream_messages[0])["output"]["data"]
+ assert "world" in _msg_as_dict(thread_stream_messages[1])["output"]["data"]
async def test_thread_print(k: Kernel, exec_req: ExecReqProvider) -> None:
@@ -126,16 +137,16 @@ async def test_thread_print(k: Kernel, exec_req: ExecReqProvider) -> None:
assert not k.errors
time.sleep(0.01) # noqa: ASYNC251
# The main thread should not have any output, but the new thread should
- stream = k.globals["stream"]
- for m in stream.messages:
- assert ("console" not in m[1]) or not m[1]["console"]
-
- thread_stream = k.globals["thread_stream"]
- assert len(thread_stream.messages) == 2
- assert "hello" in thread_stream.messages[0][1]["console"]["data"]
- assert thread_stream.messages[0][1]["console"]["channel"] == "stdout"
- assert "world" in thread_stream.messages[1][1]["console"]["data"]
- assert thread_stream.messages[1][1]["console"]["channel"] == "stdout"
+ stream = MockStream(k.globals["stream"])
+ for m in stream.operations:
+ assert ("console" not in m) or not m["console"]
+
+ thread_stream = MockStream(k.globals["thread_stream"])
+ assert len(thread_stream.operations) == 2
+ assert "hello" in thread_stream.operations[0]["console"]["data"]
+ assert thread_stream.operations[0]["console"]["channel"] == "stdout"
+ assert "world" in thread_stream.operations[1]["console"]["data"]
+ assert thread_stream.operations[1]["console"]["channel"] == "stdout"
async def test_thread_should_exit_on_rerun(
diff --git a/tests/_runtime/test_trace.py b/tests/_runtime/test_trace.py
index 69a455d816..7ccabf3b94 100644
--- a/tests/_runtime/test_trace.py
+++ b/tests/_runtime/test_trace.py
@@ -9,6 +9,7 @@ from marimo._runtime.requests import (
ExecutionRequest,
)
from marimo._runtime.runtime import Kernel
+from tests._messaging.mocks import MockStderr, MockStream
class TestScriptTrace:
@@ -161,8 +162,9 @@ class TestAppTrace:
)
# Naively strip tags to check trace
+ stderr_messages = MockStderr(k.stderr)
tag_re = re.compile(r"(<!--.*?-->|<[^>]*>)")
- result = k.stderr.messages[-1]
+ result = stderr_messages.messages[-1]
result = tag_re.sub("", result)
assert "ZeroDivisionError: division by zero" in result
@@ -258,24 +260,29 @@ class TestAppTrace:
),
]
)
+
# Runtime error expected- since not a kernel error check stderr
+
+ stream_messages = MockStream(k.stream)
+ stderr_messages = MockStderr(k.stderr)
+
assert "C" not in k.globals
if k.execution_type == "strict":
assert (
"name `R` is referenced before definition."
- in k.stream.messages[-4][1]["output"]["data"][0]["msg"]
+ in stream_messages.operations[-4]["output"]["data"][0]["msg"]
)
assert (
"This cell wasn't run"
- in k.stream.messages[-1][1]["output"]["data"][0]["msg"]
+ in stream_messages.operations[-1]["output"]["data"][0]["msg"]
)
else:
assert (
"Name `C` is not defined."
- in k.stream.messages[-2][1]["output"]["data"][0]["msg"]
+ in stream_messages.operations[-2]["output"]["data"][0]["msg"]
)
- assert "NameError" in k.stderr.messages[0]
- assert "NameError" in k.stderr.messages[-1]
+ assert "NameError" in stderr_messages.messages[0]
+ assert "NameError" in stderr_messages.messages[-1]
class TestEmbedTrace:
diff --git a/tests/_server/api/endpoints/test_ai.py b/tests/_server/api/endpoints/test_ai.py
index d08decf1e0..e50ee642ca 100644
--- a/tests/_server/api/endpoints/test_ai.py
+++ b/tests/_server/api/endpoints/test_ai.py
@@ -91,7 +91,7 @@ class TestOpenAiEndpoints:
headers=HEADERS,
json={
"prompt": "Help me create a dataframe",
- "include_other_code": "",
+ "includeOtherCode": "",
"code": "",
},
)
@@ -131,7 +131,7 @@ class TestOpenAiEndpoints:
headers=HEADERS,
json={
"prompt": "Help me create a dataframe",
- "include_other_code": "",
+ "includeOtherCode": "",
"code": "",
},
)
@@ -177,7 +177,7 @@ class TestOpenAiEndpoints:
json={
"prompt": "Help me create a dataframe",
"code": "<rewrite_this>import pandas as pd</rewrite_this>",
- "include_other_code": "",
+ "includeOtherCode": "",
},
)
assert response.status_code == 200, response.text
@@ -219,7 +219,7 @@ class TestOpenAiEndpoints:
json={
"prompt": "Help me create a dataframe",
"code": "<rewrite_this>import pandas as pd</rewrite_this>",
- "include_other_code": "",
+ "includeOtherCode": "",
},
)
assert response.status_code == 200, response.text
@@ -259,7 +259,7 @@ class TestOpenAiEndpoints:
json={
"prompt": "Help me create a dataframe",
"code": "<rewrite_this>import pandas as pd</rewrite_this>",
- "include_other_code": "",
+ "includeOtherCode": "",
},
)
assert response.status_code == 200, response.text
@@ -418,7 +418,7 @@ class TestAnthropicAiEndpoints:
headers=HEADERS,
json={
"prompt": "Help me create a dataframe",
- "include_other_code": "",
+ "includeOtherCode": "",
"code": "",
},
)
@@ -455,7 +455,7 @@ class TestAnthropicAiEndpoints:
json={
"prompt": "Help me create a dataframe",
"code": "<rewrite_this>import pandas as pd</rewrite_this>",
- "include_other_code": "",
+ "includeOtherCode": "",
},
)
assert response.status_code == 200, response.text
@@ -558,7 +558,7 @@ class TestGoogleAiEndpoints:
json={
"prompt": "Help me create a dataframe",
"code": "<rewrite_this>import pandas as pd</rewrite_this>",
- "include_other_code": "",
+ "includeOtherCode": "",
},
)
assert response.status_code == 200, response.text
@@ -596,7 +596,7 @@ class TestGoogleAiEndpoints:
headers=HEADERS,
json={
"prompt": "Help me create a dataframe",
- "include_other_code": "",
+ "includeOtherCode": "",
"code": "",
},
)
@@ -772,7 +772,7 @@ def test_chat_without_code(client: TestClient) -> None:
"messages": [{"role": "user", "content": "Hello"}],
"model": "gpt-4-turbo",
"variables": [],
- "include_other_code": "",
+ "includeOtherCode": "",
"context": {},
"id": "123",
},
@@ -818,7 +818,7 @@ def test_chat_with_code(client: TestClient) -> None:
],
"model": "gpt-4-turbo",
"variables": [],
- "include_other_code": "import pandas as pd",
+ "includeOtherCode": "import pandas as pd",
"context": {},
"id": "123",
},
@@ -1043,7 +1043,7 @@ class TestInvokeToolEndpoint:
"/api/ai/invoke_tool",
headers=HEADERS,
json={
- "tool_name": "test_tool",
+ "toolName": "test_tool",
"arguments": {"param1": "value1", "param2": 42},
},
)
@@ -1053,7 +1053,7 @@ class TestInvokeToolEndpoint:
# Verify response structure
assert response_data["success"] is True
- assert response_data["tool_name"] == "test_tool"
+ assert response_data["toolName"] == "test_tool"
assert response_data["result"] == {
"message": "Tool executed successfully",
"data": [1, 2, 3],
@@ -1088,7 +1088,7 @@ class TestInvokeToolEndpoint:
"/api/ai/invoke_tool",
headers=HEADERS,
json={
- "tool_name": "failing_tool",
+ "toolName": "failing_tool",
"arguments": {"invalid_param": "bad_value"},
},
)
@@ -1098,7 +1098,7 @@ class TestInvokeToolEndpoint:
# Verify response structure for error case
assert response_data["success"] is False
- assert response_data["tool_name"] == "failing_tool"
+ assert response_data["toolName"] == "failing_tool"
assert response_data["result"] is None
assert (
response_data["error"]
@@ -1132,7 +1132,7 @@ class TestInvokeToolEndpoint:
response = client.post(
"/api/ai/invoke_tool",
headers=HEADERS,
- json={"tool_name": "nonexistent_tool", "arguments": {}},
+ json={"toolName": "nonexistent_tool", "arguments": {}},
)
assert response.status_code == 200, response.text
@@ -1140,7 +1140,7 @@ class TestInvokeToolEndpoint:
# Verify response structure for not found case
assert response_data["success"] is False
- assert response_data["tool_name"] == "nonexistent_tool"
+ assert response_data["toolName"] == "nonexistent_tool"
assert response_data["result"] is None
assert "not found" in response_data["error"]
@@ -1172,7 +1172,7 @@ class TestInvokeToolEndpoint:
"/api/ai/invoke_tool",
headers=HEADERS,
json={
- "tool_name": "test_tool",
+ "toolName": "test_tool",
"arguments": {"optional_param": "value"},
},
)
@@ -1182,7 +1182,7 @@ class TestInvokeToolEndpoint:
# Verify response structure for validation error
assert response_data["success"] is False
- assert response_data["tool_name"] == "test_tool"
+ assert response_data["toolName"] == "test_tool"
assert response_data["result"] is None
assert "Invalid arguments" in response_data["error"]
assert "required_param" in response_data["error"]
@@ -1233,7 +1233,7 @@ class TestInvokeToolEndpoint:
response = client.post(
"/api/ai/invoke_tool",
headers=HEADERS,
- json={"tool_name": "complex_tool", "arguments": complex_args},
+ json={"toolName": "complex_tool", "arguments": complex_args},
)
assert response.status_code == 200, response.text
@@ -1241,7 +1241,7 @@ class TestInvokeToolEndpoint:
# Verify response structure
assert response_data["success"] is True
- assert response_data["tool_name"] == "complex_tool"
+ assert response_data["toolName"] == "complex_tool"
assert "processed_data" in response_data["result"]
assert "summary" in response_data["result"]
assert "metadata" in response_data["result"]
@@ -1256,7 +1256,7 @@ class TestInvokeToolEndpoint:
headers={
"Authorization": "Bearer fake-token"
}, # No session header
- json={"tool_name": "test_tool", "arguments": {}},
+ json={"toolName": "test_tool", "arguments": {}},
)
# Should fail without proper session
@@ -1290,13 +1290,13 @@ class TestInvokeToolEndpoint:
"/api/ai/invoke_tool",
headers=HEADERS,
json={
- "tool_name": "test_tool",
+ "toolName": "test_tool",
"arguments": {}, # Empty arguments
},
)
assert response.status_code == 200, response.text
data = response.json()
- assert data["tool_name"] == "test_tool"
+ assert data["toolName"] == "test_tool"
assert data["result"]["message"] == "Tool executed with empty args"
assert data["error"] is None
diff --git a/tests/_server/api/endpoints/test_datasources.py b/tests/_server/api/endpoints/test_datasources.py
index c04646f3cd..752d37d03c 100644
--- a/tests/_server/api/endpoints/test_datasources.py
+++ b/tests/_server/api/endpoints/test_datasources.py
@@ -21,10 +21,10 @@ def test_preview_column(client: TestClient) -> None:
"/api/datasources/preview_column",
headers=HEADERS,
json={
- "source_type": "connection",
+ "sourceType": "connection",
"source": "test_source",
- "table_name": "test_table",
- "column_name": "test_column",
+ "tableName": "test_table",
+ "columnName": "test_column",
},
)
assert response.status_code == 200, response.text
@@ -38,11 +38,11 @@ def test_preview_sql_table(client: TestClient) -> None:
"/api/datasources/preview_sql_table",
headers=HEADERS,
json={
- "request_id": "test_request_id",
+ "requestId": "test_request_id",
"engine": "test_engine",
"database": "test_db",
"schema": "test_schema",
- "table_name": "test_table",
+ "tableName": "test_table",
},
)
assert response.status_code == 200, response.text
@@ -56,7 +56,7 @@ def test_preview_sql_table_list(client: TestClient) -> None:
"/api/datasources/preview_sql_table_list",
headers=HEADERS,
json={
- "request_id": "test_request_id",
+ "requestId": "test_request_id",
"engine": "test_engine",
"database": "test_db",
"schema": "test_schema",
@@ -87,10 +87,10 @@ def test_fails_in_read_mode(client: TestClient) -> None:
"/api/datasources/preview_column",
headers=HEADERS,
json={
- "source_type": "connection",
+ "sourceType": "connection",
"source": "test_source",
- "table_name": "test_table",
- "column_name": "test_column",
+ "tableName": "test_table",
+ "columnName": "test_column",
},
)
assert response.status_code == 401
@@ -99,11 +99,11 @@ def test_fails_in_read_mode(client: TestClient) -> None:
"/api/datasources/preview_sql_table",
headers=HEADERS,
json={
- "request_id": "test_request_id",
+ "requestId": "test_request_id",
"engine": "test_engine",
"database": "test_db",
"schema": "test_schema",
- "table_name": "test_table",
+ "tableName": "test_table",
},
)
assert response.status_code == 401
@@ -112,7 +112,7 @@ def test_fails_in_read_mode(client: TestClient) -> None:
"/api/datasources/preview_sql_table_list",
headers=HEADERS,
json={
- "request_id": "test_request_id",
+ "requestId": "test_request_id",
"engine": "test_engine",
"database": "test_db",
"schema": "test_schema",
diff --git a/tests/_server/api/endpoints/test_editing.py b/tests/_server/api/endpoints/test_editing.py
index 75b7d84ec9..a4b53e9f89 100644
--- a/tests/_server/api/endpoints/test_editing.py
+++ b/tests/_server/api/endpoints/test_editing.py
@@ -23,7 +23,7 @@ def test_code_autocomplete(client: TestClient) -> None:
json={
"id": "completion-123",
"document": "print('Hello, World!')",
- "cell_id": "cell-123",
+ "cellId": "cell-123",
},
)
assert response.status_code == 200, response.text
@@ -37,7 +37,7 @@ def test_delete_cell(client: TestClient) -> None:
"/api/kernel/delete",
headers=HEADERS,
json={
- "cell_id": "cell-123",
+ "cellId": "cell-123",
},
)
assert response.status_code == 200, response.text
@@ -54,7 +54,7 @@ def test_format_cell(client: TestClient) -> None:
"codes": {
"cell-123": "def foo():\n return 1",
},
- "line_length": 80,
+ "lineLength": 80,
},
)
assert response.status_code == 200, response.text
diff --git a/tests/_server/api/endpoints/test_execution.py b/tests/_server/api/endpoints/test_execution.py
index ce1faff6f6..9ed08b70d0 100644
--- a/tests/_server/api/endpoints/test_execution.py
+++ b/tests/_server/api/endpoints/test_execution.py
@@ -31,7 +31,7 @@ class TestExecutionRoutes_EditMode:
"/api/kernel/set_ui_element_value",
headers=HEADERS,
json={
- "object_ids": ["ui-element-1", "ui-element-2"],
+ "objectIds": ["ui-element-1", "ui-element-2"],
"values": ["value1", "value2"],
},
)
@@ -46,9 +46,9 @@ class TestExecutionRoutes_EditMode:
"/api/kernel/instantiate",
headers=HEADERS,
json={
- "object_ids": ["ui-element-1", "ui-element-2"],
+ "objectIds": ["ui-element-1", "ui-element-2"],
"values": ["value1", "value2"],
- "auto_run": True,
+ "autoRun": True,
},
)
assert response.status_code == 200, response.text
@@ -62,9 +62,9 @@ class TestExecutionRoutes_EditMode:
"/api/kernel/instantiate",
headers=HEADERS,
json={
- "object_ids": ["ui-element-1", "ui-element-2"],
+ "objectIds": ["ui-element-1", "ui-element-2"],
"values": ["value1", "value2"],
- "auto_run": False,
+ "autoRun": False,
},
)
assert response.status_code == 200, response.text
@@ -78,9 +78,9 @@ class TestExecutionRoutes_EditMode:
"/api/kernel/function_call",
headers=HEADERS,
json={
- "function_call_id": "call-123",
+ "functionCallId": "call-123",
"namespace": "namespace1",
- "function_name": "function1",
+ "functionName": "function1",
"args": {"arg1": "value1"},
},
)
@@ -95,10 +95,10 @@ class TestExecutionRoutes_EditMode:
"/api/kernel/set_model_value",
headers=HEADERS,
json={
- "model_id": "model-1",
+ "modelId": "model-1",
"message": {
"state": {"key": "value"},
- "buffer_paths": [["a"], ["b"]],
+ "bufferPaths": [["a"], ["b"]],
},
"buffers": ["buffer1", "buffer2"],
},
@@ -139,7 +139,7 @@ class TestExecutionRoutes_EditMode:
"/api/kernel/run",
headers=HEADERS,
json={
- "cell_ids": ["cell-1", "cell-2"],
+ "cellIds": ["cell-1", "cell-2"],
"codes": ["print('Hello, cell-1')", "print('Hello, cell-2')"],
},
)
@@ -192,7 +192,7 @@ class TestExecutionRoutes_EditMode:
"/api/kernel/run",
headers=HEADERS,
json={
- "cell_ids": ["test-1"],
+ "cellIds": ["test-1"],
"codes": [
"import marimo as mo\n"
"import json\n"
@@ -238,7 +238,7 @@ class TestExecutionRoutes_RunMode:
"/api/kernel/set_ui_element_value",
headers=HEADERS,
json={
- "object_ids": ["ui-element-1", "ui-element-2"],
+ "objectIds": ["ui-element-1", "ui-element-2"],
"values": ["value1", "value2"],
},
)
@@ -253,9 +253,9 @@ class TestExecutionRoutes_RunMode:
"/api/kernel/instantiate",
headers=HEADERS,
json={
- "object_ids": ["ui-element-1", "ui-element-2"],
+ "objectIds": ["ui-element-1", "ui-element-2"],
"values": ["value1", "value2"],
- "auto_run": True,
+ "autoRun": True,
},
)
assert response.status_code == 200, response.text
@@ -269,9 +269,9 @@ class TestExecutionRoutes_RunMode:
"/api/kernel/instantiate",
headers=HEADERS,
json={
- "object_ids": ["ui-element-1", "ui-element-2"],
+ "objectIds": ["ui-element-1", "ui-element-2"],
"values": ["value1", "value2"],
- "auto_run": False,
+ "autoRun": False,
},
)
assert response.status_code == 200, response.text
@@ -285,9 +285,9 @@ class TestExecutionRoutes_RunMode:
"/api/kernel/function_call",
headers=HEADERS,
json={
- "function_call_id": "call-123",
+ "functionCallId": "call-123",
"namespace": "namespace1",
- "function_name": "function1",
+ "functionName": "function1",
"args": {"arg1": "value1"},
},
)
@@ -302,10 +302,10 @@ class TestExecutionRoutes_RunMode:
"/api/kernel/set_model_value",
headers=HEADERS,
json={
- "model_id": "model-1",
+ "modelId": "model-1",
"message": {
"state": {"key": "value"},
- "buffer_paths": [["a"], ["b"]],
+ "bufferPaths": [["a"], ["b"]],
},
"buffers": ["buffer1", "buffer2"],
},
@@ -333,7 +333,7 @@ class TestExecutionRoutes_RunMode:
"/api/kernel/run",
headers=HEADERS,
json={
- "cell_ids": ["cell-1", "cell-2"],
+ "cellIds": ["cell-1", "cell-2"],
"codes": ["print('Hello, cell-1')", "print('Hello, cell-2')"],
},
)
@@ -357,12 +357,12 @@ class TestExecutionRoutes_RunMode:
@staticmethod
@with_session(SESSION_ID)
- def with_read_session(client: TestClient) -> None:
+ def test_app_meta_request(client: TestClient) -> None:
response = client.post(
"/api/kernel/run",
headers=HEADERS,
json={
- "cell_ids": ["test-1"],
+ "cellIds": ["test-1"],
"codes": [
"import marimo as mo\n"
"import json\n"
@@ -386,6 +386,7 @@ class TestExecutionRoutes_RunMode:
"cookies",
"headers",
"user",
+ "meta",
"path_params",
"query_params",
"url",
@@ -416,5 +417,10 @@ def get_printed_object(
if console:
break
assert console
+ if console.mimetype in (
+ "application/vnd.marimo+error",
+ "application/vnd.marimo+traceback",
+ ):
+ pytest.fail(f"Console is an error: {console.data}")
assert isinstance(console.data, str)
return json.loads(console.data)
diff --git a/tests/_server/api/endpoints/test_export.py b/tests/_server/api/endpoints/test_export.py
index 11e8fccf0e..d00c9e787c 100644
--- a/tests/_server/api/endpoints/test_export.py
+++ b/tests/_server/api/endpoints/test_export.py
@@ -49,7 +49,7 @@ def test_export_html(client: TestClient) -> None:
json={
"download": False,
"files": [],
- "include_code": True,
+ "includeCode": True,
},
)
body = response.text
@@ -71,7 +71,7 @@ def test_export_html_skew_protection(client: TestClient) -> None:
json={
"download": False,
"files": [],
- "include_code": True,
+ "includeCode": True,
},
)
assert response.status_code == 401
@@ -89,7 +89,7 @@ def test_export_html_no_code(client: TestClient) -> None:
json={
"download": False,
"files": [],
- "include_code": False,
+ "includeCode": False,
},
)
body = response.text
@@ -108,7 +108,7 @@ def test_export_html_file_not_found(client: TestClient) -> None:
json={
"download": False,
"files": ["/test-10.csv"],
- "include_code": True,
+ "includeCode": True,
},
)
assert response.status_code == 200
@@ -127,7 +127,7 @@ def test_export_html_no_code_in_read(client: TestClient) -> None:
json={
"download": False,
"files": [],
- "include_code": True,
+ "includeCode": True,
},
)
body = response.text
@@ -143,7 +143,7 @@ def test_export_html_no_code_in_read(client: TestClient) -> None:
json={
"download": False,
"files": [],
- "include_code": False,
+ "includeCode": False,
},
)
body = response.text
@@ -222,7 +222,7 @@ def test_auto_export_html(client: TestClient, temp_marimo_file: str) -> None:
json={
"download": False,
"files": [],
- "include_code": True,
+ "includeCode": True,
},
)
assert response.status_code == 200
@@ -234,7 +234,7 @@ def test_auto_export_html(client: TestClient, temp_marimo_file: str) -> None:
json={
"download": False,
"files": [],
- "include_code": True,
+ "includeCode": True,
},
)
# Not modified response
@@ -267,7 +267,7 @@ def test_auto_export_html_no_code(
json={
"download": False,
"files": [],
- "include_code": False,
+ "includeCode": False,
},
)
assert response.status_code == 200
@@ -279,7 +279,7 @@ def test_auto_export_html_no_code(
json={
"download": False,
"files": [],
- "include_code": False,
+ "includeCode": False,
},
)
# Not modified response
@@ -306,7 +306,7 @@ def test_auto_export_html_no_operations(
json={
"download": False,
"files": [],
- "include_code": True,
+ "includeCode": True,
},
)
# Not modified response
@@ -407,7 +407,7 @@ def test_auto_export_ipynb_with_new_cell(
"/api/kernel/run",
headers=HEADERS,
json={
- "cell_ids": ["new_cell"],
+ "cellIds": ["new_cell"],
"codes": ["3.14"],
},
)
@@ -420,7 +420,7 @@ def test_auto_export_ipynb_with_new_cell(
"/api/kernel/save",
headers=HEADERS,
json={
- "cell_ids": ["new_cell"],
+ "cellIds": ["new_cell"],
"filename": temp_marimo_file,
"codes": ["3.14"],
"names": ["_"],
@@ -494,7 +494,7 @@ def test_export_html_with_script_config(client: TestClient) -> None:
json={
"download": False,
"files": [],
- "include_code": False,
+ "includeCode": False,
},
)
body = response.text
@@ -514,7 +514,7 @@ def test_auto_export_html_unnamed_file(client: TestClient) -> None:
json={
"download": False,
"files": [],
- "include_code": True,
+ "includeCode": True,
},
)
@@ -536,7 +536,7 @@ def test_export_html_unnamed_file(client: TestClient) -> None:
json={
"download": False,
"files": [],
- "include_code": True,
+ "includeCode": True,
},
)
diff --git a/tests/_server/api/endpoints/test_file_explorer.py b/tests/_server/api/endpoints/test_file_explorer.py
index 3b48955177..bf39c25ecd 100644
--- a/tests/_server/api/endpoints/test_file_explorer.py
+++ b/tests/_server/api/endpoints/test_file_explorer.py
@@ -96,7 +96,7 @@ def test_move_file_or_directory(client: TestClient) -> None:
headers=HEADERS,
json={
"path": test_file_path,
- "new_path": os.path.join(test_dir, "renamed.txt"),
+ "newPath": os.path.join(test_dir, "renamed.txt"),
},
)
assert response.status_code == 200, response.text
diff --git a/tests/_server/api/endpoints/test_files.py b/tests/_server/api/endpoints/test_files.py
index bf4d3a9698..b7d75b3a97 100644
--- a/tests/_server/api/endpoints/test_files.py
+++ b/tests/_server/api/endpoints/test_files.py
@@ -5,7 +5,9 @@ import os
import random
from pathlib import Path
from typing import TYPE_CHECKING
+from unittest.mock import Mock, patch
+import msgspec
import pytest
from tests._server.conftest import get_session_manager
@@ -78,13 +80,13 @@ def test_save_file(client: TestClient) -> None:
"/api/kernel/save",
headers=HEADERS,
json={
- "cell_ids": ["1"],
+ "cellIds": ["1"],
"filename": str(path),
"codes": ["import marimo as mo"],
"names": ["my_cell"],
"configs": [
{
- "hideCode": True,
+ "hide_code": True,
"disabled": False,
}
],
@@ -106,13 +108,13 @@ def test_save_file(client: TestClient) -> None:
"/api/kernel/save",
headers=HEADERS,
json={
- "cell_ids": ["1"],
+ "cellIds": ["1"],
"filename": str(path),
"codes": ["import marimo as mo"],
"names": ["__"],
"configs": [
{
- "hideCode": False,
+ "hide_code": False,
}
],
},
@@ -141,13 +143,13 @@ def test_save_with_header(client: TestClient) -> None:
"/api/kernel/save",
headers=HEADERS,
json={
- "cell_ids": ["1"],
+ "cellIds": ["1"],
"filename": str(path),
"codes": ["import marimo as mo"],
"names": ["my_cell"],
"configs": [
{
- "hideCode": True,
+ "hide_code": True,
"disabled": False,
}
],
@@ -193,13 +195,13 @@ def test_save_with_invalid_file(client: TestClient) -> None:
"/api/kernel/save",
headers=HEADERS,
json={
- "cell_ids": ["1"],
+ "cellIds": ["1"],
"filename": str(path),
"codes": ["import marimo as mo"],
"names": ["my_cell"],
"configs": [
{
- "hideCode": True,
+ "hide_code": True,
"disabled": False,
}
],
@@ -230,13 +232,13 @@ def test_save_file_cannot_rename(client: TestClient) -> None:
"/api/kernel/save",
headers=HEADERS,
json={
- "cell_ids": ["1"],
+ "cellIds": ["1"],
"filename": "random_filename.py",
"codes": ["import marimo as mo"],
"names": ["my_cell"],
"configs": [
{
- "hideCode": True,
+ "hide_code": True,
"disabled": False,
}
],
@@ -324,7 +326,7 @@ def test_rename_propagates(
"/api/kernel/run",
headers=HEADERS,
json={
- "cell_ids": ["cell-1", "cell-2"],
+ "cellIds": ["cell-1", "cell-2"],
"codes": ["b = __file__", "a = 'x' + __file__"],
},
)
@@ -366,3 +368,98 @@ def test_rename_propagates(
assert ("x" + new_filename).startswith(variables["a"])
assert new_filename.startswith(variables["b"])
+
+
+# Edge case tests
+@with_session(SESSION_ID)
+def test_read_code_without_saved_file(client: TestClient) -> None:
+ """Test read_code when file hasn't been saved yet."""
+ from marimo._server.api.status import HTTPStatus
+
+ # Mock the session to have no file path
+ with patch("marimo._server.api.endpoints.files.AppState") as mock_state:
+ mock_session = Mock()
+ mock_session.app_file_manager.path = None
+ mock_state.return_value.require_current_session.return_value = (
+ mock_session
+ )
+
+ response = client.post(
+ "/api/kernel/read_code",
+ headers=HEADERS,
+ json={},
+ )
+
+ assert response.status_code == HTTPStatus.BAD_REQUEST
+ assert (
+ "File must be saved before downloading"
+ in response.json()["detail"]
+ )
+
+
+@with_session(SESSION_ID)
+def test_save_with_unicode_content(client: TestClient) -> None:
+ """Test save endpoint with unicode and special characters."""
+ filename = get_session_manager(client).file_router.get_unique_file_key()
+ assert filename
+ path = Path(filename)
+
+ unicode_code = """# Unicode test: 你好世界 🌍 ñáéíóú
+def test():
+ return "Hello 世界" """
+
+ response = client.post(
+ "/api/kernel/save",
+ headers=HEADERS,
+ json={
+ "cellIds": ["1"],
+ "filename": str(path),
+ "codes": [unicode_code],
+ "names": ["unicode_cell"],
+ "configs": [{}],
+ },
+ )
+ assert response.status_code == 200
+
+ def _assert_contents():
+ file_contents = path.read_text(encoding="utf-8")
+ assert "你好世界" in file_contents
+ assert "🌍" in file_contents
+
+ try_assert_n_times(5, _assert_contents)
+
+
+@with_session(SESSION_ID)
+def test_save_with_missing_required_fields(client: TestClient) -> None:
+ """Test save endpoint with missing required fields."""
+ # Missing codes field
+ with pytest.raises(msgspec.ValidationError):
+ client.post(
+ "/api/kernel/save",
+ headers=HEADERS,
+ json={
+ "cellIds": ["1"],
+ "filename": "test.py",
+ "names": ["my_cell"],
+ "configs": [{}],
+ },
+ )
+
+
+def test_endpoints_without_authentication(client: TestClient) -> None:
+ """Test endpoints without proper authentication headers."""
+ endpoints_and_methods = [
+ ("/api/kernel/read_code", "post"),
+ ("/api/kernel/rename", "post"),
+ ("/api/kernel/save", "post"),
+ ("/api/kernel/copy", "post"),
+ ("/api/kernel/save_app_config", "post"),
+ ]
+
+ for endpoint, method in endpoints_and_methods:
+ response = getattr(client, method)(
+ endpoint,
+ json={"test": "data"},
+ )
+ # Should require authentication
+ assert response.status_code in [401, 403, 422]
diff --git a/tests/_server/api/endpoints/test_home.py b/tests/_server/api/endpoints/test_home.py
index eed083b147..a9bf907bcf 100644
--- a/tests/_server/api/endpoints/test_home.py
+++ b/tests/_server/api/endpoints/test_home.py
@@ -72,7 +72,7 @@ def test_shutdown_session(client: TestClient) -> None:
response = client.post(
"/api/home/shutdown_session",
headers=HEADERS,
- json={"session_id": SESSION_ID},
+ json={"sessionId": SESSION_ID},
)
assert response.status_code == 200
assert response.json() == {"files": []}
@@ -84,7 +84,7 @@ def test_open_tutorial(client: TestClient) -> None:
response = client.post(
"/api/home/tutorial/open",
headers=HEADERS,
- json={"tutorial_id": "intro"},
+ json={"tutorialId": "intro"},
)
assert response.status_code == 200
data = response.json()
@@ -97,7 +97,7 @@ def test_cant_open_non_tutorial(client: TestClient) -> None:
response = client.post(
"/api/home/tutorial/open",
headers=HEADERS,
- json={"tutorial_id": "non-tutorial"},
+ json={"tutorialId": "non-tutorial"},
)
assert response.status_code == 400
assert response.json() == {"detail": "Tutorial not found"}
diff --git a/tests/_server/api/endpoints/test_kiosk.py b/tests/_server/api/endpoints/test_kiosk.py
index eeb82f4f3d..107300e663 100644
--- a/tests/_server/api/endpoints/test_kiosk.py
+++ b/tests/_server/api/endpoints/test_kiosk.py
@@ -1,11 +1,11 @@
# Copyright 2024 Marimo. All rights reserved.
from __future__ import annotations
-from dataclasses import asdict
from typing import TYPE_CHECKING, Any, Optional
import pytest
+from marimo._messaging.msgspec_encoder import asdict
from marimo._messaging.ops import KernelCapabilities, KernelReady
from marimo._utils.parse_dataclass import parse_raw
from tests._server.mocks import token_header
diff --git a/tests/_server/api/endpoints/test_packages.py b/tests/_server/api/endpoints/test_packages.py
index e32f58b18a..43278d842a 100644
--- a/tests/_server/api/endpoints/test_packages.py
+++ b/tests/_server/api/endpoints/test_packages.py
@@ -2,8 +2,9 @@
from __future__ import annotations
from typing import TYPE_CHECKING, Any
-from unittest.mock import AsyncMock, MagicMock
+from unittest.mock import AsyncMock, MagicMock, patch
+import msgspec
import pytest
from marimo._runtime.packages.package_manager import PackageManager
@@ -58,7 +59,7 @@ def test_add_package(client: TestClient, mock_package_manager: Mock) -> None:
def test_add_package_no_name(
client: TestClient, mock_package_manager: Mock
) -> None:
- with pytest.raises(TypeError):
+ with pytest.raises(msgspec.ValidationError):
client.post(
"/api/packages/add",
headers=HEADERS,
@@ -83,7 +84,7 @@ def test_remove_package(
def test_remove_package_no_name(
client: TestClient, mock_package_manager: Mock
) -> None:
- with pytest.raises(TypeError):
+ with pytest.raises(msgspec.ValidationError):
client.post(
"/api/packages/remove",
headers=HEADERS,
@@ -166,3 +167,377 @@ def test_add_package_without_upgrade(
mock_package_manager.install.assert_called_once_with(
"test-package", version=None, upgrade=False
)
+
+
+def test_add_package_with_complex_version_spec(
+ client: TestClient, mock_package_manager: Mock
+) -> None:
+ """Test add_package with complex version specifications."""
+ response = client.post(
+ "/api/packages/add",
+ headers=HEADERS,
+ json={"package": "package>=1.0.0,<2.0.0"},
+ )
+ assert response.status_code == 200
+ mock_package_manager.install.assert_called_once()
+
+
+def test_add_package_with_empty_string(
+ client: TestClient, mock_package_manager: Mock
+) -> None:
+ """Test add_package with empty package name."""
+ response = client.post(
+ "/api/packages/add",
+ headers=HEADERS,
+ json={"package": ""},
+ )
+ assert response.status_code in [200, 400, 422]
+ mock_package_manager.install.assert_called_once()
+
+
+def test_remove_package_with_empty_string(
+ client: TestClient, mock_package_manager: Mock
+) -> None:
+ """Test remove_package with empty package name."""
+ response = client.post(
+ "/api/packages/remove",
+ headers=HEADERS,
+ json={"package": ""},
+ )
+ assert response.status_code in [200, 400, 422]
+ mock_package_manager.uninstall.assert_called_once()
+
+
+def mock_package_manager_not_installed(
+ monkeypatch: pytest.MonkeyPatch,
+) -> PackageManager:
+ """Mock package manager that is not installed."""
+ mock_manager = MagicMock(spec=PackageManager)
+ mock_manager.is_manager_installed.return_value = False
+ mock_manager.name = "test-manager"
+ mock_manager.docs_url = "https://example.com/docs"
+ mock_manager.alert_not_installed = MagicMock()
+
+ def mock_get_package_manager(request: Any) -> PackageManager:
+ del request
+ return mock_manager
+
+ monkeypatch.setattr(
+ "marimo._server.api.endpoints.packages._get_package_manager",
+ mock_get_package_manager,
+ )
+ return mock_manager
+
+
+def test_add_package_manager_not_installed(
+ client: TestClient, mock_package_manager_not_installed: Mock
+) -> None:
+ """Test add_package when package manager is not installed."""
+ response = client.post(
+ "/api/packages/add",
+ headers=HEADERS,
+ json={"package": "test-package"},
+ )
+ assert response.status_code == 200
+ result = response.json()
+ assert result["success"] is False
+ assert "test-manager is not available" in result["error"]
+ mock_package_manager_not_installed.alert_not_installed.assert_called_once()
+
+
+def test_list_packages_manager_not_installed(
+ client: TestClient, mock_package_manager_not_installed: Mock
+) -> None:
+ """Test list_packages when package manager is not installed."""
+ response = client.get(
+ "/api/packages/list",
+ headers=HEADERS,
+ )
+ assert response.status_code == 200
+ result = response.json()
+ assert result["packages"] == []
+ mock_package_manager_not_installed.alert_not_installed.assert_called_once()
+
+
+def test_package_operations_without_session(client: TestClient) -> None:
+ """Test package operations without session."""
+ headers_no_session = token_header("fake-token")
+
+ endpoints = [
+ ("/api/packages/add", "post"),
+ ("/api/packages/remove", "post"),
+ ("/api/packages/list", "get"),
+ ]
+
+ for endpoint, method in endpoints:
+ if method == "get":
+ response = client.get(endpoint, headers=headers_no_session)
+ else:
+ response = client.post(
+ endpoint,
+ headers=headers_no_session,
+ json={"package": "test-package"},
+ )
+ assert response.status_code in [200, 400, 401, 422]
+
+
+def test_package_operations_with_invalid_authentication(
+ client: TestClient,
+) -> None:
+ """Test package operations with invalid authentication."""
+ invalid_headers = {"Marimo-Session-Id": SESSION_ID} # No token
+
+ endpoints = [
+ ("/api/packages/add", "post"),
+ ("/api/packages/remove", "post"),
+ ("/api/packages/list", "get"),
+ ]
+
+ for endpoint, method in endpoints:
+ if method == "get":
+ response = client.get(endpoint, headers=invalid_headers)
+ else:
+ response = client.post(
+ endpoint,
+ headers=invalid_headers,
+ json={"package": "test-package"},
+ )
+ assert response.status_code in [401, 403, 422]
+
+
+def test_add_package_request_validation(
+ client: TestClient, mock_package_manager: Mock
+) -> None:
+ """Test request validation for add_package endpoint."""
+ invalid_requests = [
+ {}, # Missing package
+ {"package": None}, # Null package
+ {"upgrade": True}, # Missing package
+ ]
+
+ for invalid_request in invalid_requests:
+ with pytest.raises(msgspec.ValidationError):
+ client.post(
+ "/api/packages/add",
+ headers=HEADERS,
+ json=invalid_request,
+ )
+ mock_package_manager.install.assert_not_called()
+
+
+def test_remove_package_request_validation(
+ client: TestClient, mock_package_manager: Mock
+) -> None:
+ """Test request validation for remove_package endpoint."""
+ invalid_requests = [
+ {}, # Missing package
+ {"package": None}, # Null package
+ ]
+
+ for invalid_request in invalid_requests:
+ with pytest.raises(msgspec.ValidationError):
+ client.post(
+ "/api/packages/remove",
+ headers=HEADERS,
+ json=invalid_request,
+ )
+ mock_package_manager.uninstall.assert_not_called()
+
+
+def test_remove_package_manager_not_installed(
+ client: TestClient, mock_package_manager_not_installed: Mock
+) -> None:
+ """Test remove_package when package manager is not installed."""
+ response = client.post(
+ "/api/packages/remove",
+ headers=HEADERS,
+ json={"package": "test-package"},
+ )
+ assert response.status_code == 200
+ result = response.json()
+ assert result["success"] is False
+ assert "test-manager is not available" in result["error"]
+ mock_package_manager_not_installed.alert_not_installed.assert_called_once()
+
+
+def mock_package_manager_with_tree(
+ monkeypatch: pytest.MonkeyPatch,
+) -> PackageManager:
+ """Mock package manager with dependency tree support."""
+ mock_manager = MagicMock(spec=PackageManager)
+ mock_manager.is_manager_installed.return_value = True
+ from marimo._server.models.packages import DependencyTreeNode
+
+ mock_manager.dependency_tree.return_value = DependencyTreeNode(
+ name="root",
+ version="1.0.0",
+ tags=[],
+ dependencies=[
+ DependencyTreeNode(
+ name="child",
+ version="0.1.0",
+ tags=[{"kind": "extra", "value": "dev"}],
+ dependencies=[],
+ )
+ ],
+ )
+
+ def mock_get_package_manager(request: Any) -> PackageManager:
+ del request
+ return mock_manager
+
+ monkeypatch.setattr(
+ "marimo._server.api.endpoints.packages._get_package_manager",
+ mock_get_package_manager,
+ )
+ return mock_manager
+
+
+def test_dependency_tree(
+ client: TestClient, mock_package_manager_with_tree: Mock
+) -> None:
+ """Test dependency tree endpoint."""
+ response = client.get(
+ "/api/packages/tree",
+ headers=HEADERS,
+ )
+ assert response.status_code == 200
+ result = response.json()
+ assert "tree" in result
+ tree = result["tree"]
+ assert tree is not None
+ assert tree["name"] == "root"
+ assert tree["version"] == "1.0.0"
+ assert len(tree["dependencies"]) == 1
+ assert tree["dependencies"][0]["name"] == "child"
+ assert tree["dependencies"][0]["version"] == "0.1.0"
+ mock_package_manager_with_tree.dependency_tree.assert_called_once()
+
+
+def test_dependency_tree_no_tree(
+ client: TestClient, mock_package_manager: Mock
+) -> None:
+ """Test dependency tree endpoint when no tree is available."""
+ mock_package_manager.dependency_tree.return_value = None
+ response = client.get(
+ "/api/packages/tree",
+ headers=HEADERS,
+ )
+ assert response.status_code == 200
+ result = response.json()
+ assert result["tree"] is None
+ mock_package_manager.dependency_tree.assert_called_once()
+
+
+def test_dependency_tree_without_session(client: TestClient) -> None:
+ """Test dependency tree without session."""
+ headers_no_session = token_header("fake-token")
+ response = client.get(
+ "/api/packages/tree",
+ headers=headers_no_session,
+ )
+ assert response.status_code in [200, 400, 401, 422]
+
+
+def mock_package_manager_with_metadata(
+ monkeypatch: pytest.MonkeyPatch,
+) -> PackageManager:
+ """Mock package manager with metadata update functionality."""
+ mock_manager = MagicMock(spec=PackageManager)
+ mock_manager.install = AsyncMock(return_value=True)
+ mock_manager.uninstall = AsyncMock(return_value=True)
+ mock_manager.is_manager_installed.return_value = True
+ mock_manager.update_notebook_script_metadata = MagicMock()
+
+ def mock_get_package_manager(request: Any) -> PackageManager:
+ del request
+ return mock_manager
+
+ monkeypatch.setattr(
+ "marimo._server.api.endpoints.packages._get_package_manager",
+ mock_get_package_manager,
+ )
+ return mock_manager
+
+
+def test_add_package_with_metadata_update(
+ client: TestClient, mock_package_manager_with_metadata: Mock
+) -> None:
+ """Test add_package calls metadata update when MANAGE_SCRIPT_METADATA is enabled."""
+ with patch(
+ "marimo._config.settings.GLOBAL_SETTINGS.MANAGE_SCRIPT_METADATA", True
+ ):
+ with patch(
+ "marimo._server.api.endpoints.packages._get_filename",
+ return_value="test.py",
+ ):
+ response = client.post(
+ "/api/packages/add",
+ headers=HEADERS,
+ json={"package": "test-package"},
+ )
+ assert response.status_code == 200
+ result = response.json()
+ assert result == {"success": True, "error": None}
+ mock_package_manager_with_metadata.update_notebook_script_metadata.assert_called_once()
+
+
+def test_remove_package_with_metadata_update(
+ client: TestClient, mock_package_manager_with_metadata: Mock
+) -> None:
+ """Test remove_package calls metadata update when MANAGE_SCRIPT_METADATA is enabled."""
+ with patch(
+ "marimo._config.settings.GLOBAL_SETTINGS.MANAGE_SCRIPT_METADATA", True
+ ):
+ with patch(
+ "marimo._server.api.endpoints.packages._get_filename",
+ return_value="test.py",
+ ):
+ response = client.post(
+ "/api/packages/remove",
+ headers=HEADERS,
+ json={"package": "test-package"},
+ )
+ assert response.status_code == 200
+ result = response.json()
+ assert result == {"success": True, "error": None}
+ mock_package_manager_with_metadata.update_notebook_script_metadata.assert_called_once()
+
+
+def test_add_package_no_metadata_update_when_disabled(
+ client: TestClient, mock_package_manager_with_metadata: Mock
+) -> None:
+ """Test add_package doesn't call metadata update when MANAGE_SCRIPT_METADATA is disabled."""
+ with patch(
+ "marimo._config.settings.GLOBAL_SETTINGS.MANAGE_SCRIPT_METADATA", False
+ ):
+ response = client.post(
+ "/api/packages/add",
+ headers=HEADERS,
+ json={"package": "test-package"},
+ )
+ assert response.status_code == 200
+ mock_package_manager_with_metadata.update_notebook_script_metadata.assert_not_called()
+
+
+def test_add_package_no_metadata_update_when_no_filename(
+ client: TestClient, mock_package_manager_with_metadata: Mock
+) -> None:
+ """Test add_package doesn't call metadata update when no filename is available."""
+ with patch(
+ "marimo._config.settings.GLOBAL_SETTINGS.MANAGE_SCRIPT_METADATA", True
+ ):
+ with patch(
+ "marimo._server.api.endpoints.packages._get_filename",
+ return_value=None,
+ ):
+ response = client.post(
+ "/api/packages/add",
+ headers=HEADERS,
+ json={"package": "test-package"},
+ )
+ assert response.status_code == 200
+ mock_package_manager_with_metadata.update_notebook_script_metadata.assert_not_called()
diff --git a/tests/_server/api/endpoints/test_resume_session.py b/tests/_server/api/endpoints/test_resume_session.py
index c6f557e2c8..fa941db62d 100644
--- a/tests/_server/api/endpoints/test_resume_session.py
+++ b/tests/_server/api/endpoints/test_resume_session.py
@@ -3,12 +3,12 @@ from __future__ import annotations
import time
from contextlib import contextmanager
-from dataclasses import asdict
from typing import TYPE_CHECKING, Any, Optional
import pytest
from marimo._config.manager import UserConfigManager
+from marimo._messaging.msgspec_encoder import asdict
from marimo._messaging.ops import CellOp, KernelCapabilities, KernelReady
from marimo._server.sessions import Session
from marimo._types.ids import SessionId
@@ -57,6 +57,7 @@ def assert_kernel_ready_response(
raw_data: dict[str, Any], response: dict[str, Any]
) -> None:
data = parse_raw(raw_data["data"], KernelReady)
+ print(response)
expected = parse_raw(response, KernelReady)
assert data.cell_ids == expected.cell_ids
assert data.codes == expected.codes
@@ -79,6 +80,7 @@ def get_session(
def test_refresh_session(client: TestClient) -> None:
with client.websocket_connect("/ws?session_id=123") as websocket:
data = websocket.receive_json()
+ print(data)
assert_kernel_ready_response(data, create_response({}))
# Check the session still exists after closing the websocket
@@ -98,7 +100,7 @@ def test_refresh_session(client: TestClient) -> None:
with client.websocket_connect("/ws?session_id=456") as websocket:
# First message is the kernel reconnected
data = websocket.receive_json()
- assert data == {"op": "reconnected", "data": {}}
+ assert data == {"op": "reconnected", "data": {"op": "reconnected"}}
# Resume the session
data = websocket.receive_json()
assert_kernel_ready_response(
@@ -115,7 +117,7 @@ def test_refresh_session(client: TestClient) -> None:
"/api/kernel/set_ui_element_value",
headers=headers("456"),
json={
- "object_ids": ["ui-element-1", "ui-element-2"],
+ "objectIds": ["ui-element-1", "ui-element-2"],
"values": ["value1", "value2"],
},
)
@@ -130,7 +132,7 @@ def test_refresh_session(client: TestClient) -> None:
with client.websocket_connect("/ws?session_id=789") as websocket:
# First message is the kernel reconnected
data = websocket.receive_json()
- assert data == {"op": "reconnected", "data": {}}
+ assert data == {"op": "reconnected", "data": {"op": "reconnected"}}
# Resume the session
data = websocket.receive_json()
assert_kernel_ready_response(
@@ -170,7 +172,7 @@ def test_save_session(client: TestClient) -> None:
"/api/kernel/save",
headers=headers("123"),
json={
- "cell_ids": ["2", "1"],
+ "cellIds": ["2", "1"],
"filename": filename,
"codes": [
"slider = mo.ui.slider(0, 100)",
@@ -198,7 +200,7 @@ def test_save_session(client: TestClient) -> None:
with client.websocket_connect("/ws?session_id=456") as websocket:
# First message is the kernel reconnected
data = websocket.receive_json()
- assert data == {"op": "reconnected", "data": {}}
+ assert data == {"op": "reconnected", "data": {"op": "reconnected"}}
# Resume the session
data = websocket.receive_json()
assert_kernel_ready_response(
@@ -318,7 +320,7 @@ def test_resume_session_with_watch(client: TestClient) -> None:
data = websocket.receive_json()
assert data == {
"op": "update-cell-ids",
- "data": {"cell_ids": ["MJUe", "Hbol"]},
+ "data": {"cell_ids": ["MJUe", "Hbol"], "op": "update-cell-ids"},
}
data = websocket.receive_json()
assert data == {
@@ -327,6 +329,7 @@ def test_resume_session_with_watch(client: TestClient) -> None:
"cell_ids": ["MJUe"],
"code_is_stale": False,
"codes": ["x=10; x"],
+ "op": "update-cell-codes",
},
}
@@ -335,7 +338,7 @@ def test_resume_session_with_watch(client: TestClient) -> None:
with client.websocket_connect("/ws?session_id=456") as websocket:
# First message is the kernel reconnected
data = websocket.receive_json()
- assert data == {"op": "reconnected", "data": {}}
+ assert data == {"op": "reconnected", "data": {"op": "reconnected"}}
# Check for KernelReady message
data = websocket.receive_json()
@@ -356,7 +359,7 @@ def test_resume_session_with_watch(client: TestClient) -> None:
assert messages[0]["op"] == "banner"
assert messages[1] == {
"op": "update-cell-ids",
- "data": {"cell_ids": ["MJUe", "Hbol"]},
+ "data": {"cell_ids": ["MJUe", "Hbol"], "op": "update-cell-ids"},
}
session = get_session(client, "456")
diff --git a/tests/_server/api/endpoints/test_ws.py b/tests/_server/api/endpoints/test_ws.py
index d3cb6a6f71..168e055d42 100644
--- a/tests/_server/api/endpoints/test_ws.py
+++ b/tests/_server/api/endpoints/test_ws.py
@@ -2,7 +2,6 @@
from __future__ import annotations
from contextlib import contextmanager
-from dataclasses import asdict
from pathlib import Path
from typing import TYPE_CHECKING, Any, Optional
@@ -11,6 +10,7 @@ from starlette.websockets import WebSocketDisconnect
from marimo._config.config import ExperimentalConfig
from marimo._config.manager import UserConfigManager
+from marimo._messaging.msgspec_encoder import asdict
from marimo._messaging.ops import KernelCapabilities, KernelReady
from marimo._server.codes import WebSocketCodes
from marimo._server.model import SessionMode
@@ -105,7 +105,7 @@ def test_disconnect_and_reconnect(client: TestClient) -> None:
# Connect by the same session id
with client.websocket_connect("/ws?session_id=123") as websocket:
data = websocket.receive_json()
- assert data == {"op": "reconnected", "data": {}}
+ assert data == {"op": "reconnected", "data": {"op": "reconnected"}}
data = websocket.receive_json()
assert data["op"] == "alert"
@@ -120,13 +120,13 @@ def test_disconnect_then_reconnect_then_refresh(client: TestClient) -> None:
# Connect by the same session id
with client.websocket_connect("/ws?session_id=123") as websocket:
data = websocket.receive_json()
- assert data == {"op": "reconnected", "data": {}}
+ assert data == {"op": "reconnected", "data": {"op": "reconnected"}}
data = websocket.receive_json()
assert data["op"] == "alert"
# New session with new ID (simulates refresh)
with client.websocket_connect("/ws?session_id=456") as websocket:
data = websocket.receive_json()
- assert data == {"op": "reconnected", "data": {}}
+ assert data == {"op": "reconnected", "data": {"op": "reconnected"}}
data = websocket.receive_json()
assert_kernel_ready_response(data, create_response({"resumed": True}))
@@ -220,7 +220,7 @@ async def test_file_watcher_calls_reload(client: TestClient) -> None:
watcher = list(session_manager.watcher_manager._watchers.values())[0]
await watcher.callback(Path(filename))
data = websocket.receive_json()
- assert data == {"op": "reload", "data": {}}
+ assert data == {"op": "reload", "data": {"op": "reload"}}
session_manager.mode = SessionMode.EDIT
session_manager.watch = False
client.post("/api/kernel/shutdown", headers=HEADERS)
@@ -312,7 +312,7 @@ async def test_connects_to_existing_session_with_same_file(
client.post(
"/api/kernel/instantiate",
headers=headers("123"),
- json={"object_ids": [], "values": [], "auto_run": True},
+ json={"objectIds": [], "values": [], "auto_run": True},
)
messages1 = flush_messages(websocket1, at_least=14)
diff --git a/tests/_server/api/endpoints/test_ws_rtc.py b/tests/_server/api/endpoints/test_ws_rtc.py
index ebea3c6613..3eeb98731a 100644
--- a/tests/_server/api/endpoints/test_ws_rtc.py
+++ b/tests/_server/api/endpoints/test_ws_rtc.py
@@ -2,12 +2,12 @@ from __future__ import annotations
import asyncio
from contextlib import contextmanager
-from dataclasses import asdict
from typing import TYPE_CHECKING, Any, Optional
import pytest
from marimo._config.manager import UserConfigManager
+from marimo._messaging.msgspec_encoder import asdict
from marimo._messaging.ops import KernelCapabilities, KernelReady
from marimo._server.api.endpoints.ws import DOC_MANAGER
from marimo._utils.parse_dataclass import parse_raw
diff --git a/tests/_server/export/snapshots/run_until_completion_with_stack_trace.txt b/tests/_server/export/snapshots/run_until_completion_with_stack_trace.txt
index 25f1bd7e33..bc929167c5 100644
--- a/tests/_server/export/snapshots/run_until_completion_with_stack_trace.txt
+++ b/tests/_server/export/snapshots/run_until_completion_with_stack_trace.txt
@@ -16,10 +16,10 @@
{
"output": [
{
+ "type": "exception",
"msg": "Failed to authenticate. The correct password is 's3cret'.",
"exception_type": "ValueError",
- "raising_cell": null,
- "type": "exception"
+ "raising_cell": null
}
],
"console": [
diff --git a/tests/_server/export/snapshots/run_until_completion_with_stop.txt b/tests/_server/export/snapshots/run_until_completion_with_stop.txt
index 043bc215dd..1cab18710d 100644
--- a/tests/_server/export/snapshots/run_until_completion_with_stop.txt
+++ b/tests/_server/export/snapshots/run_until_completion_with_stop.txt
@@ -12,9 +12,9 @@
{
"output": [
{
+ "type": "ancestor-stopped",
"msg": "This cell wasn't run because an ancestor was stopped with `mo.stop`: ",
- "raising_cell": "MJUe",
- "type": "ancestor-stopped"
+ "raising_cell": "MJUe"
}
],
"console": [],
diff --git a/tests/_server/export/test_exporter.py b/tests/_server/export/test_exporter.py
index 82cca57219..8683842c58 100644
--- a/tests/_server/export/test_exporter.py
+++ b/tests/_server/export/test_exporter.py
@@ -12,8 +12,8 @@ from marimo._ast.app import App, InternalApp
from marimo._config.config import DEFAULT_CONFIG
from marimo._dependencies.dependencies import DependencyManager
from marimo._messaging.cell_output import CellChannel, CellOutput
+from marimo._messaging.msgspec_encoder import encode_json_str
from marimo._messaging.ops import CellOp
-from marimo._plugins.core.json_encoder import WebComponentEncoder
from marimo._server.export import (
export_as_wasm,
run_app_then_export_as_ipynb,
@@ -422,7 +422,9 @@ def _print_messages(messages: list[CellOp]) -> str:
"status": message.status,
}
)
- return json.dumps(result, indent=2, cls=WebComponentEncoder)
+ # Use msgspec for encoding, then format with json for readable snapshots
+ encoded = encode_json_str(result)
+ return json.dumps(json.loads(encoded), indent=2)
def _as_list(data: Any) -> list[Any]:
@@ -807,7 +809,6 @@ def test_export_as_html_with_error_outputs():
from marimo._messaging.errors import MarimoExceptionRaisedError
error = MarimoExceptionRaisedError(
- type="exception",
exception_type="ValueError",
msg="Test error",
raising_cell=cell_ids[0],
diff --git a/tests/_server/session/test_serialize_session.py b/tests/_server/session/test_serialize_session.py
index 141440c27f..ce1afdd8c1 100644
--- a/tests/_server/session/test_serialize_session.py
+++ b/tests/_server/session/test_serialize_session.py
@@ -62,7 +62,7 @@ def test_serialize_session_with_error():
output=CellOutput(
channel=CellChannel.MARIMO_ERROR,
mimetype="application/vnd.marimo+error",
- data=[UnknownError(type="unknown", msg="Something went wrong")],
+ data=[UnknownError(msg="Something went wrong")],
),
console=[],
timestamp=0,
@@ -732,7 +732,7 @@ def test_serialize_session_with_mixed_error_formats():
"traceback": ["line 1", "line 2"],
},
# Object format error
- UnknownError(type="RuntimeError", msg="Runtime error occurred"),
+ UnknownError(msg="Runtime error occurred", error_type="RuntimeError"),
# Dictionary without traceback
{"type": "TypeError", "msg": "Type mismatch"},
]
diff --git a/tests/_server/session/test_session_view.py b/tests/_server/session/test_session_view.py
index 7d301736ad..b6a06b22d8 100644
--- a/tests/_server/session/test_session_view.py
+++ b/tests/_server/session/test_session_view.py
@@ -7,6 +7,7 @@ from unittest.mock import patch
from marimo._ast.cell import RuntimeStateType
from marimo._data.models import DataTable, DataTableColumn
from marimo._messaging.cell_output import CellChannel, CellOutput
+from marimo._messaging.msgspec_encoder import asdict as serialize
from marimo._messaging.ops import (
CellOp,
Datasets,
@@ -19,7 +20,6 @@ from marimo._messaging.ops import (
Variables,
VariableValue,
VariableValues,
- serialize,
)
from marimo._runtime.requests import (
CreationRequest,
@@ -117,8 +117,8 @@ def test_session_view_variable_values() -> None:
# Create VariableValues operation
variable_values_op = VariableValues(
variables=[
- VariableValue(name="var1", value=1),
- VariableValue(name="var2", value="hello"),
+ VariableValue.create(name="var1", value=1),
+ VariableValue.create(name="var2", value="hello"),
]
)
session_view.add_operation(variable_values_op)
@@ -255,7 +255,7 @@ def test_last_run_code() -> None:
def test_serialize_parse_variable_value() -> None:
- original = VariableValue(name="var1", value=1)
+ original = VariableValue.create(name="var1", value=1)
serialized = serialize(original)
assert serialized == {"datatype": "int", "name": "var1", "value": "1"}
parsed = parse_raw(serialized, VariableValue)
@@ -283,8 +283,8 @@ def test_add_variables() -> None:
serialize(
VariableValues(
variables=[
- VariableValue(name="var1", value=1),
- VariableValue(name="var2", value="hello"),
+ VariableValue.create(name="var1", value=1),
+ VariableValue.create(name="var2", value="hello"),
]
)
)
@@ -483,18 +483,21 @@ def test_add_data_source_connections() -> None:
dialect="duckdb",
name="db1",
display_name="duckdb (db1)",
+ databases=[],
),
DataSourceConnection(
source="sqlalchemy",
dialect="postgresql",
name="pg1",
display_name="postgresql (pg1)",
+ databases=[],
),
DataSourceConnection(
source="duckdb",
dialect="default",
name=INTERNAL_DUCKDB_ENGINE,
display_name="duckdb internal",
+ databases=[],
),
]
)
@@ -517,12 +520,14 @@ def test_add_data_source_connections() -> None:
dialect="duckdb",
name="db1",
display_name="duckdb (db1_updated)",
+ databases=[],
),
DataSourceConnection(
source="sqlalchemy",
dialect="mysql",
name="mysql1",
display_name="mysql (mysql1)",
+ databases=[],
),
]
)
diff --git a/tests/_server/test_errors.py b/tests/_server/test_errors.py
index 57d7bbfe6e..a635381e08 100644
--- a/tests/_server/test_errors.py
+++ b/tests/_server/test_errors.py
@@ -2,6 +2,7 @@ from __future__ import annotations
from unittest.mock import MagicMock, patch
+import msgspec
from starlette.exceptions import HTTPException
from starlette.requests import Request
@@ -82,3 +83,10 @@ async def test_non_exception_response():
response = "Not an exception"
result = await handle_error(Request({"type": "http"}), response)
assert result == response
+
+
+async def test_msgspec_validation_error():
+ exc = msgspec.ValidationError("Invalid data")
+ response = await handle_error(Request({"type": "http"}), exc)
+ assert response.status_code == 400
+ assert response.body == b'{"detail":"Invalid data"}'
diff --git a/tests/_sql/test_duckdb.py b/tests/_sql/test_duckdb.py
index 1a6fe66b99..5b4127ff87 100644
--- a/tests/_sql/test_duckdb.py
+++ b/tests/_sql/test_duckdb.py
@@ -150,7 +150,9 @@ def test_duckdb_engine_get_databases_no_conn() -> None:
include_table_details=False,
include_tables=False,
)
- assert initial_databases == [Database(name="memory", dialect="duckdb")]
+ assert initial_databases == [
+ Database(name="memory", dialect="duckdb", schemas=[])
+ ]
assert engine.get_default_database() == "memory"
assert engine.get_default_schema() == "main"
diff --git a/tests/_sql/test_get_engines.py b/tests/_sql/test_get_engines.py
index f5bfe14c99..6c71cb8e69 100644
--- a/tests/_sql/test_get_engines.py
+++ b/tests/_sql/test_get_engines.py
@@ -51,7 +51,9 @@ def test_engine_to_data_source_connection() -> None:
assert connection.display_name == "duckdb (my_duckdb)"
assert connection.default_database == "memory"
assert connection.default_schema == "main"
- assert connection.databases == [Database(name="memory", dialect="duckdb")]
+ assert connection.databases == [
+ Database(name="memory", dialect="duckdb", schemas=[])
+ ]
# Test with ClickhouseEmbedded engine
clickhouse_engine = ClickhouseEmbedded(None)
diff --git a/tests/_utils/test_parse_dataclass.py b/tests/_utils/test_parse_dataclass.py
index cd478f6c74..98295935d3 100644
--- a/tests/_utils/test_parse_dataclass.py
+++ b/tests/_utils/test_parse_dataclass.py
@@ -4,7 +4,7 @@ from __future__ import annotations
import datetime as dt
import json
import sys
-from dataclasses import asdict, dataclass, field
+from dataclasses import dataclass, field
from enum import Enum
from typing import (
Any,
@@ -20,6 +20,7 @@ from typing import (
import pytest
from marimo._config.config import ExperimentalConfigType
+from marimo._messaging.msgspec_encoder import asdict
from marimo._runtime.requests import SetCellConfigRequest
from marimo._types.ids import CellId_t
from marimo._utils.parse_dataclass import parse_raw
@@ -781,8 +782,8 @@ def test_not_required_types() -> None:
data: dict[str, Any] = {
"required": "value",
"optional": "optional_value",
- "optionalDict": {"key": "value"},
- "optionalList": ["item"],
+ "optional_dict": {"key": "value"},
+ "optional_list": ["item"],
}
parsed = parse_raw(data, WithNotRequired)
assert parsed["required"] == "value"
@@ -805,13 +806,12 @@ def test_not_required_types() -> None:
# Test with empty values for container types
data = {
"required": "value",
- "optional": None,
- "optionalDict": {},
- "optionalList": [],
+ "optional_dict": {},
+ "optional_list": [],
}
parsed = parse_raw(data, WithNotRequired)
assert parsed["required"] == "value"
- assert parsed["optional"] is None
+ assert "optional" not in parsed
assert parsed["optional_dict"] == {}
assert parsed["optional_list"] == []
diff --git a/tests/_utils/test_uv_tree.py b/tests/_utils/test_uv_tree.py
index 5361836efc..013b43a8f2 100644
--- a/tests/_utils/test_uv_tree.py
+++ b/tests/_utils/test_uv_tree.py
@@ -1,6 +1,5 @@
from __future__ import annotations
-import dataclasses
import json
import os
import pathlib
@@ -8,6 +7,7 @@ import subprocess
import pytest
+from marimo._messaging.msgspec_encoder import asdict
from marimo._server.models.packages import DependencyTreeNode
from marimo._utils.uv_tree import parse_uv_tree
from tests.mocks import snapshotter
@@ -18,7 +18,7 @@ snapshot_test = snapshotter(__file__)
def serialize(tree: DependencyTreeNode) -> str:
- return json.dumps(dataclasses.asdict(tree), indent=2)
+ return json.dumps(asdict(tree), indent=2)
def uv(cmd: list[str], cwd: str | None = None) -> str:
diff --git a/tests/conftest.py b/tests/conftest.py
index 4b0f0eb738..b6f373e023 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -25,6 +25,7 @@ from marimo._messaging.streams import (
ThreadSafeStdout,
ThreadSafeStream,
)
+from marimo._messaging.types import KernelMessage
from marimo._output.formatters.formatters import register_formatters
from marimo._runtime import patches
from marimo._runtime.context import teardown_context
@@ -66,21 +67,15 @@ class _MockStream(ThreadSafeStream):
pipe: None = None
redirect_console: bool = False
- messages: list[tuple[str, dict[Any, Any]]] = dataclasses.field(
- default_factory=list
- )
+ messages: list[KernelMessage] = dataclasses.field(default_factory=list)
- def write(self, op: str, data: dict[Any, Any]) -> None:
+ def write(self, op: str, data: bytes) -> None:
self.messages.append((op, data))
@property
def operations(self) -> list[MessageOperation]:
- @dataclasses.dataclass
- class Container:
- operation: MessageOperation
-
return [
- parse_raw({"operation": op_data}, Container).operation
+ parse_raw(op_data, cls=MessageOperation)
for _op_name, op_data in self.messages
]