Skip to main content

Nexus Python SDK

What is Nexus?

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.

Installation

uv add nexus-rpc

or

pip install nexus-rpc

Usage

The SDK currently supports two use cases:

  1. As an end user, defining Nexus services and operations.

  2. Implementing a Nexus handler that can accept and respond to incoming Nexus requests, dispatching to the corresponding user-defined Nexus operation.

The handler in (2) would form part of a server or worker that processes Nexus requests; the SDK does not yet provide reference implementations of these, or of a Nexus client.

Defining Nexus services and operations

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:
    # You can create an __init__ method accepting what is needed by your operation
    # handlers to handle requests. You will typically instantiate your service handler class
    # when starting your Nexus server/worker.

    # This is a Nexus operation that responds synchronously to all requests. That means
    # that the `start` method returns the final operation result.
    #
    # Sync operations are free to make arbitrary network calls.
    @nexusrpc.handler.sync_operation
    async def my_sync_operation(
        self, ctx: nexusrpc.handler.StartOperationContext, input: MyInput
    ) -> MyOutput:
        return MyOutput(message=f"Hello {input.name}!")

Implementing and registering a dynamic Operation handler

A dynamic Operation handler handles requests whose operation name is not registered with a service handler. Named Operations take precedence. A service handler can have one dynamic handler, with or without named Operations.

The handler receives the requested operation name through ctx.operation and raw input as nexusrpc.LazyValue. Decode the input with await input.consume(as_type=...). Do not use the input after the handler returns. The handler can be sync or async.

from typing import Any

import nexusrpc.handler


class MyDynamicOperation(nexusrpc.handler.OperationHandler[nexusrpc.LazyValue, Any]):
    # Dynamic handler that simply echoes the input back synchronously.
    async def start(
        self, ctx: nexusrpc.handler.StartOperationContext, input: nexusrpc.LazyValue
    ) -> nexusrpc.handler.StartOperationResultSync[Any]:
        value = await input.consume(as_type=str)
        return nexusrpc.handler.StartOperationResultSync(value)

    async def cancel(
        self, ctx: nexusrpc.handler.CancelOperationContext, token: str
    ) -> None:
        raise NotImplementedError("An operation that responded synchronously cannot be cancelled.")

Register the handler with @nexusrpc.handler.operation_handler(dynamic=True) on your Nexus service handler. Each service can have maximum 1 dynamic handler. The registration will error if:

  • A name is provided for the dynamic handler
  • A dynamic handler is already defined on this service handler
@nexusrpc.handler.service_handler(name="example-service")
class MyDynamicServiceHandler:
    @nexusrpc.handler.operation_handler(dynamic=True)
    def forward(self) -> nexusrpc.handler.OperationHandler[nexusrpc.LazyValue, Any]:
        return MyDynamicOperation()


handler = nexusrpc.handler.Handler([MyDynamicServiceHandler()])

Middleware applies to dynamic handlers as it does to named Operations and receives the undecoded nexusrpc.LazyValue on start.


Versions 1.0.1 and earlier of the nexus-rpc package on PyPI belong to an unrelated project. The Nexus Python SDK starts at version 1.1.0.

Metadata

Release files for nexus-rpc 1.6.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for nexus-rpc 1.6.0
File Size Uploaded Provenance Actions
nexus_rpc-1.6.0.tar.gz 101.3 kB With provenance Details for nexus_rpc-1.6.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for nexus-rpc 1.6.0
File Interpreter ABI Platform Actions
nexus_rpc-1.6.0-py3-none-any.whl Python 3 none any Details for nexus_rpc-1.6.0-py3-none-any.whl

Total release size: 132.9 kB

Release files / nexus_rpc-1.6.0.tar.gz

Download URL nexus_rpc-1.6.0.tar.gz
Size 101.3 kB
Tags Source
SHA-256 checksum
How to use checksums
c1981fb45ef42dd46529035d5fa5fd6748cbfbd4428fc9d3a0c1acb559e708e2
BLAKE2b-256 checksum
How to use checksums
1718ba511fc6889802b0e797d60d8cfcaa51cf4c5037d52e5f62962599a51a21
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.

Transparency log

Release files / nexus_rpc-1.6.0-py3-none-any.whl

Download URL nexus_rpc-1.6.0-py3-none-any.whl
Size 31.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a8220f62bd7cccdb9ab60a01bc2c095d1a9cc6a0ec65075efbad557554e339f6
BLAKE2b-256 checksum
How to use checksums
cfd9c0f4df94d0f0b0c69243aafaa79144d13e8f35953c4236ba213991864a73
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.

Transparency log

Security for nexus-rpc 1.6.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for nexus_rpc-1.6.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page