Skip to content

Client API

Python client for SpatialEngine statements.

Use these APIs to configure the client, manage connections and transactions, and handle errors.

6 functions / 20 types

Index

FunctionDescription
build_async_client
build_clientBuild a Client bound to the given Transport.
connectConnect to an FDK gRPC runtime server, retrying until it is reachable.
connect_asyncconnect for AsyncClient. Call it inside a running event loop and enter the result with async with.
proto_pathReturns the directory containing the SDK’s .proto schema.
target_from_envReturns host:port, using FDK_HOST and FDK_PORT for omitted arguments.
TypeDescription
AsyncClientAsynchronous statement client for a running engine.
AsyncGrpcTransportGrpcTransport for AsyncClient. Construct it inside a running event loop.
AsyncStatementStreamStatementStream for async for and async with.
AsyncTransactionTransaction for AsyncClient.
AsyncTransportTransport with the request awaited.
CancelledErrorRaised when a statement fails on any transport.
ClientBlocking statement client for a running engine.
EngineErrorRaised when a statement fails on any transport.
ExtensionTransportSubmits statements through the extension host’s WIT execute-statement function.
FailedPreconditionErrorRaised when a statement fails on any transport.
GrpcTransportSends Protobuf-encoded statements to a native engine over gRPC.
InternalErrorRaised when a statement fails on any transport.
InvalidArgumentErrorRaised when a statement fails on any transport.
MalformedAnswerErrorRaised when an engine response is missing a required field or has no selected oneof field.
NotFoundErrorRaised when a statement fails on any transport.
PermissionDeniedErrorRaised when a statement fails on any transport.
StatementStreamIterator over a streaming statement’s responses.
TransactionContext manager for an engine transaction.
TransportSends a Protobuf-encoded statement request and returns the response bytes.
UnavailableErrorRaised when a statement fails on any transport.

build_async_client

def build_async_client(transport: AsyncTransport) -> AsyncClient

Returns AsyncClient.

transport : AsyncTransport

build_client

def build_client(transport: Transport) -> Client

Build a Client bound to the given Transport.

Returns Client.

transport : Transport

connect

def connect(
    host: str | None = None,
    port: int | None = None,
    startup_timeout: float | None = 120.0,
    retry_interval: float = 2.0,
    options: Sequence[tuple[str, Any]] | None = None
) -> Client

Connect to an FDK gRPC runtime server, retrying until it is reachable.

Returns Client.

host optional : str | None

Server hostname. Defaults to FDK_HOST, or “localhost” if unset. Defaults to None.

port optional : int | None

Server port. Defaults to FDK_PORT, or 50051 if unset. Defaults to None.

startup_timeout optional : float | None

Max seconds to wait for the server. None or 0 returns immediately. Defaults to 120.0.

retry_interval optional : float

Seconds between connection attempts. Defaults to 2.0.

options optional : Sequence[tuple[str, Any]] | None

grpc channel options, replacing DEFAULT_CHANNEL_OPTIONS entirely. Defaults to None.

connect_async

def connect_async(
    host: str | None = None,
    port: int | None = None,
    startup_timeout: float | None = 120.0,
    retry_interval: float = 2.0,
    options: Sequence[tuple[str, Any]] | None = None,
    connections: int = 4
) -> AsyncClient

connect for AsyncClient. Call it inside a running event loop and enter the result with async with.

Returns AsyncClient.

host optional : str | None

Defaults to None.

port optional : int | None

Defaults to None.

startup_timeout optional : float | None

Defaults to 120.0.

retry_interval optional : float

Defaults to 2.0.

options optional : Sequence[tuple[str, Any]] | None

Defaults to None.

connections optional : int

Defaults to 4.

proto_path

def proto_path() -> str

Returns the directory containing the SDK’s .proto schema.

Use this directory as the protoc include path (-I) to generate a client in another language. Schema files are under spatialengine/v1.

Returns str.

target_from_env

def target_from_env(host: str | None = None, port: int | None = None) -> str

Returns host:port, using FDK_HOST and FDK_PORT for omitted arguments.

Returns str.

host optional : str | None

Defaults to None.

port optional : int | None

Defaults to None.

AsyncClient

AsyncClient(
    target: str | None = None,
    *,
    transport: AsyncTransport | None = None,
    secure: bool = False,
    startup_timeout: float | None = 120.0,
    retry_interval: float = 2.0,
    options: Sequence[tuple[str, Any]] | None = None,
    connections: int = 4
)

Asynchronous statement client for a running engine.

Construct it inside a running event loop. async with waits for the engine to accept connections. connections sets the number of TCP connections used for concurrent calls.

AsyncClient.wait_until_ready

async def AsyncClient.wait_until_ready() -> None

Returns None.

AsyncClient.close

async def AsyncClient.close() -> None

Returns None.

AsyncClient.print

async def AsyncClient.print(*, message: str, _transaction_id: str | None = None) -> str

Echoes back the string you added.

Returns str.

message : str

The message to echo.

_transaction_id optional : str | None

Transaction to join. Omit to submit without an explicit transaction. Defaults to None.

