Skip to main content

Nexus Python SDK

⚠️ This SDK is currently at an experimental release stage. Backwards-incompatible changes are anticipated until a stable release is announced. ⚠️

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}!")

The nexus-rpc name in PyPi was originally held by an unrelated project. Despite the version being at v1.x it is currently at an experimental release stage.

Metadata

Release files for nexus-rpc 1.4.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.4.0
File Size Uploaded
nexus_rpc-1.4.0.tar.gz 82.4 kB Details

Built distribution (wheel)

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

Total release size: 112.0 kB

Release files / nexus_rpc-1.4.0.tar.gz

Download URL nexus_rpc-1.4.0.tar.gz
Size 82.4 kB
Tags Source
SHA-256 checksum
How to use checksums
3b8b373d4865671789cc43623e3dc0bcbf192562e40e13727e17f1c149050fba
BLAKE2b-256 checksum
How to use checksums
35d5cd1ffb202b76ebc1b33c1332a3416e55a39929006982adc2b1eb069aaa9b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.19

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

Download URL nexus_rpc-1.4.0-py3-none-any.whl
Size 29.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
14c953d3519113f8ccec533a9efdb6b10c28afef75d11cdd6d422640c40b3a49
BLAKE2b-256 checksum
How to use checksums
11526327a5f4fda01207205038a106a99848a41c83e933cd23ea2cab3d2ebc6c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.19

Release history Release notifications | RSS feed

This release

1.4.0 This release

2 release files

1.3.0

2 release files

1.2.0

2 release files

1.1.0

2 release files

1.0.1

1 release file

1.0.0

1 release file

0.1.1

1 release file

0.1.0

1 release file

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