Skip to main content

Installation

Initialization

register_worker

Register the worker with a iii instance, returns a connected worker client. Blocks until the WebSocket connection is established and ready. Signature
address
str
required
WebSocket URL of the III engine (e.g. ws://localhost:49134).
options
InitOptions | None
Optional configuration for worker name, timeouts, reconnection, and OTel.

Methods

register_trigger

Bind a trigger configuration to a registered function. Signature
trigger
RegisterTriggerInput | dict[str, Any]
required
A RegisterTriggerInput or dict with type, function_id, and optional config.

register_function

Register a function with the engine. Pass a handler for local execution, or an HttpInvocationConfig for HTTP-invoked functions (Lambda, Cloudflare Workers, etc.). Handlers can be synchronous or asynchronous. Sync handlers are automatically wrapped with run_in_executor so they do not block the event loop. Each handler receives a data argument containing the trigger payload, and may optionally accept a second metadata argument carrying per-invocation metadata (e.g. def handler(data, metadata=None) or def handler(data, *, metadata=None)). Metadata is only forwarded to handlers that declare a parameter literally named metadata, so existing handlers, including ones with unrelated extra parameters, *args, or **kwargs, keep working unchanged. request_format and response_format are auto-extracted from the handler’s type hints when omitted or passed as None (the default). To opt out of auto-extraction, pass an explicit schema (RegisterFunctionFormat or dict). This behavior is Python-specific; the Node SDK relies on explicit schemas because TypeScript types are erased at runtime. Signature
function_id
str
required
Unique string identifier for the function.
handler_or_invocation
RemoteFunctionHandler | HttpInvocationConfig
required
A callable handler or HttpInvocationConfig. Callable handlers receive data (the trigger payload) as the first argument and may optionally accept metadata (per-invocation metadata) as a second argument; they may return a value.
description
str | None
Human-readable description of what the function does.
metadata
dict[str, Any] | None
Arbitrary metadata attached to the function.
request_format
RegisterFunctionFormat | dict[str, Any] | None
Schema describing expected input. When None (default), auto-extracted from the handler’s first-parameter type hint. Pass an explicit schema to override; there is no way to register with no schema when the handler is typed.
response_format
RegisterFunctionFormat | dict[str, Any] | None
Schema describing expected output. Same auto-extraction semantics as request_format.

trigger

Invoke a remote function. The routing behavior and return type depend on the action field:
  • No action: synchronous, waits for the function to return.
  • TriggerAction.Enqueue(...): async via named queue, returns a dict with messageReceiptId.
  • TriggerAction.Void(): fire-and-forget, returns None.
Signature
request
dict[str, Any] | TriggerRequest
required
A TriggerRequest or dict with function_id, payload, and optional action / timeout_ms.

register_trigger_type

Register a custom trigger type with the engine. Returns a :class:TriggerTypeRef handle with register_trigger and register_function methods. Signature
trigger_type
RegisterTriggerTypeInput | dict[str, Any]
required
A RegisterTriggerTypeInput or dict with id, description, and optional trigger_request_format / call_request_format (Pydantic class or dict).
handler
TriggerHandler[Any]
required
A TriggerHandler instance.

unregister_trigger_type

Unregister a previously registered trigger type. Signature
trigger_type
RegisterTriggerTypeInput | dict[str, Any]
required
A RegisterTriggerTypeInput or dict with id and optional description.

connect_async

Connect to the III Engine via WebSocket. Initializes OpenTelemetry (if configured), attaches the event loop, and establishes the WebSocket connection. This is called automatically during construction; use it only if you need to reconnect manually from an async context. Signature

get_connection_state

Return the current WebSocket connection state. Signature

Example


shutdown

Gracefully shut down the client, releasing all resources. Cancels any pending reconnection attempts, rejects all in-flight invocations with an error, closes the WebSocket connection, and stops the background event-loop thread. After this call the instance must not be reused. Signature

Example


shutdown_async

Gracefully shut down the client, releasing all resources. Cancels any pending reconnection attempts, rejects all in-flight invocations with an error, closes the WebSocket connection, and stops the background event-loop thread. After this call the instance must not be reused. Signature

Example


trigger_async

Invoke a remote function. The routing behavior and return type depend on the action field:
  • No action: synchronous, waits for the function to return.
  • TriggerAction.Enqueue(...): async via named queue, returns a dict with messageReceiptId.
  • TriggerAction.Void(): fire-and-forget, returns None.
Signature
request
dict[str, Any] | TriggerRequest
required
A TriggerRequest or dict with function_id, payload, and optional action / timeout_ms.

Types

iii

EnqueueResult · InitOptions · MiddlewareFunctionInput · StreamRequest · StreamResponse · TelemetryOptions · TriggerAction · TriggerActionEnqueue

EnqueueResult

Result returned when a function is invoked with TriggerAction.Enqueue.
NameTypeRequiredDescription
messageReceiptIdstrYesUnique receipt ID for the enqueued message.

InitOptions

Configuration options passed to register_worker.
NameTypeRequiredDescription
enable_metrics_reportingboolNoEnable worker metrics via OpenTelemetry. Default True.
headersdict[str, str] | NoneNo-
invocation_timeout_msintNoDefault timeout for worker.trigger() invocations in milliseconds. Default 30000.
otelOtelConfig | dict[str, Any] | NoneNoOpenTelemetry configuration. Enabled by default. Set \{'enabled': False\} or env OTEL_ENABLED=false to disable.
reconnection_configReconnectionConfig | NoneNoWebSocket reconnection behavior.
telemetryTelemetryOptions | NoneNoInternal worker metadata reported to the engine.
worker_descriptionstr | NoneNoOne-line, human/LLM-readable summary of what this worker does. Surfaces in engine::workers::list / engine::workers::info.
worker_namestr | NoneNoDisplay name for this worker. Defaults to hostname:pid.

MiddlewareFunctionInput

Input passed to the RBAC middleware function on every function invocation through the RBAC port.
NameTypeRequiredDescription
actionTriggerActionEnqueue | TriggerActionVoid | NoneNoRouting action, if any.
contextdict[str, Any]YesAuth context returned by the auth function for this session.
function_idstrYesID of the function being invoked.
payloaddict[str, Any]YesPayload sent by the caller.

StreamRequest

Incoming streaming request received by a function registered with a stream trigger.
NameTypeRequiredDescription
bodyAnyYes-
headersdict[str, str | list[str]]Yes-
methodstrYes-
path_paramsdict[str, str]Yes-
query_paramsdict[str, str | list[str]]Yes-
request_bodyChannelReaderYes-

StreamResponse

Streaming response built on top of a ChannelWriter.
NameTypeRequiredDescription
close() -> NoneYes-
headersasync (headers: dict[str, str]) -> NoneYes-
statusasync (status_code: int) -> NoneYes-
streamWritableStreamYes-
writerChannelWriterYes-

TelemetryOptions

Worker metadata reported to the engine (language, framework, project).
NameTypeRequiredDescription
amplitude_api_keystr | NoneNoAmplitude API key for product analytics.
frameworkstr | NoneNoFramework name, if applicable.
languagestr | NoneNoProgramming language of the worker.
project_namestr | NoneNoName of the project this worker belongs to.

TriggerAction

Factory for creating trigger actions used with trigger().
NameTypeRequiredDescription
Enqueue(*, queue: str) -> TriggerActionEnqueueYesRoute the invocation through a named queue for async processing.
Void() -> TriggerActionVoidYesFire-and-forget routing. No response is returned.

TriggerActionEnqueue

Routes the invocation through a named queue for async processing. Requires a queue worker in the project. Run iii worker add queue. Without it the trigger rejects with enqueue_error (no queue provider).
NameTypeRequiredDescription
queuestrYesName of the target queue.
typeLiteral['enqueue']NoAlways 'enqueue'.

iii.channel

Channel · ChannelReader · ChannelWriter · StreamChannelRef

Channel

A streaming channel pair for worker-to-worker data transfer.
NameTypeRequiredDescription
readerChannelReaderYes-
reader_refStreamChannelRefYes-
writerChannelWriterYes-
writer_refStreamChannelRefYes-

ChannelReader

WebSocket-backed reader for streaming binary data and text messages.
NameTypeRequiredDescription
close_asyncasync () -> NoneYes-
on_message(callback: Callable[[str], Any]) -> NoneYes-
read_allasync () -> bytesYesRead the entire stream into a single bytes object.
streamAnyNo-

ChannelWriter

WebSocket-backed writer for streaming binary data and text messages.
NameTypeRequiredDescription
close() -> NoneYesFire-and-forget close.
close_asyncasync () -> NoneYes-
send_message(msg: str) -> NoneYesFire-and-forget text message. Queues a coroutine on the running loop.
send_message_asyncasync (msg: str) -> NoneYes-
streamAnyNo-
writeasync (data: bytes) -> NoneYes-

StreamChannelRef

Reference to a streaming channel for worker-to-worker data transfer.
NameTypeRequiredDescription
access_keystrYesSecret key for authenticating channel access.
channel_idstrYesUnique channel identifier.
directionLiteral['read', 'write']YesChannel direction (read or write).

iii.engine

EngineFunctions · EngineTriggers

EngineFunctions

Engine function ids for internal operations (parity with the Node SDK).
NameTypeRequiredDescription
INFO_FUNCTIONSFinal[str]No-
INFO_REGISTERED_TRIGGERSFinal[str]No-
INFO_TRIGGERSFinal[str]No-
INFO_WORKERSFinal[str]No-
LIST_FUNCTIONSFinal[str]No-
LIST_REGISTERED_TRIGGERSFinal[str]No-
LIST_TRIGGERSFinal[str]No-
LIST_WORKERSFinal[str]No-
REGISTER_WORKERFinal[str]No-

EngineTriggers

Engine trigger ids (parity with the Node SDK).
NameTypeRequiredDescription
FUNCTIONS_AVAILABLEFinal[str]No-
LOGFinal[str]No-

iii.errors

InvocationError

InvocationError

Raised when an invocation dispatched by the SDK fails. Inspect err.code to react to a specific category (e.g. 'FORBIDDEN' for RBAC denials, 'TIMEOUT' for timeouts). Catch this class to handle every rejection. except Exception continues to work because InvocationError inherits from Exception. Attributes are read-only after construction. stacktrace is the engine-side trace when the remote handler raised; it may include internal file paths and should not be surfaced to end users. str(err) intentionally never includes the stacktrace.
NameTypeRequiredDescription
codeAnyNo-
function_idAnyNo-
invocation_idAnyNo-
messageAnyNo-
stacktraceAnyNo-

iii.protocol

MessageType · RegisterFunctionFormat · RegisterFunctionInput · RegisterFunctionMessage · RegisterTriggerInput · RegisterTriggerMessage · RegisterTriggerTypeInput · RegisterTriggerTypeMessage · TriggerRequest

MessageType

Message types for iii communication.
NameTypeRequiredDescription
INVOCATION_RESULTAnyNo-
INVOKE_FUNCTIONAnyNo-
REGISTER_FUNCTIONAnyNo-
REGISTER_SERVICEAnyNo-
REGISTER_TRIGGERAnyNo-
REGISTER_TRIGGER_TYPEAnyNo-
TRIGGER_REGISTRATION_RESULTAnyNo-
UNREGISTER_FUNCTIONAnyNo-
UNREGISTER_TRIGGERAnyNo-
UNREGISTER_TRIGGER_TYPEAnyNo-
WORKER_REGISTEREDAnyNo-

RegisterFunctionFormat

Format definition for function parameters.
NameTypeRequiredDescription
bodylist[RegisterFunctionFormat] | NoneNoNested fields for object types.
descriptionstr | NoneNoHuman-readable description of the parameter.
itemsRegisterFunctionFormat | NoneNoItem schema for array types.
namestrYesParameter name.
requiredboolNoWhether the parameter is required.
typestrYesType string (string, number, boolean, object, array, null, map).

RegisterFunctionInput

Input for registering a function, matches Node.js RegisterFunctionInput.
NameTypeRequiredDescription
descriptionstr | NoneNoHuman-readable description.
idstrYesUnique function identifier.
invocationHttpInvocationConfig | NoneNoHTTP invocation config for externally hosted functions.
metadataAny | NoneNoArbitrary metadata attached to the function.
request_formatRegisterFunctionFormat | dict[str, Any] | NoneNoSchema describing expected input.
response_formatRegisterFunctionFormat | dict[str, Any] | NoneNoSchema describing expected output.

RegisterFunctionMessage

NameTypeRequiredDescription
descriptionstr | NoneNo-
idstrYes-
invocationHttpInvocationConfig | NoneNo-
message_typeMessageTypeNo-
metadataAny | NoneNo-
request_formatRegisterFunctionFormat | dict[str, Any] | NoneNo-
response_formatRegisterFunctionFormat | dict[str, Any] | NoneNo-

RegisterTriggerInput

Input for registering a trigger (matches Node SDK’s RegisterTriggerInput).
NameTypeRequiredDescription
configAnyNoTrigger-type-specific configuration, matching the shape the trigger type expects.
function_idstrYesID of the function this trigger invokes when it fires.
metadataAny | NoneNoArbitrary user-specifiable metadata supplied to the triggered handler function on every invocation.
typestrYesIdentifier of the registered trigger type this trigger uses (e.g. storage::object-created, http).

RegisterTriggerMessage

NameTypeRequiredDescription
configAnyYes-
function_idstrYes-
idstrYes-
message_typeMessageTypeNo-
metadataAny | NoneNo-
trigger_typestrYes-

RegisterTriggerTypeInput

Input for registering a trigger type.
NameTypeRequiredDescription
call_request_formatAny | NoneNoJSON Schema describing the payload sent to functions.
descriptionstrYesHuman-readable description of what this trigger type does.
idstrYesUnique identifier for the trigger type (e.g. state, durable:subscriber).
trigger_request_formatAny | NoneNoJSON Schema describing the expected trigger config.

RegisterTriggerTypeMessage

NameTypeRequiredDescription
call_request_formatAny | NoneNo-
descriptionstrYes-
idstrYes-
message_typeMessageTypeNo-
trigger_request_formatAny | NoneNo-

TriggerRequest

Request object for trigger().
NameTypeRequiredDescription
actionTriggerActionEnqueue | TriggerActionVoid | NoneNoSets how the trigger is routed. Omit for a synchronous request/response. Specify for a specific routing scheme (e.g. TriggerAction.Enqueue(...), TriggerAction.Void()).
function_idstrYesID of the function to invoke.
metadataAny | NoneNoArbitrary user-specifiable metadata supplied to the triggered handler function on every invocation.
payloadAnyNoInput data passed to the function.
timeout_msint | NoneNoOverride the default invocation timeout, in milliseconds.

iii.runtime

FunctionRef · TriggerTypeRef

FunctionRef

Reference to a registered function, allowing programmatic unregistration.
NameTypeRequiredDescription
idstrYesThe unique function identifier.
unregisterCallable[[], None]YesRemoves this function from the engine.

TriggerTypeRef

Typed handle returned by :meth:iii.III.register_trigger_type. Type parameters:
  • C: configuration type for :meth:register_trigger
  • R: call-request type for :meth:register_function
NameTypeRequiredDescription
register_function(function_id: str, handler: Callable[[R], Any] | Callable[[R], Awaitable[Any]], *, description: str | None = None) -> AnyYesRegister a function whose input matches the call-request format.
register_trigger(function_id: str, config: C, metadata: dict[str, Any] | None = None) -> TriggerYesRegister a trigger with validated config.

iii.state

IState · StateDeleteInput · StateDeleteResult · StateEventData · StateEventType · StateGetInput · StateListInput · StateSetInput · StateSetResult · StateUpdateInput · StateUpdateResult

IState

Abstract interface for state management operations.
NameTypeRequiredDescription
deleteasync (input: StateDeleteInput) -> StateDeleteResultYesDelete a state value.
getasync (input: StateGetInput) -> TData | NoneYesRetrieve a value by scope and key.
listasync (input: StateListInput) -> list[TData]YesList all values in a scope.
setasync (input: StateSetInput) -> StateSetResult[TData] | NoneYesSet (create or overwrite) a state value.
updateasync (input: StateUpdateInput) -> StateUpdateResult[TData] | NoneYesApply atomic update operations to a state value.

StateDeleteInput

Input for deleting a state value.
NameTypeRequiredDescription
keystrYesKey within the scope.
scopestrYesState scope (namespace).

StateDeleteResult

Result of a state delete operation.
NameTypeRequiredDescription
old_valueAny | NoneNoPrevious value (if it existed).

StateEventData

Payload for state change events.
NameTypeRequiredDescription
event_typeStateEventTypeYesType of state change.
keystrYesKey within the scope.
new_valueTData | NoneNoNew value (for create/update events).
old_valueTData | NoneNoPrevious value (for update/delete events).
scopestrYesState scope (namespace).
typestrNoEvent category (always state).

StateEventType

Types of state change events.
NameTypeRequiredDescription
CREATEDAnyNo-
DELETEDAnyNo-
UPDATEDAnyNo-

StateGetInput

Input for retrieving a state value.
NameTypeRequiredDescription
keystrYesKey within the scope.
scopestrYesState scope (namespace).

StateListInput

Input for listing all values in a state scope.
NameTypeRequiredDescription
scopestrYesState scope (namespace).

StateSetInput

Input for setting a state value.
NameTypeRequiredDescription
keystrYesKey within the scope.
scopestrYesState scope (namespace).
valueAnyYesValue to store.

StateSetResult

Result of a state set operation.
NameTypeRequiredDescription
new_valueTDataYesNew value that was stored.
old_valueTData | NoneNoPrevious value (if it existed).

StateUpdateInput

Input for atomically updating a state value.
NameTypeRequiredDescription
keystrYesKey within the scope.
opslist[UpdateOp]YesOrdered list of update operations to apply atomically.
scopestrYesState scope (namespace).

StateUpdateResult

Result of a state update operation.
NameTypeRequiredDescription
new_valueTDataYesNew value after the update.
old_valueTData | NoneNoPrevious value (if it existed).

iii.stream

IStream · StreamDeleteInput · StreamDeleteResult · StreamGetInput · StreamListGroupsInput · StreamListInput · StreamSetInput · StreamSetResult · StreamUpdateInput · StreamUpdateResult

IStream

Abstract interface for stream operations.
NameTypeRequiredDescription
deleteasync (input: StreamDeleteInput) -> StreamDeleteResultYesDelete an item from the stream.
getasync (input: StreamGetInput) -> TData | NoneYesGet an item from the stream.
listasync (input: StreamListInput) -> list[TData]YesGet all items in a group.
list_groupsasync (input: StreamListGroupsInput) -> List[str]YesList all groups in the stream.
setasync (input: StreamSetInput) -> StreamSetResult[TData] | NoneYesSet an item in the stream.
updateasync (input: StreamUpdateInput) -> StreamUpdateResult[TData] | NoneYesApply atomic update operations to a stream item.

StreamDeleteInput

Input for stream delete operation.
NameTypeRequiredDescription
group_idstrYesGroup identifier.
item_idstrYesItem identifier.
stream_namestrYesName of the stream.

StreamDeleteResult

Result of stream delete operation.
NameTypeRequiredDescription
old_valueAny | NoneNoPrevious value (if it existed).

StreamGetInput

Input for stream get operation.
NameTypeRequiredDescription
group_idstrYesGroup identifier.
item_idstrYesItem identifier.
stream_namestrYesName of the stream.

StreamListGroupsInput

Input for stream list groups operation.
NameTypeRequiredDescription
stream_namestrYesName of the stream.

StreamListInput

Input for stream list operation.
NameTypeRequiredDescription
group_idstrYesGroup identifier.
stream_namestrYesName of the stream.

StreamSetInput

Input for stream set operation.
NameTypeRequiredDescription
dataAnyYesData to store.
group_idstrYesGroup identifier.
item_idstrYesItem identifier.
stream_namestrYesName of the stream.

StreamSetResult

Result of stream set operation.
NameTypeRequiredDescription
new_valueTDataYesNew value that was stored.
old_valueTData | NoneNoPrevious value (if it existed).

StreamUpdateInput

Input for stream update operation.
NameTypeRequiredDescription
group_idstrYesGroup identifier.
item_idstrYesItem identifier.
opslist['UpdateOp']YesOrdered list of update operations to apply atomically.
stream_namestrYesName of the stream.

StreamUpdateResult

Result of stream update operation.
NameTypeRequiredDescription
errorslist[UpdateOpError]NoPer-op errors. Emitted by merge and append for validation rejections (path depth/size, value depth, or a __proto__ / constructor / prototype segment or top-level key) and by append for the append.type_mismatch and append.target_not_object surfaces. Successfully applied ops are still reflected in new_value. The field is omitted from the JSON wire when empty.
new_valueTDataYesNew value after the update.
old_valueTData | NoneNoPrevious value (if it existed).

iii.trigger

Trigger · TriggerActionVoid · TriggerConfig · TriggerHandler

Trigger

Represents a registered trigger.
NameTypeRequiredDescription
unregister() -> NoneYesUnregister this trigger.

TriggerActionVoid

Fire-and-forget routing. No response is returned.
NameTypeRequiredDescription
typeLiteral['void']NoAlways 'void'.

TriggerConfig

Configuration passed to a trigger handler when a trigger instance is registered or unregistered.
NameTypeRequiredDescription
configAnyYesTrigger-specific configuration.
function_idstrYesFunction to invoke when the trigger fires.
idstrYesTrigger instance ID.
metadatadict[str, Any] | NoneNoArbitrary user-specifiable metadata supplied to the triggered handler function on every invocation.

TriggerHandler

Abstract base class for trigger handlers.
NameTypeRequiredDescription
register_triggerasync (config: TriggerConfig[TConfig]) -> NoneYesRegister a trigger with the given configuration.
unregister_triggerasync (config: TriggerConfig[TConfig]) -> NoneYesUnregister a trigger with the given configuration.