AsyncGrpcTransport

AsyncGrpcTransport(
    target: str,
    *,
    secure: bool = False,
    options: Sequence[tuple[str, Any]] | None = None,
    connections: int = 4
)

GrpcTransport for AsyncClient. Construct it inside a running event loop.

Concurrent calls are distributed across connections TCP connections.

AsyncGrpcTransport.wait_until_ready

async def AsyncGrpcTransport.wait_until_ready(
    startup_timeout: float | None = 120.0,
    retry_interval: float = 2.0
) -> None

Returns None.

startup_timeout optional : float | None

Defaults to 120.0.

retry_interval optional : float

Defaults to 2.0.

AsyncGrpcTransport.unary

async def AsyncGrpcTransport.unary(
    full_path: str,
    payload: bytes,
    transaction_id: str | None = None
) -> bytes

Returns bytes.

full_path : str

payload : bytes

transaction_id optional : str | None

Defaults to None.

AsyncGrpcTransport.server_stream

def AsyncGrpcTransport.server_stream(
    full_path: str,
    payload: bytes,
    transaction_id: str | None = None
) -> AsyncIterator[bytes]

Returns AsyncIterator[bytes].

full_path : str

payload : bytes

transaction_id optional : str | None

Defaults to None.

AsyncGrpcTransport.close

async def AsyncGrpcTransport.close() -> None

Returns None.

AsyncStatementStream

AsyncStatementStream(responses: AsyncIterator[bytes], decode: Callable[[bytes], T])

StatementStream for async for and async with.

AsyncStatementStream.close

async def AsyncStatementStream.close() -> None

Returns None.

AsyncTransaction

AsyncTransaction(client, mode='Shared', *, lease_seconds=60.0)

Transaction for AsyncClient.

Await every submitted operation before commit(). The engine rejects operations that are still in flight when the transaction ends.

Canceled entry waits for the transaction id and cancels that transaction before raising asyncio.CancelledError.

AsyncTransaction.submit

def AsyncTransaction.submit(statement, **kwargs)

statement :

kwargs :

AsyncTransaction.commit

async def AsyncTransaction.commit()

AsyncTransaction.cancel

async def AsyncTransaction.cancel()

AsyncTransport

AsyncTransport(*args, **kwargs)

Transport with the request awaited.

AsyncTransport.unary

async def AsyncTransport.unary(
    full_path: str,
    payload: bytes,
    transaction_id: str | None = None
) -> bytes

Returns bytes.

full_path : str

payload : bytes

transaction_id optional : str | None

Defaults to None.

AsyncTransport.server_stream

def AsyncTransport.server_stream(
    full_path: str,
    payload: bytes,
    transaction_id: str | None = None
) -> AsyncIterator[bytes]

Returns AsyncIterator[bytes].

full_path : str

payload : bytes

transaction_id optional : str | None

Defaults to None.

CancelledError

CancelledError(code: int, message: str, path: str, kind: int = 0)

Raised when a statement fails on any transport.

kind is the StatementErrorKind the engine assigned the failure, so callers branch on it rather than matching on message.

Client

Client(
    target: str | None = None,
    *,
    transport: Transport | None = None,
    secure: bool = False,
    startup_timeout: float | None = 120.0,
    retry_interval: float = 2.0,
    options: Sequence[tuple[str, Any]] | None = None
)

Blocking statement client for a running engine.

Each statement blocks until its RPC returns. Call dependent statements in sequence. Use AsyncClient in asyncio applications, or asyncio.to_thread for synchronous work. Concurrent calls have no execution-order guarantee. Keep synchronous transaction submission and finalization in one worker. Custom transports define their own concurrency requirements.

startup_timeout limits connection retries during engine startup. It does not limit statement execution time.

Client.close

def Client.close() -> None

Release the transport’s resources (closes the gRPC channel, if any).

Returns None.

Client.print

def Client.print(*, message: str, _transaction_id: str | None = None) -> str

Echoes back the string you added.

Returns str.

message : str

The message to echo.

_transaction_id optional : str | None

Transaction to join. Omit to submit without an explicit transaction. Defaults to None.

EngineError

EngineError(code: int, message: str, path: str, kind: int = 0)

Raised when a statement fails on any transport.

kind is the StatementErrorKind the engine assigned the failure, so callers branch on it rather than matching on message.

ExtensionTransport

ExtensionTransport(host_fn: Any | None = None)

Submits statements through the extension host’s WIT execute-statement function.

The extension host injects a callable through componentize-py bindings; this class calls that function. Instantiating outside a WebAssembly extension raises RuntimeError because there is no host binding to invoke.

ExtensionTransport.unary

def ExtensionTransport.unary(
    full_path: str,
    payload: bytes,
    transaction_id: str | None = None
) -> bytes

Returns bytes.

full_path : str

payload : bytes

transaction_id optional : str | None

Defaults to None.

ExtensionTransport.server_stream

def ExtensionTransport.server_stream(
    full_path: str,
    payload: bytes,
    transaction_id: str | None = None
) -> Iterator[bytes]

Returns Iterator[bytes].

