A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
tests: generate notification schema (#7586)
Myles Scolnickbd7caaded055
diff --git a/.github/workflows/test_schemas.yaml b/.github/workflows/test_schemas.yamlindex 725edf50a9..1c0f67b64d 100644--- a/.github/workflows/test_schemas.yaml+++ b/.github/workflows/test_schemas.yaml@@ -17,6 +17,7 @@ jobs:openapi: ${{ steps.filter.outputs.openapi }}session: ${{ steps.filter.outputs.session }}notebook: ${{ steps.filter.outputs.notebook }}+ notifications: ${{ steps.filter.outputs.notifications }}steps:- uses: actions/checkout@v4- uses: dorny/paths-filter@v3@@ -29,6 +30,8 @@ jobs:- 'marimo/_schemas/generated/session.yaml'notebook:- 'marimo/_schemas/generated/notebook.yaml'+ notifications:+ - 'marimo/_schemas/generated/notifications.yaml'check-schemas:needs: changes@@ -48,6 +51,10 @@ jobs:path: marimo/_schemas/generated/notebook.yamldisplay_name: Notebook Schemacondition: ${{ needs.changes.outputs.notebook == 'true' }}+ - name: notifications+ path: marimo/_schemas/generated/notifications.yaml+ display_name: Notifications Schema+ condition: ${{ needs.changes.outputs.notifications == 'true' }}steps:- name: Checkout current branchif: ${{ matrix.schema.condition }}diff --git a/marimo/_schemas/README.md b/marimo/_schemas/README.mdindex 781c0dfed0..9c0420ab6a 100644--- a/marimo/_schemas/README.md+++ b/marimo/_schemas/README.md@@ -1,6 +1,12 @@# Schemas-This directory contains the schemas for the notebook and session.+This directory contains the schemas for the notebook, session, and kernel messages.++## Available Schemas++- **notebook.py**: Schema for the notebook file format+- **session.py**: Schema for the notebook session (outputs, console, etc.)+- **notifications** (from `marimo/_messaging/ops.py`): Schema for kernel notifications sent to the client## How to update the schemasdiff --git a/marimo/_schemas/generated/notebook.yaml b/marimo/_schemas/generated/notebook.yamlindex b0a2139a24..33b31dc4bd 100644--- a/marimo/_schemas/generated/notebook.yaml+++ b/marimo/_schemas/generated/notebook.yaml@@ -2,57 +2,64 @@components:schemas:NotebookCell:+ description: Code cell specific structureproperties:code:- nullable: true- type: string+ anyOf:+ - type: string+ - type: 'null'code_hash:- nullable: true- type: string+ anyOf:+ - type: string+ - type: 'null'config:- properties:- column:- nullable: true- type: integer- disabled:- nullable: true- type: boolean- hide_code:- nullable: true- type: boolean- type: object+ $ref: '#/components/schemas/NotebookCellConfig'id:- nullable: true- type: string+ anyOf:+ - type: string+ - type: 'null'name:- nullable: true- type: string+ anyOf:+ - type: string+ - type: 'null'required:- - id- code- code_hash- - name- config+ - id+ - name+ title: NotebookCelltype: objectNotebookCellConfig:+ description: Configuration for a notebook cellproperties:column:- nullable: true- type: integer+ anyOf:+ - type: integer+ - type: 'null'disabled:- nullable: true- type: boolean+ anyOf:+ - type: boolean+ - type: 'null'hide_code:- nullable: true- type: boolean+ anyOf:+ - type: boolean+ - type: 'null'+ required: []+ title: NotebookCellConfigtype: objectNotebookMetadata:+ description: Metadata about the notebookproperties:marimo_version:- nullable: true- type: string+ anyOf:+ - type: string+ - type: 'null'+ required: []+ title: NotebookMetadatatype: objectNotebookV1:+ description: Main notebook structureproperties:cells:items:@@ -63,12 +70,12 @@ components:version:enum:- '1'- type: stringrequired:- - version- - metadata- cells+ - metadata+ - version+ title: NotebookV1type: objectinfo:- title: marimo_session+ title: marimoopenapi: 3.0.0diff --git a/marimo/_schemas/generated/notifications.yaml b/marimo/_schemas/generated/notifications.yamlnew file mode 100644index 0000000000..4a0fc62360--- /dev/null+++ b/marimo/_schemas/generated/notifications.yaml@@ -0,0 +1,1592 @@+# This file is generated by scripts/generate_schemas.py+components:+ schemas:+ Alert:+ properties:+ description:+ type: string+ op:+ enum:+ - alert+ title:+ type: string+ variant:+ anyOf:+ - enum:+ - danger+ - type: 'null'+ default: null+ required:+ - op+ - title+ - description+ title: Alert+ type: object+ Banner:+ properties:+ action:+ anyOf:+ - enum:+ - restart+ - type: 'null'+ default: null+ description:+ type: string+ op:+ enum:+ - banner+ title:+ type: string+ variant:+ anyOf:+ - enum:+ - danger+ - type: 'null'+ default: null+ required:+ - op+ - title+ - description+ title: Banner+ type: object+ CacheCleared:+ description: Result of clearing cache.+ properties:+ bytes_freed:+ type: integer+ op:+ enum:+ - cache-cleared+ required:+ - op+ - bytes_freed+ title: CacheCleared+ type: object+ CacheInfoFetched:+ description: Cache statistics information.+ properties:+ disk_to_free:+ type: integer+ disk_total:+ type: integer+ hits:+ type: integer+ misses:+ type: integer+ op:+ enum:+ - cache-info-fetched+ time:+ type: number+ required:+ - op+ - hits+ - misses+ - time+ - disk_to_free+ - disk_total+ title: CacheInfoFetched+ type: object+ CellChannel:+ description: The channel of a cell's output.+ enum:+ - marimo-error+ - media+ - 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:+ anyOf:+ - type: integer+ - type: 'null'+ default: null+ disabled:+ default: false+ type: boolean+ hide_code:+ default: false+ type: boolean+ required: []+ title: CellConfig+ type: object+ CellOp:+ description: "Op to transition a cell.\n\nA CellOp's data has some optional\+ \ fields:\n\noutput - a CellOutput\nconsole - a CellOutput (console\+ \ msg to append), or a list of\n CellOutputs\nstatus \+ \ - execution status\nstale_inputs - whether the cell has stale inputs (variables,\+ \ modules, ...)\nrun_id - the run associated with this cell.\nserialization\+ \ - the serialization status of the cell\n\nOmitting a field means that its\+ \ value should be unchanged!\n\nAnd one required field:\n\ncell_id - the cell\+ \ id"+ properties:+ cell_id:+ type: string+ console:+ anyOf:+ - items:+ $ref: '#/components/schemas/CellOutput'+ type: array+ - type: 'null'+ - $ref: '#/components/schemas/CellOutput'+ default: null+ op:+ enum:+ - cell-op+ output:+ anyOf:+ - type: 'null'+ - $ref: '#/components/schemas/CellOutput'+ default: null+ run_id:+ anyOf:+ - type: string+ - type: 'null'+ default: null+ serialization:+ anyOf:+ - type: string+ - type: 'null'+ default: null+ stale_inputs:+ anyOf:+ - type: boolean+ - type: 'null'+ default: null+ status:+ anyOf:+ - enum:+ - disabled-transitively+ - idle+ - queued+ - running+ - type: 'null'+ default: null+ timestamp:+ type: number+ required:+ - op+ - cell_id+ title: CellOp+ type: object+ CellOutput:+ properties:+ channel:+ $ref: '#/components/schemas/CellChannel'+ data:+ anyOf:+ - type: string+ - items:+ 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/MarimoSQLError'+ - $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'+ sql-error: '#/components/schemas/MarimoSQLError'+ strict-exception: '#/components/schemas/MarimoStrictExecutionError'+ syntax: '#/components/schemas/MarimoSyntaxError'+ unknown: '#/components/schemas/UnknownError'+ propertyName: type+ type: array+ - type: object+ 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+ title: CellOutput+ type: object+ ColumnStats:+ description: Represents stats for a column in a data table.+ properties:+ 'false':+ anyOf:+ - type: integer+ - type: 'null'+ default: null+ max:+ anyOf:+ - {}+ - type: 'null'+ default: null+ mean:+ anyOf:+ - {}+ - type: 'null'+ default: null+ median:+ anyOf:+ - {}+ - type: 'null'+ default: null+ min:+ anyOf:+ - {}+ - type: 'null'+ default: null+ nulls:+ anyOf:+ - type: integer+ - type: 'null'+ default: null+ p25:+ anyOf:+ - {}+ - type: 'null'+ default: null+ p5:+ anyOf:+ - {}+ - type: 'null'+ default: null+ p75:+ anyOf:+ - {}+ - type: 'null'+ default: null+ p95:+ anyOf:+ - {}+ - type: 'null'+ default: null+ std:+ anyOf:+ - {}+ - type: 'null'+ default: null+ total:+ anyOf:+ - type: integer+ - type: 'null'+ default: null+ 'true':+ anyOf:+ - type: integer+ - type: 'null'+ default: null+ unique:+ 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:+ op:+ enum:+ - completed-run+ required:+ - op+ title: CompletedRun+ 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+ op:+ enum:+ - completion-result+ options:+ items:+ $ref: '#/components/schemas/CompletionOption'+ type: array+ prefix_length:+ type: integer+ required:+ - op+ - completion_id+ - prefix_length+ - options+ title: CompletionResult+ type: object+ CycleError:+ properties:+ edges_with_vars:+ items:+ items: false+ maxItems: 3+ minItems: 3+ prefixItems:+ - type: string+ - items:+ type: string+ type: array+ - type: string+ type: array+ type: array+ type:+ enum:+ - cycle+ required:+ - type+ - edges_with_vars+ title: CycleError+ type: object+ DataColumnPreview:+ description: Preview of a column in a dataset.+ properties:+ chart_code:+ anyOf:+ - type: string+ - type: 'null'+ default: null+ chart_spec:+ anyOf:+ - type: string+ - type: 'null'+ default: null+ column_name:+ type: string+ error:+ anyOf:+ - type: string+ - type: 'null'+ default: null+ missing_packages:+ anyOf:+ - items:+ type: string+ type: array+ - type: 'null'+ default: null+ op:+ enum:+ - data-column-preview+ stats:+ anyOf:+ - type: 'null'+ - $ref: '#/components/schemas/ColumnStats'+ default: null+ table_name:+ type: string+ required:+ - op+ - table_name+ - column_name+ 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:+ $ref: '#/components/schemas/Database'+ type: array+ default_database:+ anyOf:+ - type: string+ - type: 'null'+ default: null+ default_schema:+ anyOf:+ - type: string+ - type: 'null'+ default: null+ dialect:+ type: string+ display_name:+ type: string+ name:+ type: string+ source:+ type: string+ required:+ - source+ - dialect+ - name+ - display_name+ - databases+ title: DataSourceConnection+ type: object+ DataSourceConnections:+ properties:+ connections:+ items:+ $ref: '#/components/schemas/DataSourceConnection'+ type: array+ op:+ enum:+ - data-source-connections+ required:+ - op+ - connections+ 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:+ anyOf:+ - type: string+ - type: 'null'+ default: null+ indexes:+ anyOf:+ - items:+ type: string+ type: array+ - type: 'null'+ default: null+ name:+ type: string+ num_columns:+ anyOf:+ - type: integer+ - type: 'null'+ num_rows:+ anyOf:+ - type: integer+ - type: 'null'+ primary_keys:+ anyOf:+ - items:+ type: string+ type: array+ - type: 'null'+ default: null+ source:+ type: string+ source_type:+ enum:+ - catalog+ - connection+ - duckdb+ - local+ type:+ default: table+ enum:+ - table+ - view+ variable_name:+ anyOf:+ - type: string+ - type: 'null'+ required:+ - source_type+ - source+ - name+ - num_rows+ - num_columns+ - variable_name+ - columns+ 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:+ type: array+ type:+ enum:+ - boolean+ - date+ - datetime+ - integer+ - number+ - string+ - time+ - unknown+ required:+ - name+ - type+ - external_type+ - sample_values+ title: DataTableColumn+ type: object+ 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:+ anyOf:+ - type: string+ - type: 'null'+ default: null+ name:+ type: string+ schemas:+ items:+ $ref: '#/components/schemas/Schema'+ type: array+ required:+ - name+ - dialect+ - schemas+ title: Database+ type: object+ Datasets:+ description: List of datasets.+ properties:+ clear_channel:+ anyOf:+ - enum:+ - catalog+ - connection+ - duckdb+ - local+ - type: 'null'+ default: null+ op:+ enum:+ - datasets+ tables:+ items:+ $ref: '#/components/schemas/DataTable'+ type: array+ required:+ - op+ - tables+ title: Datasets+ type: object+ FocusCell:+ properties:+ cell_id:+ type: string+ op:+ enum:+ - focus-cell+ required:+ - op+ - cell_id+ title: FocusCell+ type: object+ FunctionCallResult:+ description: Result of calling a function.+ properties:+ function_call_id:+ type: string+ op:+ enum:+ - function-call-result+ return_value: {}+ status:+ $ref: '#/components/schemas/HumanReadableStatus'+ required:+ - op+ - function_call_id+ - return_value+ - status+ title: FunctionCallResult+ type: object+ HumanReadableStatus:+ description: Human-readable status.+ properties:+ code:+ enum:+ - error+ - ok+ message:+ anyOf:+ - type: string+ - type: 'null'+ default: null+ title:+ anyOf:+ - type: string+ - type: 'null'+ default: null+ required:+ - code+ title: HumanReadableStatus+ type: object+ ImportStarError:+ properties:+ lineno:+ anyOf:+ - type: integer+ - type: 'null'+ default: null+ msg:+ type: string+ type:+ enum:+ - import-star+ required:+ - type+ - msg+ title: ImportStarError+ type: object+ InstallingPackageAlert:+ properties:+ log_status:+ anyOf:+ - enum:+ - append+ - done+ - start+ - type: 'null'+ default: null+ logs:+ anyOf:+ - additionalProperties:+ type: string+ type: object+ - type: 'null'+ default: null+ op:+ enum:+ - installing-package-alert+ packages:+ additionalProperties:+ enum:+ - failed+ - installed+ - installing+ - queued+ type: object+ required:+ - op+ - packages+ title: InstallingPackageAlert+ type: object+ Interrupted:+ description: Written when the kernel is interrupted by the user.+ properties:+ op:+ enum:+ - interrupted+ required:+ - op+ title: Interrupted+ 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+ KernelReady:+ description: Kernel is ready for execution.+ properties:+ app_config:+ $ref: '#/components/schemas/_AppConfig'+ capabilities:+ $ref: '#/components/schemas/KernelCapabilities'+ cell_ids:+ items:+ type: string+ type: array+ codes:+ items:+ type: string+ type: array+ configs:+ items:+ $ref: '#/components/schemas/CellConfig'+ type: array+ kiosk:+ type: boolean+ last_executed_code:+ anyOf:+ - additionalProperties:+ type: string+ type: object+ - type: 'null'+ last_execution_time:+ anyOf:+ - additionalProperties:+ type: number+ type: object+ - type: 'null'+ layout:+ anyOf:+ - $ref: '#/components/schemas/LayoutConfig'+ - type: 'null'+ names:+ items:+ type: string+ type: array+ op:+ enum:+ - kernel-ready+ resumed:+ type: boolean+ ui_values:+ 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+ title: KernelReady+ type: object+ LayoutConfig:+ properties:+ data:+ type: object+ type:+ type: string+ required:+ - type+ - data+ title: LayoutConfig+ type: object+ MarimoAncestorPreventedError:+ properties:+ blamed_cell:+ anyOf:+ - type: string+ - type: 'null'+ msg:+ type: string+ raising_cell:+ type: string+ type:+ enum:+ - ancestor-prevented+ required:+ - type+ - msg+ - raising_cell+ - blamed_cell+ title: MarimoAncestorPreventedError+ type: object+ MarimoAncestorStoppedError:+ properties:+ msg:+ type: string+ raising_cell:+ type: string+ type:+ enum:+ - ancestor-stopped+ required:+ - type+ - msg+ - raising_cell+ title: MarimoAncestorStoppedError+ type: object+ MarimoExceptionRaisedError:+ properties:+ exception_type:+ type: string+ msg:+ type: string+ raising_cell:+ anyOf:+ - type: string+ - type: 'null'+ type:+ enum:+ - exception+ required:+ - type+ - msg+ - exception_type+ - raising_cell+ title: MarimoExceptionRaisedError+ 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+ required:+ - type+ - error_id+ title: MarimoInternalError+ type: object+ MarimoInterruptionError:+ properties:+ type:+ enum:+ - interruption+ required:+ - type+ title: MarimoInterruptionError+ type: object+ MarimoSQLError:+ description: SQL-specific error with enhanced metadata for debugging.+ properties:+ hint:+ anyOf:+ - type: string+ - type: 'null'+ default: null+ msg:+ type: string+ node_col_offset:+ default: 0+ type: integer+ node_lineno:+ default: 0+ type: integer+ sql_col:+ anyOf:+ - type: integer+ - type: 'null'+ default: null+ sql_line:+ anyOf:+ - type: integer+ - type: 'null'+ default: null+ sql_statement:+ type: string+ type:+ enum:+ - sql-error+ required:+ - type+ - msg+ - sql_statement+ title: MarimoSQLError+ type: object+ MarimoStrictExecutionError:+ properties:+ blamed_cell:+ anyOf:+ - type: string+ - type: 'null'+ msg:+ type: string+ ref:+ type: string+ type:+ enum:+ - strict-exception+ required:+ - type+ - msg+ - ref+ - blamed_cell+ title: MarimoStrictExecutionError+ type: object+ MarimoSyntaxError:+ properties:+ lineno:+ anyOf:+ - type: integer+ - type: 'null'+ default: null+ msg:+ type: string+ type:+ enum:+ - syntax+ required:+ - type+ - msg+ title: MarimoSyntaxError+ type: object+ MissingPackageAlert:+ properties:+ isolated:+ type: boolean+ op:+ enum:+ - missing-package-alert+ packages:+ items:+ type: string+ type: array+ required:+ - op+ - packages+ - isolated+ title: MissingPackageAlert+ type: object+ MultipleDefinitionError:+ properties:+ cells:+ items:+ type: string+ type: array+ name:+ type: string+ type:+ enum:+ - multiple-defs+ required:+ - type+ - name+ - cells+ title: MultipleDefinitionError+ type: object+ QueryParamsAppend:+ properties:+ key:+ type: string+ op:+ enum:+ - query-params-append+ value:+ type: string+ required:+ - op+ - key+ - value+ title: QueryParamsAppend+ type: object+ QueryParamsClear:+ properties:+ op:+ enum:+ - query-params-clear+ required:+ - op+ title: QueryParamsClear+ type: object+ QueryParamsDelete:+ properties:+ key:+ type: string+ op:+ enum:+ - query-params-delete+ value:+ anyOf:+ - type: string+ - type: 'null'+ required:+ - op+ - key+ - value+ title: QueryParamsDelete+ type: object+ QueryParamsSet:+ description: Set query parameters.+ properties:+ key:+ type: string+ op:+ enum:+ - query-params-set+ value:+ anyOf:+ - type: string+ - items:+ type: string+ type: array+ required:+ - op+ - key+ - value+ title: QueryParamsSet+ type: object+ Reconnected:+ properties:+ op:+ enum:+ - reconnected+ required:+ - op+ title: Reconnected+ type: object+ Reload:+ properties:+ op:+ enum:+ - reload+ required:+ - op+ title: Reload+ type: object+ RemoveUIElements:+ description: Invalidate UI elements for a given cell.+ properties:+ cell_id:+ type: string+ op:+ enum:+ - remove-ui-elements+ required:+ - op+ - cell_id+ title: RemoveUIElements+ type: object+ SQLMetadata:+ description: Metadata for a SQL database.+ properties:+ connection:+ type: string+ database:+ type: string+ schema:+ type: string+ type:+ enum:+ - sql-metadata+ required:+ - type+ - connection+ - database+ - schema+ title: SQLMetadata+ type: object+ SQLTableListPreview:+ description: Preview of a list of tables in a schema.+ properties:+ error:+ anyOf:+ - type: string+ - type: 'null'+ default: null+ metadata:+ $ref: '#/components/schemas/SQLMetadata'+ op:+ enum:+ - sql-table-list-preview+ request_id:+ type: string+ tables:+ default: []+ items:+ $ref: '#/components/schemas/DataTable'+ type: array+ required:+ - op+ - request_id+ - metadata+ title: SQLTableListPreview+ type: object+ SQLTablePreview:+ description: Preview of a table in a SQL database.+ properties:+ error:+ anyOf:+ - type: string+ - type: 'null'+ default: null+ metadata:+ $ref: '#/components/schemas/SQLMetadata'+ op:+ enum:+ - sql-table-preview+ request_id:+ type: string+ table:+ anyOf:+ - type: 'null'+ - $ref: '#/components/schemas/DataTable'+ required:+ - op+ - request_id+ - metadata+ - table+ title: SQLTablePreview+ type: object+ Schema:+ properties:+ name:+ type: string+ tables:+ items:+ $ref: '#/components/schemas/DataTable'+ type: array+ required:+ - name+ - tables+ title: Schema+ type: object+ SecretKeysResult:+ description: Result of listing secret keys.+ properties:+ op:+ enum:+ - secret-keys-result+ request_id:+ type: string+ secrets:+ items:+ $ref: '#/components/schemas/SecretKeysWithProvider'+ type: array+ required:+ - op+ - request_id+ - secrets+ title: SecretKeysResult+ type: object+ SecretKeysWithProvider:+ properties:+ keys:+ items:+ type: string+ type: array+ name:+ type: string+ provider:+ enum:+ - dotenv+ - env+ required:+ - provider+ - name+ - keys+ title: SecretKeysWithProvider+ type: object+ SendUIElementMessage:+ description: Send a message to a UI element.+ properties:+ buffers:+ anyOf:+ - items:+ contentEncoding: base64+ type: string+ type: array+ - type: 'null'+ default: null+ message:+ type: object+ model_id:+ anyOf:+ - type: string+ - type: 'null'+ op:+ enum:+ - send-ui-element-message+ ui_element:+ anyOf:+ - type: string+ - type: 'null'+ required:+ - op+ - ui_element+ - model_id+ - message+ title: SendUIElementMessage+ type: object+ SetupRootError:+ properties:+ edges_with_vars:+ items:+ items: false+ maxItems: 3+ minItems: 3+ prefixItems:+ - type: string+ - items:+ type: string+ type: array+ - type: string+ type: array+ type: array+ type:+ enum:+ - setup-refs+ required:+ - type+ - edges_with_vars+ title: SetupRootError+ type: object+ SqlCatalogCheckResult:+ description: Result of running validation against the database.+ properties:+ error_message:+ anyOf:+ - type: string+ - type: 'null'+ success:+ type: boolean+ required:+ - success+ - error_message+ title: SqlCatalogCheckResult+ type: object+ SqlParseError:+ description: "Represents a single SQL parse error.\n\nAttributes:\n message\+ \ (str): Description of the error.\n line (int): Line number where the\+ \ error occurred (1-based).\n column (int): Column number where the error\+ \ occurred (1-based).\n severity (Literal[\"error\", \"warning\"]): Severity\+ \ of the error."+ properties:+ column:+ type: integer+ line:+ type: integer+ message:+ type: string+ severity:+ enum:+ - error+ - warning+ required:+ - message+ - line+ - column+ - severity+ title: SqlParseError+ type: object+ SqlParseResult:+ description: "Result of parsing an SQL query.\n\nAttributes:\n success (bool):\+ \ True if parsing succeeded without errors.\n errors (list[SqlParseError]):\+ \ List of parse errors (empty if success is True)."+ properties:+ errors:+ items:+ $ref: '#/components/schemas/SqlParseError'+ type: array+ success:+ type: boolean+ required:+ - success+ - errors+ title: SqlParseResult+ type: object+ StartupLogs:+ properties:+ content:+ type: string+ op:+ enum:+ - startup-logs+ status:+ enum:+ - append+ - done+ - start+ required:+ - op+ - content+ - status+ title: StartupLogs+ type: object+ UnknownError:+ properties:+ error_type:+ anyOf:+ - type: string+ - type: 'null'+ default: null+ msg:+ type: string+ type:+ enum:+ - unknown+ required:+ - type+ - msg+ title: UnknownError+ type: object+ UpdateCellCodes:+ properties:+ cell_ids:+ items:+ type: string+ type: array+ code_is_stale:+ type: boolean+ codes:+ items:+ type: string+ type: array+ op:+ enum:+ - update-cell-codes+ required:+ - op+ - cell_ids+ - codes+ - code_is_stale+ 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+ op:+ enum:+ - update-cell-ids+ required:+ - op+ - cell_ids+ title: UpdateCellIdsRequest+ type: object+ ValidateSQLResult:+ properties:+ error:+ anyOf:+ - type: string+ - type: 'null'+ default: null+ op:+ enum:+ - validate-sql-result+ parse_result:+ anyOf:+ - type: 'null'+ - $ref: '#/components/schemas/SqlParseResult'+ default: null+ request_id:+ type: string+ validate_result:+ anyOf:+ - type: 'null'+ - $ref: '#/components/schemas/SqlCatalogCheckResult'+ default: null+ required:+ - op+ - request_id+ title: ValidateSQLResult+ type: object+ VariableDeclaration:+ properties:+ declared_by:+ items:+ type: string+ type: array+ name:+ type: string+ used_by:+ items:+ type: string+ type: array+ required:+ - name+ - declared_by+ - used_by+ title: VariableDeclaration+ type: object+ VariableValue:+ properties:+ datatype:+ anyOf:+ - type: string+ - type: 'null'+ name:+ type: string+ value:+ anyOf:+ - type: string+ - type: 'null'+ required:+ - name+ - value+ - datatype+ title: VariableValue+ type: object+ VariableValues:+ description: List of variables and their types/values.+ properties:+ op:+ enum:+ - variable-values+ variables:+ items:+ $ref: '#/components/schemas/VariableValue'+ type: array+ required:+ - op+ - variables+ title: VariableValues+ type: object+ Variables:+ description: List of variable declarations.+ properties:+ op:+ enum:+ - variables+ variables:+ items:+ $ref: '#/components/schemas/VariableDeclaration'+ type: array+ required:+ - op+ - variables+ title: Variables+ type: object+ _AppConfig:+ description: 'Program-specific configuration.+++ Configuration for frontends or runtimes that is specific to++ 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+openapi: 3.0.0diff --git a/marimo/_schemas/generated/session.yaml b/marimo/_schemas/generated/session.yamlindex e10a512cc8..4917b59244 100644--- a/marimo/_schemas/generated/session.yaml+++ b/marimo/_schemas/generated/session.yaml@@ -185,5 +185,5 @@ components:- durationtype: objectinfo:- title: marimo_session+ title: marimoopenapi: 3.0.0diff --git a/packages/openapi/src/notebook.ts b/packages/openapi/src/notebook.tsindex 9b3f7ebe52..92340d223b 100644--- a/packages/openapi/src/notebook.ts+++ b/packages/openapi/src/notebook.ts@@ -7,29 +7,41 @@ export type paths = Record<string, never>;export type webhooks = Record<string, never>;export interface components {schemas: {+ /**+ * NotebookCell+ * @description Code cell specific structure+ */NotebookCell: {code: string | null;code_hash: string | null;- config: {- column?: number | null;- disabled?: boolean | null;- hide_code?: boolean | null;- };+ config: components["schemas"]["NotebookCellConfig"];id: string | null;name: string | null;};+ /**+ * NotebookCellConfig+ * @description Configuration for a notebook cell+ */NotebookCellConfig: {column?: number | null;disabled?: boolean | null;hide_code?: boolean | null;};+ /**+ * NotebookMetadata+ * @description Metadata about the notebook+ */NotebookMetadata: {marimo_version?: string | null;};+ /**+ * NotebookV1+ * @description Main notebook structure+ */NotebookV1: {cells: components["schemas"]["NotebookCell"][];metadata: components["schemas"]["NotebookMetadata"];- /** @enum {string} */+ /** @enum {unknown} */version: "1";};};diff --git a/scripts/generate_schemas.py b/scripts/generate_schemas.pyindex 32eea6ad14..e6beac46fe 100755--- a/scripts/generate_schemas.py+++ b/scripts/generate_schemas.py@@ -2,14 +2,14 @@import marimo-__generated_with = "0.13.15"+__generated_with = "0.18.4"app = marimo.App(width="medium")with app.setup:import marimo as moimport marimo._schemas.session as s-import marimo._schemas.notebook as n+ import marimo._messaging.ops as oimport typing as tSESSION_MESSAGES = [@@ -30,13 +30,49 @@ with app.setup:n.NotebookMetadata,n.NotebookV1,]+ OPS_MESSAGES = [+ # Message operations+ o.CellOp,+ o.FunctionCallResult,+ o.RemoveUIElements,+ o.SendUIElementMessage,+ o.Interrupted,+ o.CompletedRun,+ o.KernelReady,+ o.CompletionResult,+ o.Alert,+ o.MissingPackageAlert,+ o.InstallingPackageAlert,+ o.Reconnected,+ o.StartupLogs,+ o.Banner,+ o.Reload,+ o.Variables,+ o.VariableValues,+ o.Datasets,+ o.SQLTablePreview,+ o.SQLTableListPreview,+ o.DataColumnPreview,+ o.DataSourceConnections,+ o.ValidateSQLResult,+ o.QueryParamsSet,+ o.QueryParamsAppend,+ o.QueryParamsDelete,+ o.QueryParamsClear,+ o.FocusCell,+ o.UpdateCellCodes,+ o.SecretKeysResult,+ o.CacheCleared,+ o.CacheInfoFetched,+ o.UpdateCellIdsRequest,+ ]@app.cell(hide_code=True)def _():- mo.md(- r"""This marimo notebook generates the OpenAPI schema for the `TypeDict`s defined in `marimo._schemas`"""- )+ mo.md(r"""+ This marimo notebook generates the OpenAPI schema for the `TypeDict`s defined in `marimo._schemas`+ """)return@@ -51,14 +87,19 @@ def _():def generate_schema(name: str):import yaml- assert name == "session" or name == "notebook", (- "Invalid schema name must be 'session' or 'notebook'"+ assert name in ["session", "notebook", "notifications"], (+ "Invalid schema name must be 'session', 'notebook', or 'notifications'")header = f"# This file is generated by scripts/generate_schemas.py\n"print(f"Writing schema to marimo/_schemas/generated/{name}.yaml")- messages = SESSION_MESSAGES if name == "session" else NOTEBOOK_MESSAGES+ if name == "session":+ messages = SESSION_MESSAGES+ elif name == "notebook":+ messages = NOTEBOOK_MESSAGES+ else:+ messages = OPS_MESSAGESreturn header + yaml.dump(build_openapi_schema(messages))@@ -74,20 +115,29 @@ def write_schema(name: str):output.write_text(generate_schema(name), encoding="utf-8")-def _(generate_schema_button):- if mo.app_meta().mode == "script" or generate_schema_button.value:- write_schema("session")- write_schema("notebook")- return--[email protected](hide_code=True)def build_openapi_schema(messages):- from marimo._server.api.router import build_routesfrom marimo._utils.dataclass_to_openapi import (PythonTypeToOpenAPI,)+ import msgspec+ import msgspec.json++ try:+ components = msgspec.json.schema_components(messages, ref_template="#/components/schemas/{name}")+ return {+ "openapi": "3.0.0",+ "info": {"title": "marimo"},+ "components": {+ "schemas": {+ **components[1],+ }+ },+ }+ except Exception as e:+ import traceback++ traceback.print_exc()processed_classes: dict[t.Any, str] = {}component_schemas: dict[str, t.Any] = {}@@ -105,7 +155,7 @@ def build_openapi_schema(messages):schemas = {"openapi": "3.0.0",- "info": {"title": "marimo_session"},+ "info": {"title": "marimo"},"components": {"schemas": {**component_schemas,@@ -115,5 +165,14 @@ def build_openapi_schema(messages):return schemas+def _(generate_schema_button):+ if mo.app_meta().mode == "script" or generate_schema_button.value:+ write_schema("session")+ write_schema("notebook")+ write_schema("notifications")+ return++if __name__ == "__main__":app.run()diff --git a/tests/_schemas/test_schema.py b/tests/_schemas/test_schema.pyindex 4e2a057fd3..93fb994e24 100644--- a/tests/_schemas/test_schema.py+++ b/tests/_schemas/test_schema.py@@ -8,8 +8,8 @@ import yaml@pytest.mark.skipif(- sys.platform == "win32",- reason="This test is flaky on Windows",+ sys.platform == "win32" or sys.version_info != (3, 12),+ reason="This test is flaky on Windows. And only test on 3.12",)def test_session_schema_up_to_date() -> None:current_session_schema = yaml.safe_load(@@ -18,6 +18,9 @@ def test_session_schema_up_to_date() -> None:current_notebook_schema = yaml.safe_load(Path("marimo/_schemas/generated/notebook.yaml").read_text())+ current_notifications_schema = yaml.safe_load(+ Path("marimo/_schemas/generated/notifications.yaml").read_text()+ )import sys@@ -26,6 +29,9 @@ def test_session_schema_up_to_date() -> None:generated_session_schema = yaml.safe_load(generate_schema("session"))generated_notebook_schema = yaml.safe_load(generate_schema("notebook"))+ generated_notifications_schema = yaml.safe_load(+ generate_schema("notifications")+ )cmd = "python scripts/generate_schemas.py"assert current_session_schema == generated_session_schema, (@@ -34,3 +40,6 @@ def test_session_schema_up_to_date() -> None:assert current_notebook_schema == generated_notebook_schema, (f"notebook.yaml is not up to date. Run '{cmd}' and press 'Write schema' to update.")+ assert current_notifications_schema == generated_notifications_schema, (+ f"notifications.yaml is not up to date. Run '{cmd}' and press 'Write schema' to update."+ )