Nexus RPC Python SDK
nexus-rpc is a Python SDK for building handlers that implement the Nexus synchronous RPC protocol. Nexus is designed for arbitrary-duration operations, allowing handlers to respond synchronously or return a token for asynchronous completion. As of version 1.4.0, the SDK is in an experimental release stage, and backwards-incompatible changes are expected prior to a stable release.
Warnings
- breaking The nexus-rpc SDK is currently at an experimental release stage. Backwards-incompatible changes are anticipated until a stable release is announced.
- gotcha The PyPI package name 'nexus-rpc' was previously used by an unrelated project. Ensure you are using the correct SDK for the Nexus synchronous RPC protocol from the `nexus-rpc` GitHub organization.
- gotcha The SDK for the Nexus RPC protocol only provides components for implementing handlers. It does not include reference implementations for Nexus servers or clients.
Install
-
pip install nexus-rpc
Imports
- nexusrpc
import nexusrpc
- service
from nexusrpc import service
- Operation
from nexusrpc import Operation
- handler
from nexusrpc import handler
Quickstart
from dataclasses import dataclass
import nexusrpc
@dataclass
class MyInput:
name: str
@dataclass
class MyOutput:
message: str
@nexusrpc.service
class MyNexusService:
my_sync_operation: nexusrpc.Operation[MyInput, MyOutput]
@nexusrpc.handler.service_handler(service=MyNexusService)
class MyNexusServiceHandler:
@nexusrpc.handler.sync_operation
async def my_sync_operation(
self, ctx: nexusrpc.handler.StartOperationContext, input: MyInput
) -> MyOutput:
return MyOutput(message=f"Hello {input.name}!")
# In a real application, you would instantiate MyNexusServiceHandler
# and integrate it with your server/worker to process Nexus requests.
# For example:
# handler_instance = MyNexusServiceHandler()