UiPath Runtime Python SDK
uipath-runtime provides foundational interfaces and base contracts for building agent runtimes in the UiPath ecosystem. It defines the protocols that all runtime implementations must follow, offering utilities for execution context, event streaming, tracing, structured error handling, durable execution, and human-in-the-loop interactions. This package, currently at version 0.10.0, is under rapid development, with minor version changes indicating potential breaking changes to public interfaces.
Warnings
- breaking Minor version increments for `uipath-runtime` indicate breaking changes for public interfaces not explicitly marked as beta. Always review release notes when upgrading between minor versions (e.g., from 0.x to 0.y).
- breaking In version `0.3.0`, `UiPathDebugBridgeProtocol` was renamed to `UiPathDebugProtocol`. Methods on `UiPathResumableStorageProtocol` gained a `runtime_id` parameter, and `UiPathResumableRuntime` gained the ability to store arbitrary `(namespace, key, value)` tuples.
- gotcha This `uipath-runtime` Python package is distinct from `UiPath.Python.Activities` used within UiPath Studio. While related, `uipath-runtime` focuses on programmatic creation of UiPath runtimes in Python, whereas `UiPath.Python.Activities` facilitates running Python scripts *within* UiPath Studio workflows. The latter may have additional .NET Desktop Runtime dependencies (e.g., .NET 6 or higher) and specific Python version compatibilities that do not directly apply to `uipath-runtime` itself.
- gotcha When building custom runtimes or agents with `uipath-runtime` that rely on external Python libraries, those dependencies must be correctly installed in the Python environment where your runtime will execute. Failure to do so will result in `ModuleNotFoundError` or other runtime exceptions.
Install
-
pip install uipath-runtime
Imports
- UiPathRuntimeProtocol
from uipath.runtime import UiPathRuntimeProtocol
- UiPathRuntimeResult
from uipath.runtime import UiPathRuntimeResult
- UiPathRuntimeSchema
from uipath.runtime import UiPathRuntimeSchema
- UiPathExecuteOptions
from uipath.runtime import UiPathExecuteOptions
- UiPathRuntimeEvent
from uipath.runtime.events import UiPathRuntimeEvent
Quickstart
from typing import Any, AsyncGenerator, Optional
from uipath.runtime import (
UiPathRuntimeResult,
UiPathRuntimeStatus,
UiPathRuntimeSchema,
UiPathRuntimeEvent,
UiPathExecuteOptions,
UiPathStreamOptions,
UiPathRuntimeProtocol
)
class MyRuntime(UiPathRuntimeProtocol):
"""Example runtime implementing the UiPath runtime protocols."""
async def get_schema(self) -> UiPathRuntimeSchema:
return UiPathRuntimeSchema(
name="MyRuntime",
description="A sample UiPath runtime",
input_schema={'type': 'object', 'properties': {'name': {'type': 'string'}}},
output_schema={'type': 'object', 'properties': {'message': {'type': 'string'}}},
)
async def execute(
self, input: Any, options: Optional[UiPathExecuteOptions] = None
) -> UiPathRuntimeResult:
name = input.get('name', 'World')
message = f"Hello, {name}!"
return UiPathRuntimeResult(status=UiPathRuntimeStatus.SUCCESS, output={'message': message})
async def stream(
self, input: Any, options: Optional[UiPathStreamOptions] = None
) -> AsyncGenerator[UiPathRuntimeEvent, None]:
yield UiPathRuntimeEvent(name='start', payload={'input': input})
await self.execute(input, options) # Simulate execution
yield UiPathRuntimeEvent(name='end', payload={'result': 'success'})
async def dispose(self) -> None:
# Clean up resources if any
pass
# To use this runtime (e.g., in a higher-level SDK or framework):
# runtime_instance = MyRuntime()
# schema = await runtime_instance.get_schema()
# print(schema.model_dump_json(indent=2))
# result = await runtime_instance.execute({'name': 'Alice'})
# print(result.model_dump_json(indent=2))