Skip to main content

Nexus Python SDK

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nexus_rpc-1.3.0.tar.gz (75.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nexus_rpc-1.3.0-py3-none-any.whl (28.9 kB view details)

Uploaded Python 3

File details

Details for the file nexus_rpc-1.3.0.tar.gz.

File metadata

  • Download URL: nexus_rpc-1.3.0.tar.gz
  • Upload date:
  • Size: 75.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.19

File hashes

Hashes for nexus_rpc-1.3.0.tar.gz
Algorithm Hash digest
SHA256 e56d3b57b60d707ce7a72f83f23f106b86eca1043aa658e44582ab5ff30ab9ad
MD5 55dc5a5942becb54c4ca2942ff920e59
BLAKE2b-256 2ef2d54f5c03d8f4672ccc0875787a385f53dcb61f98a8ae594b5620e85b9cb3

See more details on using hashes here.

File details

Details for the file nexus_rpc-1.3.0-py3-none-any.whl.

File metadata

  • Download URL: nexus_rpc-1.3.0-py3-none-any.whl
  • Upload date:
  • Size: 28.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.19

File hashes

Hashes for nexus_rpc-1.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 aee0707b4861b22d8124ecb3f27d62dafbe8777dc50c66c91e49c006f971b92d
MD5 5a3884b0d40ed19d0fe958bc49ae868b
BLAKE2b-256 d6740afd841de3199c148146c1d43b4bfb5605b2f1dc4c9a9087fe395091ea5a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page