Skip to content

WebSocket protocol ​

Protocol version 1.1. Served live and machine-readable at GET /v1/protocol.

Transport

  • control_plane: JSON text WebSocket frames (InterfaceMessage).
  • data_plane: Raw binary WebSocket frames for chunk upload/read and the buffers announced by an event frame.
  • concurrency: Each call runs as its own task: a later call, ping or close on the same socket is answered while an earlier call still runs or streams, and replies are matched by id. Sync methods run in worker threads, so concurrent calls may run methods of the same interface instance at the same time; an interface whose methods share state guards it with a lock. A client that waits for each reply before sending the next call sees calls run one at a time. Connect, chunk and widget frames are handled in order. Closing the socket cancels its calls.
  • rest: All non-WebSocket endpoints are described by /openapi.json.

Endpoints

  • /v1/interfaces/ws: Create/attach any Interface; call/chunk/read/emit.
  • /v1/executions/ws: Attach to an existing Execution by uuid.

Request headers

HeaderRequiredDescription
X-Machinable-ProjectnoProject directory to target (also ?project=); must be under the server's project_roots allowlist. Defaults to the launch project.
X-Machinable-UsernoAttributes created interfaces to this user (created_by). Defaults to the server's OS user; ignored when an OIDC token admitted the request (its identity claim is used).
X-Machinable-PythonnoInterpreter to serve the request or socket (also ?python=); a non-gateway interpreter is routed to a subprocess worker. With the server's project_default_python, a request naming a project under project_roots without one is served by that project's .venv.
AuthorizationnoBearer <token> when the server sets api_token or oidc_issuer: the shared api_token, or a JWT access token from the OIDC issuer (then attributed to its identity claim, X-Machinable-User ignored). On a WebSocket upgrade, also as Sec-WebSocket-Protocol: bearer, <token> (answered with bearer); an OIDC-admitted socket closes with 4401 when its token expires.
X-Machinable-Source-TokennoThe source_token for source writes (PUT/DELETE/move /v1/source), sent beside Authorization.

Frames

typeDirectionPurpose
connectclient→serverCreate or attach to an interface and bind the project.
connectedserver→clientConfirms the connection; returns uuid and resolved config.
callclient→serverInvoke a public method on the connected interface; runs concurrently with the socket's other calls.
resultserver→clientSingle return value of a call.
streamserver→clientOne yielded value from a generator method; final=true closes.
eventserver→clientUnsolicited push from Interface.emit(), at any time.
errorserver→clientFailure detail; payload.code='not_found' for missing reads.
chunk_startclient→serverBegin a binary upload (write/append) or read (mode read).
chunk_endclient→serverFinish the active upload (after one or more binary frames).
chunk_doneserver→clientUpload/read complete (bytes_written / bytes_sent).
widget_getclient→serverRequest a widget's full synced state.
widget_stateserver→clientA widget's full synced state (reply to widget_get).
widget_setclient→serverApply synced-state changes (model.set + save_changes).
widget_changeserver→clientTrait changes (reply to widget_set, or server-originated).
widget_msgeitherCustom widget message (model.send / msg:custom).
pingclient→serverLiveness probe; answered with pong.
pongserver→clientReply to ping.
closeeitherTeardown; the server evicts the interface from its cache.

connect fields:

  • target (string) (required): Module path to instantiate, or an existing uuid.
  • version (array): Version list passed to Interface.make().
  • uuid (string): Client-supplied id for create-by-id (content hash); idempotent in that the same id attaches to the existing instance.
  • label (string): Optional mutable label to set on the instance.
  • project (string): Project dir to bind (overrides header/query).
  • meta (object): Client metadata stored with the interface.

connected fields:

  • payload.uuid (string): Interface uuid.
  • payload.config (object): Resolved configuration.

call fields:

  • method (string) (required): Public method name (no leading underscore).
  • args (array): Positional arguments.
  • kwargs (object): Keyword arguments.

result fields:

  • payload (any): JSON-encoded result.

stream fields:

  • payload (any): One item; null on the terminal frame.

event fields:

  • payload (any): Emitted payload.
  • buffers (int): Present when the emit carried buffers: the number of binary frames that follow this frame immediately and in order, before any other frame.

