Skip to main content

nodus-gateway

WebSocket coordination hub for Nodus AI systems.

A typed message exchange point where agents, channels, and tools connect to send RequestEnvelope / ResponseEnvelope / EventEnvelope messages. Provides handler dispatch, idempotency caching, event broadcasting, and an async client. No required dependencies — WebSocket transport is optional.

Status: v0.1.0 — published on PyPI.


Install

pip install nodus-gateway

# With WebSocket transport:
pip install "nodus-gateway[websockets]"

What it provides

Component Purpose
GatewayServer WebSocket server; registers handlers, dispatches requests
HandlerRegistry Maps method names → async handler functions
JobResultCache Idempotent result cache with TTL (dedup concurrent requests)
EventBroadcaster Fan-out execution events to all subscribers
GatewayClient Async client for connecting to a GatewayServer

GatewayServer

from nodus_gateway import GatewayServer, HandlerRegistry

registry = HandlerRegistry()

@registry.register("agent.run")
async def handle_agent_run(params: dict) -> dict:
    return {"status": "ok", "run_id": "run-123"}

server = GatewayServer(host="127.0.0.1", port=18789, registry=registry)
await server.start()   # blocks until stopped
# await server.stop()

Requires pip install "nodus-gateway[websockets]" for the WebSocket transport. Without websockets installed, GatewayServer raises ImportError on start.


HandlerRegistry

from nodus_gateway import HandlerRegistry

registry = HandlerRegistry()

# Decorator form
@registry.register("memory.read")
async def handle_memory_read(params: dict) -> dict:
    return {"value": "..."}

# Imperative form
registry.register("memory.write", handle_write)

handler = registry.get("memory.read")   # callable | None
methods = registry.list_methods()        # list[str]
registry.unregister("memory.read")

JobResultCache

from nodus_gateway import JobResultCache

cache = JobResultCache(ttl_seconds=300)

# Store and retrieve results by job ID
cache.set("job-abc", {"result": "done"})
result = cache.get("job-abc")    # dict | None (None if expired)
cache.evict_expired()            # remove expired entries
len(cache)

Used internally by GatewayServer to make concurrent duplicate requests idempotent — only the first call executes; subsequent calls get the cached result.


EventBroadcaster

from nodus_gateway import EventBroadcaster

broadcaster = EventBroadcaster()

def my_handler(event: dict) -> None:
    print(event["type"], event["payload"])

sub_id = broadcaster.subscribe(my_handler)
broadcaster.broadcast({"type": "flow.completed", "payload": {"id": "f1"}})
broadcaster.unsubscribe(sub_id)

GatewayClient

from nodus_gateway import GatewayClient

async with GatewayClient("ws://127.0.0.1:18789") as client:
    response = await client.send("agent.run", {"objective": "hello"})
    # response is the handler's return value

    # Subscribe to events
    client.subscribe(lambda event: print(event))

Requires websockets for the actual WebSocket connection.


Design

  • No required dependencies. Core components (HandlerRegistry, JobResultCache, EventBroadcaster) are pure stdlib. WebSocket transport is opt-in.
  • Thread-safe. JobResultCache and EventBroadcaster use threading.Lock.
  • Idempotent dispatch. JobResultCache deduplicates concurrent requests with the same job ID.

Development

pip install -e ".[dev]"
pytest tests/ -q

License

MIT — see LICENSE.

Metadata

Release files for nodus-gateway 0.1.1

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

Source distribution (sdist)

Source distribution for nodus-gateway 0.1.1
File Size Uploaded
nodus_gateway-0.1.1.tar.gz 11.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for nodus-gateway 0.1.1
File Interpreter ABI Platform
nodus_gateway-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 21.2 kB

Release files / nodus_gateway-0.1.1.tar.gz

Download URL nodus_gateway-0.1.1.tar.gz
Size 11.0 kB
Tags Source
SHA-256 checksum
How to use checksums
546a20a048039cd2ec3ce608f1bbde8afa004222eac0136d730ed692f4808c13
BLAKE2b-256 checksum
How to use checksums
4b48614ed3bafd7b2d8a372f38367be1ad49ac27365b72d4c287bcf993248fb8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.9

Release files / nodus_gateway-0.1.1-py3-none-any.whl

Download URL nodus_gateway-0.1.1-py3-none-any.whl
Size 10.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5663ddb7293f63d564616f293c4a1aeca0ce0d8dbc558351f1852a7bc26aae06
BLAKE2b-256 checksum
How to use checksums
6d5eab0c6e800d92e59c3446be581b0b8b0fe32d7a0c0ac5ec03d0597a0f262c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.9

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

2 release files

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