Skip to content

Python API reference

This reference covers the calls used by the runnable guides. Release means the tested local FFI environment; checkout means the SDK source client used in the separate Scaling and worker environments. Method signatures below omit self. An await is required for operations marked async, including native methods returning Python awaitables.

Release and checkout availability

Both clients report 0.2.0. Select an environment by its imported files and dependency set, rather than by that version alone.

Surface Tested release Reviewed checkout
Unary/streaming FFI Executed with supplied native wheel Executed with the matching development wheel
pipeline_buffers= / send_input(require_zero_copy=...) Absent Present in wrappers/PyO3 source
attach(..., token=..., participant=...) Keywords absent Present; backend token exercised through Entry
subscribe, publish, attach_inproc Present; local echo exercised Present; remote echo exercised
subscribe_in, publish_out, publish metadata= Absent Present; see MS2 guides for executed scope
host_endpoint Absent Present; see MS2 guides for executed scope
register_node(..., generates=...) Keyword absent Present; see MS2 guides for executed scope
Worker dotted-class discovery and reply RPC Not validated; discovery fails for this example Executed with the RPC reply-header fix and matching worker wheel

No transport or platform parity is implied by sharing a method name. Signature snapshots are generated with python scripts/inspect_api.py <output.json> in each environment.

One request through FFI

Import from remotemedia. Exact release call signatures, with annotations omitted:

async execute_pipeline(pipeline_or_manifest, enable_metrics=False) -> Any
async execute_pipeline_with_input(pipeline_or_manifest, input_data, enable_metrics=False) -> Any

The checkout adds keyword-only pipeline_buffers=None to both calls. It accepts a pipeline object, node list, JSON string, or manifest dictionary. The guides use a dictionary and a one-item input list. The reviewed manifest path validates all inputs but executes only the first; use a stream for multiple requests.

For the tested PassThrough graph without metrics, the return value is the echoed string. Metrics-enabled and other graph outputs have different envelopes. These calls own their execution and return no session handle. An application timeout bounds waiting; it does not certify that native work has stopped.

Error Condition
ImportError Native module missing or unable to load
TypeError input_data is not a list, or unsupported manifest/node-list type
ValueError Empty input list, empty pipeline, or invalid manifest
RuntimeError Runtime execution or node initialization failure

The empty-list branch raises ValueError even though an older wrapper docstring lists it under TypeError. The lifecycle probe checks the actual behavior. Pipeline.run(use_rust=True) can retry through Python after native errors; it has different execution semantics.

Native streaming session

Import remotemedia.runtime as rt. Tested release signatures:

await rt.create_streaming_session(manifest_json) -> PyStreamingSession
await session.send_input(data) -> None
await session.recv_output() -> tuple[str, Any] | None
await session.signal_input_complete() -> None
await session.close() -> None

manifest_json is a JSON string, not a dictionary. Parse errors raise ValueError; executor/session creation failures raise RuntimeError. The caller owns the resulting session and must close it in finally.

send_input() converts supported Python values into runtime data. Strings are text inputs. Data-conversion errors occur before queuing; sending after input completion or close raises RuntimeError. A successful send means the input was queued, not that every downstream node has finished.

recv_output() consumes one output from the shared audio/video/data queues and returns (kind, value). Text echoes are ("data", "hello"). None means all relevant output channels are closed. Use one receiving strategy per session; kind-specific receivers and recv_output() compete for the same queues.

Input completion drops the external input sender. In the tested artifact it does not establish natural EOF for the echo graph. Receive the graph's expected result count or application completion event, stop receiving tasks, then close. Explicit close discards unread output, is idempotent, and makes subsequent receive return None. See the tested lifecycle.

The checkout adds pipeline_buffers=None to creation and require_zero_copy=False to send. These signatures are present in the worker wheel, but absent in the supplied release wheel. The examples use their defaults; copy accounting is not an end-to-end zero-copy guarantee.

Attach control

Import attach and attach_inproc from remotemedia.control. Both return async context managers yielding AttachedSession:

# Release
attach(address, *, session_id, attach_id='python-client', credentials=None)
attach_inproc(session)

# Checkout
attach(address, *, session_id, attach_id='python-client', credentials=None,
       token=None, participant=None)

address is host:port. credentials is a gRPC channel-credentials object; None selects plaintext. The checkout sends a bearer token from token, or REMOTEMEDIA_CONTROL_TOKEN when the argument is None. Scaling requires a backend token. participant is a participant ID or metadata mapping for attribution; it is not media admission.

attach_inproc() uses a live FFI session without a network connection. Closing either control context closes its transport and proxies, not the pipeline session. The FFI owner or Scaling administration still owns session teardown.

Observe and publish

async ctrl.subscribe(address: str) -> AsyncIterator[Data]
async ctrl.publish(address: str, data: Data | str) -> None
async ctrl.close() -> None

Await subscribe() first, then iterate its result. Subscribe to node.out before publishing to node.in when you need to observe that input's output. Named ports use node.in.port or node.out.port. Close the iterator with await tap.aclose() on early exit.

Data here is remotemedia.control.Data; .text accesses a text payload. Worker RuntimeData is a different type. Publication returning None is not an application-result acknowledgement. Wait for the expected tap output or an RPC reply as appropriate.

The checkout's publish signature additionally accepts keyword-only metadata: Mapping[str, str] | None = None. It also provides subscribe_in(address) for input taps and publish_out(address, data, *, metadata=None) for output control-bus subscribers. Output publication does not enqueue downstream processing. Entry tap traffic is capped and may be dropped; subscription is a live observation channel.

Error surface Meaning
ControlAddressError Malformed address or wrong .in/.out direction
SessionNotFoundError Attach cannot resolve the live session
UnknownNodeError Address references an absent node; may arrive through the event stream
gRPC transport/auth errors Unreachable service, rejected credentials/token, closed connection
TimeoutError from asyncio.wait_for The application's deadline expired

The protocol uses one bidirectional PipelineControl.Attach stream: a session-identifying Hello, then control frames and events. The Python client handles that framing. Server errors may arrive asynchronously; successful enqueue alone cannot confirm remote processing.

Worker node contract

Import MultiprocessNode, NodeConfig, and register_node from remotemedia.core.multiprocessing; import RuntimeData from its data module.

NodeConfig(node_id: str, node_type: str, params: dict,
           session_id: str | None = None, log_level: str = 'INFO')
async node.initialize() -> None
async node.process(data: RuntimeData) -> RuntimeData | AsyncGenerator | None
async node.cleanup() -> None
register_node(node_type: str)
rt.register_python_node_type(node_type, python_class=None, multi_output=False,
                             description=None, category=None, accepts=None, produces=None)

The host supplies configuration, calls initialization before processing, and owns cleanup. @register_node registers a class when its Python module is imported; native register_python_node_type tells the host the importable dotted class path. Both sides must resolve the same type. In the example, RuntimeData.text(...), .is_text(), and .as_text() construct/check/read the worker payload; non-text input raises the example's TypeError.

The direct class test validates parameter use and method behavior. The real worker check also validates configuration transport, transformed output, RPC with a distinct process ID, and normal termination of observed children.

Reply RPC

rpc(func=None, *, reply=False, stream=False, timeout=None)

Import the decorator from remotemedia.rpc. The node example marks describe() with @rpc(reply=True). The client calls await ctrl.formatter.describe(); method names and arguments are supplied by the actual node, not by PassThrough. Reply-mode failures use RpcError; a reply deadline uses RpcTimeoutError. RPC replies travel over their own correlated protocol and are distinct from media outputs. See the executed RPC and endpoint examples and generation cancellation checks for transport-specific behavior and limits.