error fields:

  • payload.message (string): Message.
  • payload.code (string): Typed code, e.g. 'not_found' on a missing read.

chunk_start fields:

  • id (string) (required): Correlation id; must match chunk_end on upload.
  • mode (string): "write" (truncate), "append", or "read".
  • path (string): Relative path under interface dir (upload only).
  • params (object): Opaque, interface-defined read parameters (read only); passed verbatim to the interface read() hook.

chunk_done fields:

  • payload (object): bytes_written (upload) or bytes_sent (read).

widget_get fields:

  • id (string): Correlation id.

widget_state fields:

  • payload.state (object): Full anywidget model state.

widget_set fields:

  • changes (object): Changed keys/values to apply.

widget_change fields:

  • payload.changes (object): Normalized changed keys/values.

widget_msg fields:

  • content (any): Message body (client→server); reply in payload.

Binary flows

upload: Write opaque bytes to a path under the interface directory.

client → chunk_start {id, path, mode: write|append}
client → <binary frame> ×N
client → chunk_end {id}
server → chunk_done {path, bytes_written}

read: Stream the interface read() hook's bytes back, bounded.

client → chunk_start {id, mode: read, params}
server → <binary frame> ×N (bounded)
server → chunk_done {bytes_sent}
server → error {code: not_found}   # when missing

event_buffers: An emit with buffers: an event frame, then its bytes.

server → event {payload, buffers: n}
server → <binary frame> xn   # buffers[0] … buffers[n-1]

Interface hooks ​

Implemented by project interfaces:

<public methods> ​

python
def method(self, *args, **kwargs) -> Any | Iterator

Any non-underscore method is callable via call. Returning a generator streams as stream frames. Restrict with a class __api_methods__ allowlist.

read ​

python
def read(self, params: dict) -> bytes | Iterable[bytes]

Binary read hook for chunk_start mode=read. params is opaque to machinable. Raise machinable.errors.NotFound (or FileNotFoundError) to emit error{code:'not_found'}.

emit ​

python
self.emit(payload: Any, *, buffers: Sequence[bytes | bytearray | memoryview | ndarray] | None = None) -> None

Push an unsolicited event frame to a connected client, during a call or from any thread while the socket is connected. buffers are copied at the call and sent as binary frames right after the event (buffers: n); a numpy array goes as its C-order bytes.

widget_state / widget_update / widget_message ​

python
machinable.Widget hooks (see the Widgets guide)

A machinable.Widget ships an anywidget frontend (_esm/_css) and backs the model protocol: widget_state() (default: read-only config), widget_update() (rejects by default since config is immutable; keep state via save_file or mark), and widget_message(). Pushes via self.push_widget_change/message().

local_directory ​

python
self.local_directory(*append, create=False) -> str

Working directory where uploaded chunks land and read() reads from. Machinable never parses the bytes.

Capabilities ​

CapabilitySummarySurfaces
remote_callInvoke any interface method over REST or WS, incl. streaming.POST /v1/interfaces/call; ws: call/result/stream
binary_uploadStream opaque bytes into an interface directory.`ws: chunk_start(write
binary_eventsPush raw bytes with an event, without base64 in JSON.ws: event(buffers) + binary frames
binary_readStream interface bytes back via its read() hook.ws: chunk_start(read)
config_searchQuery instances by config (operators), sort, and paginate.POST /v1/interfaces/search
create_by_idContent-addressed, idempotent create with a client id.POST /v1/interfaces (uuid); ws: connect(uuid)
mutable_labelRename via a mutable label (config stays immutable).PATCH /v1/interfaces/{uuid}/label
creator_attributionDurable created_by metadata, queryable and reindex-preserved.X-Machinable-User header; search/find created_by
multi_projectServe many projects (and interpreters) from one gateway.X-Machinable-Project; X-Machinable-Python
source_editRead/write/create/rename interface source (token-gated).GET/PUT/DELETE /v1/source/{path}; POST /v1/source/move
widgetsInterfaces ship an anywidget frontend for notebook + web.`GET /v1/project/{module}/widget/{esm

MIT Licensed