Components for implementing Nexus handlers.
Server/worker authors will use this module to create the top-level Nexus handlers responsible for dispatching requests to Nexus operations.
Nexus service/operation authors will use this module to implement operation handler methods within service handler classes.
| Module | _common |
Undocumented |
| Module | _core |
This module contains Handler classes. A Handler manages a collection of Nexus service handlers. It receives and responds to incoming Nexus requests, dispatching to the corresponding operation handler. |
| Module | _decorators |
Undocumented |
| Module | _operation |
No module docstring; 3/3 functions, 1/1 class documented |
| Module | _syncio |
No module docstring; 1/1 class documented |
| Module | _util |
No module docstring; 0/1 type variable, 1/1 function documented |
From __init__.py:
| Class | |
Context for the cancel method. |
| Class | |
A Nexus handler manages a collection of Nexus service handlers. |
| Class | |
An OperationHandler where start and cancel can be awaited by an async runtime. It can produce a result synchronously by returning StartOperationResultSync or asynchronously by returning StartOperationResultAsync... |
| Class | |
Context for the execution of the requested operation method. |
| Class | |
Base class for an operation handler in a Nexus service implementation. |
| Class | |
Middleware for operation handlers. |
| Class | |
Indicates whether a a Nexus task has been cancelled during a sync operation or before an async operation has returned a token. |
| Class | |
Context for the start method. |
| Class | |
A value returned by the start method of a nexus operation handler indicating that the operation is responding asynchronously. |
| Class | |
A result returned synchronously by the start method of a nexus operation handler. |
| Function | operation |
Decorator marking an operation handler factory method in a service handler class. |
| Function | service |
Decorator that marks a class as a Nexus service handler. |
| Function | sync |
Decorator marking a method as the start method for a synchronous operation. |
OperationHandlerFactoryT) -> OperationHandlerFactoryT:str | None = None) -> Callable[ [ OperationHandlerFactoryT], OperationHandlerFactoryT]:Decorator marking an operation handler factory method in a service handler class.
An operation handler factory method is a method that takes no arguments other than
self and returns an OperationHandler instance.
| Parameters | |
method:OperationHandlerFactoryT | None | The method to decorate. |
name:str | None | Optional name for the operation. If not provided, the method name will be used. |
| Returns | |
OperationHandlerFactoryT | Callable[ | Undocumented |
type[ ServiceHandlerT]) -> type[ ServiceHandlerT]:type[ Any] | None = None) -> Callable[ [ type[ ServiceHandlerT]], type[ ServiceHandlerT]]:str) -> Callable[ [ type[ ServiceHandlerT]], type[ ServiceHandlerT]]:Decorator that marks a class as a Nexus service handler.
A service handler is a class that implements the Nexus service by providing operation handler implementations for all operations in the service.
The class should implement Nexus operation handlers as methods decorated with
operation handler decorators such as @nexusrpc.handler.operation_handler.
Example
from nexusrpc.handler import service_handler, sync_operation @service_handler(service=MyService) class MyServiceHandler: @sync_operation async def my_operation( self, ctx: StartOperationContext, input: MyInput ) -> MyOutput: return MyOutput(processed=input.data)
| Parameters | |
cls:type[ | The service handler class to decorate. |
service:type[ | The service definition that the service handler implements. |
name:str | None | Optional name to use for the service, if a service definition is not provided.
service and name are mutually exclusive. If neither is provided, the
class name will be used. |
| Returns | |
type[ | Undocumented |
Callable[ [ ServiceHandlerT, StartOperationContext, InputT], Awaitable[ OutputT]]) -> Callable[ [ ServiceHandlerT, StartOperationContext, InputT], Awaitable[ OutputT]]:Callable[ [ ServiceHandlerT, StartOperationContext, InputT], OutputT]) -> Callable[ [ ServiceHandlerT, StartOperationContext, InputT], OutputT]:str | None = None) -> Callable[ [ Callable[ [ ServiceHandlerT, StartOperationContext, InputT], Any]], Callable[ [ ServiceHandlerT, StartOperationContext, InputT], Any]]:Decorator marking a method as the start method for a synchronous operation.
Example
import httpx from nexusrpc.handler import service_handler, sync_operation @service_handler class MyServiceHandler: @sync_operation async def process_data( self, ctx: StartOperationContext, input: str ) -> str: # You can use asynchronous I/O libraries async with httpx.AsyncClient() as client: response = await client.get("https://api.example.com/data") data = response.json() return f"Processed: {data}"