nexusrpc is a library for building Nexus handlers.
See https://github.com/nexus-rpc and https://github.com/nexus-rpc/api/blob/main/SPEC.md.
Nexus is a synchronous RPC protocol. Arbitrary duration operations are modeled on top of a set of pre-defined synchronous RPCs.
A Nexus caller calls a handler. The handler may respond inline (synchronous response) or return a token referencing the ongoing operation (asynchronous response). The caller can cancel an asynchronous operation, check for its outcome, or fetch its current state. The caller can also specify a callback URL, which the handler uses to deliver the result of an asynchronous operation when it is ready.
Package | handler |
Components for implementing Nexus handlers. |
Module | _common |
No module docstring; 2/2 type variables documented |
Module | _serializer |
No module docstring; 1/2 class documented |
Module | _service |
A Nexus service definition is a class with class attributes of type Operation. It must be be decorated with @nexusrpc.service. The decorator validates the Operation attributes. |
Module | _util |
No module docstring; 0/3 constant, 5/7 functions documented |
From __init__.py
:
Class |
|
A container for a map of headers and a byte array of data. |
Class |
|
Nexus handler error types. |
Class |
|
A container for a value encoded in an underlying stream. |
Class |
|
A Link contains a URL and a type that can be used to decode the URL. |
Class |
|
Defines a Nexus operation in a Nexus service definition. |
Class |
|
Internal representation of a user's Operation definition. |
Class |
|
The state of an operation as described by an OperationError . |
Class |
|
Information about an operation. |
Class |
|
Describes the current state of an operation. |
Class |
|
Internal representation of a user's service definition class. |
Exception |
|
A Nexus handler error. |
Exception |
|
An error that represents "failed" and "canceled" operation results. |
Function | get |
Return the nexusrpc.Operation for the object, or None |
Function | get |
Return the nexusrpc.ServiceDefinition for the object, or None |
Function | service |
Decorator marking a class as a Nexus service definition. |
Function | set |
Set the nexusrpc.Operation for this object. |
Type Variable |
|
Operation input type |
Type Variable |
|
Operation output type |
Return the nexusrpc.Operation
for the object, or None
obj should be a decorated operation start method, or a method that takes no arguments and returns an OperationHandler.
@dataclass_transform(
type[ ServiceT]
) -> type[ ServiceT]
:@dataclass_transform(
str | None
= None) -> Callable[ [ type[ ServiceT]], type[ ServiceT]]
:Decorator marking a class as a Nexus service definition.
The decorator validates the operation definitions in the service definition: that they have the correct type, and that there are no duplicate operation names. The decorator also creates instances of the Operation class for each operation definition.
Example
@nexusrpc.service class MyNexusService: my_op: nexusrpc.Operation[MyInput, MyOutput] another_op: nexusrpc.Operation[str, dict] @nexusrpc.service(name="custom-service-name") class AnotherService: process: nexusrpc.Operation[ProcessInput, ProcessOutput]