full_path : str

payload : bytes

transaction_id optional : str | None

Defaults to None.

FailedPreconditionError

FailedPreconditionError(code: int, message: str, path: str, kind: int = 0)

Raised when a statement fails on any transport.

kind is the StatementErrorKind the engine assigned the failure, so callers branch on it rather than matching on message.

GrpcTransport

GrpcTransport(
    target: str,
    *,
    secure: bool = False,
    startup_timeout: float | None = 120.0,
    retry_interval: float = 2.0,
    options: Sequence[tuple[str, Any]] | None = None
)

Sends Protobuf-encoded statements to a native engine over gRPC.

GrpcTransport.unary

def GrpcTransport.unary(
    full_path: str,
    payload: bytes,
    transaction_id: str | None = None
) -> bytes

Returns bytes.

full_path : str

payload : bytes

transaction_id optional : str | None

Defaults to None.

GrpcTransport.server_stream

def GrpcTransport.server_stream(
    full_path: str,
    payload: bytes,
    transaction_id: str | None = None
) -> Iterator[bytes]

Returns Iterator[bytes].

full_path : str

payload : bytes

transaction_id optional : str | None

Defaults to None.

GrpcTransport.close

def GrpcTransport.close() -> None

Returns None.

InternalError

InternalError(code: int, message: str, path: str, kind: int = 0)

Raised when a statement fails on any transport.

kind is the StatementErrorKind the engine assigned the failure, so callers branch on it rather than matching on message.

InvalidArgumentError

InvalidArgumentError(code: int, message: str, path: str, kind: int = 0)

Raised when a statement fails on any transport.

kind is the StatementErrorKind the engine assigned the failure, so callers branch on it rather than matching on message.

MalformedAnswerError

MalformedAnswerError(*args, **kwargs)

Raised when an engine response is missing a required field or has no selected oneof field.

NotFoundError

NotFoundError(code: int, message: str, path: str, kind: int = 0)

Raised when a statement fails on any transport.

kind is the StatementErrorKind the engine assigned the failure, so callers branch on it rather than matching on message.

PermissionDeniedError

PermissionDeniedError(code: int, message: str, path: str, kind: int = 0)

Raised when a statement fails on any transport.

kind is the StatementErrorKind the engine assigned the failure, so callers branch on it rather than matching on message.

StatementStream

StatementStream(responses: Iterator[bytes], decode: Callable[[bytes], T])

Iterator over a streaming statement’s responses.

Call close() or exit its with block to cancel the stream.

StatementStream.close

def StatementStream.close() -> None

Returns None.

Transaction

Transaction(client, mode='Shared', *, lease_seconds=60.0)

Context manager for an engine transaction.

On __enter__ calls project.transaction.begin and stores the returned id. submit(statement, **kwargs) tags a statement with the id so its operation joins the open transaction. commit() and cancel() end the transaction by id. Exiting the with block without an explicit commit() cancels the transaction, whether the exit is clean or via an exception. Call commit() before the block ends to persist the batch.

mode is "Shared" (the default) or "Private". A shared transaction includes every operation submitted while it is open. A private transaction accepts only operations tagged with its ID.

submit() returns after the operation is applied. Subsequent statements can read its changes before commit. cancel() or exiting without committing discards those changes. commit() waits for the transaction to become durable.

If Ctrl+C interrupts entry over gRPC, entry waits for the transaction id and cancels that transaction before raising KeyboardInterrupt.

gRPC transactions renew automatically while the context is open. Other transports renew on submit. A pause longer than lease_seconds on those transports expires the transaction.

Example: python with spatialengine.Transaction(client, mode="Shared") as txn: txn.submit(client.project.object.transform.set, node=node, transform=transform) txn.submit(client.project.object.visibility.set, node=node, visibility=visibility) txn.commit()

Transaction.submit

def Transaction.submit(statement, **kwargs)

statement :

kwargs :

Transaction.commit

def Transaction.commit()

Transaction.cancel

def Transaction.cancel()

Transport

Transport(*args, **kwargs)

Sends a Protobuf-encoded statement request and returns the response bytes.

Implementations exist for network gRPC, in-process WASM engine, and WIT extensions. A failure is raised as an EngineError subclass through raise_statement_error.

transaction_id assigns the statement to a transaction. None submits it without an explicit transaction ID. Generated methods pass this argument positionally.

Transport.unary

def Transport.unary(
    full_path: str,
    payload: bytes,
    transaction_id: str | None = None
) -> bytes

Returns bytes.

full_path : str

payload : bytes

transaction_id optional : str | None

Defaults to None.

Transport.server_stream

def Transport.server_stream(
    full_path: str,
    payload: bytes,
    transaction_id: str | None = None
) -> Iterator[bytes]

Returns Iterator[bytes].

full_path : str

payload : bytes

transaction_id optional : str | None

Defaults to None.

UnavailableError

UnavailableError(code: int, message: str, path: str, kind: int = 0)

Raised when a statement fails on any transport.

kind is the StatementErrorKind the engine assigned the failure, so callers branch on it rather than matching on message.