Skip to content

Statements

A statement is a typed engine call. SDK methods submit statements and return their results.

KindExecutionState
OperationAsynchronousUpdates versioned project state. Changes are undoable.
ActionSynchronousUpdates unversioned engine state.
TaskAsynchronousUpdates unversioned engine state.

For example, creating a project node is an operation. Spawning a temporary scene shape is an action. Loading data into unversioned engine state can be a task.

Synchronous and asynchronous describe how the engine executes the statement. A network call to a synchronous action still requires your application to wait for its response.

The SDK includes statement documentation and generated method signatures.

Ordering

Blocking Python calls complete before the next call starts. Async Python and TypeScript callers choose the order by awaiting results.

Submit dependent calls in sequence. For example, await the node creation before updating that node. Submit independent work concurrently when ordering does not matter.

AsyncClient exposes the same statements as awaitable calls. Use it from an active event loop.

import asyncio
import spatialengine

async def main():
    async with spatialengine.connect_async() as client:
        messages = await asyncio.gather(
            client.print(message="First independent call"),
            client.print(message="Second independent call"),
        )
        print(messages)

asyncio.run(main())

Transactions

Transactions group project operations into one undoable edit. They do not make concurrently submitted calls execute in source order.

An applied operation’s changes are visible before the transaction commits. Committing makes the transaction durable. Cancellation discards its changes.

Transactions and undo.

Failures

Handle failures at the application boundary. Depending on the error, retry the call, cancel the edit, or report the failure to the user.

Calls return typed values directly. Messages and variants are defined under spatialengine.types. Engine failures raise EngineError subclasses.

import spatialengine

with spatialengine.connect() as client:
    try:
        client.viewport.camera.zoom_extents(viewport="main")
    except spatialengine.EngineError as error:
        print(error.message)

A camera statement needs an active viewport. Use the label assigned by your page. Reads requiring one viewport fail when the label selects none or several.

An operation on a node removed by undo can fail even if your application still retains the old ID. Read current state when a UI action depends on that node’s continued existence.