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 |
No module docstring; 0/2 type variable, 1/1 function documented |
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 |
|
Context for the fetch_info method. |
Class |
|
Context for the fetch_result method. |
Class |
|
A Nexus handler manages a collection of Nexus service handlers. |
Class |
|
Context for the execution of the requested operation method. |
Class |
|
Base class for an operation handler in a Nexus service implementation. |
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 | 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. |
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}"