Skip to main content

Universal bridge for distributed bot control: bot -> server -> user worker

Project description

NexusBridgeHub

PyPI version Python 3.11–3.14 Tests License: MIT

Universal bridge for distributed bot control: bot → server → user worker.

Add a thin integration layer to any Python bot or automation project — keep your business logic local, control it remotely through a central server.

Русская документация: README.ru.md · Деплой на VPS: docs/DEPLOY.ru.md · Проверка: docs/TESTING.ru.md

Python versions

Version Status
3.10 and below Not supported — pip will refuse to install
3.11 – 3.14 Fully supported — every release is tested in CI on 3.11, 3.12, 3.13, and 3.14

Requires Python 3.11+. Check your version: python --version.

Architecture

┌─────────────┐   JWT controller  ┌──────────────┐   JWT worker   ┌─────────────────┐
│ Telegram    │ ────────────────► │ NexusBridgeHub │ ◄───────────── │ User Worker App │
│ Bot / API   │                   │   Server     │                │ (local runtime) │
└─────────────┘                   └──────────────┘                └─────────────────┘
Component Role
Server Routes commands from bot to the correct user's worker
BridgeClient Embedded in a project on the user's machine; executes registered functions
BridgeController Used by a bot or API to invoke remote functions
WorkerApp Thin standalone client; pairs via code, no secrets in binary

Security model

  • JWT tokens — workers and controllers authenticate with short-lived tokens (no hardcoded secrets in the app)
  • Pair codes — bot generates 8-char code; user enters it in the worker app → receives JWT
  • Encrypted server URL — WSS address stored as AES-256-GCM blob with PBKDF2 key derivation + machine fingerprint (not plain text in .exe)
  • Thin client buildnexusbridgehub-build generates per-build seed; combine with PyInstaller + optional commercial obfuscators

Error handling and logging

  • A failing handler does not crash the worker — the error is returned as ok: false and the worker keeps running
  • Auto-reconnect on WebSocket drops (BridgeClient, WorkerApp)
  • Invalid messages are logged and skipped; the session stays alive
  • Log level: NEXUSBRIDGEHUB_LOG_LEVEL=DEBUG (default INFO)

Install

pip install nexusbridgehub
# or from source
pip install -e ".[dev]"

Quick start

1. Start server (VPS)

export NEXUSBRIDGEHUB_JWT_SECRET="your-48-char-minimum-secret-key-here"
nexusbridgehub-server --host 0.0.0.0 --port 8765

2. Embed in your project (user's machine)

from nexusbridgehub import BridgeClient

bridge = BridgeClient(
    server_url="wss://bridge.example.com:8765",
    token=user_jwt,
    project_id="taskrelay",
    user_id=str(user_id),
)
bridge.register("run_task", run_task)
bridge.register("worker_status", get_worker_status)
await bridge.run()

3. Bot side (controller on VPS)

from nexusbridgehub import AuthManager, BridgeController
from nexusbridgehub.protocol import Role

auth = AuthManager(os.environ["NEXUSBRIDGEHUB_JWT_SECRET"])

# Generate pair code for user (show in Telegram)
code = auth.create_pair_code(project_id="taskrelay", user_id=str(user_id))

# After user paired — invoke remote functions
bot_jwt = auth.create_token(role=Role.CONTROLLER, project_id="taskrelay", user_id=str(user_id))
ctrl = BridgeController(
    server_url="wss://bridge.example.com:8765",
    token=bot_jwt,
    project_id="taskrelay",
    user_id=str(user_id),
)
result = await ctrl.invoke("run_task", {"job_id": "job-42"})

4. Thin client for users

# User runs with pair code from bot (no server URL visible)
nexusbridgehub-worker --pair-code ABCD1234

# Build distributable .exe with encrypted server URL
pip install nexusbridgehub[builder]
nexusbridgehub-build --server-url wss://bridge.example.com:8765 --output-dir worker_dist

Per-user workers

Each end user runs a worker app on their own machine:

  1. User opens the bot → bot shows a pair code
  2. User runs the worker with that code → worker connects to your bridge server
  3. Bot sends run_task, worker_status, etc. → commands execute on the user's machine
  4. Local resources stay on the user's device — the bot only orchestrates

See examples/minimal/ for a step-by-step RU/EN worker test, examples/worker_integration.py (EN) or examples/worker_integration.ru.py (RU) for project integration stubs.

Protocol

JSON messages over WebSocket:

Type Direction Purpose
register client → server Join as worker or controller
invoke controller → worker Call registered function
result worker → controller Return value or error
pair_request worker → server Redeem pair code for JWT

Deployment

Production guide (VPS, systemd, WSS, Hetzner/Contabo): docs/DEPLOY.ru.md

Development

pip install -e ".[dev]"
pytest
python -m build   # PyPI wheel
python -m twine check dist/*

Release guide: docs/PUBLISH.ru.md

License

MIT

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

nexusbridgehub-0.1.0.tar.gz (19.1 kB view details)

Uploaded Source

Built Distribution

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

nexusbridgehub-0.1.0-py3-none-any.whl (20.4 kB view details)

Uploaded Python 3

File details

Details for the file nexusbridgehub-0.1.0.tar.gz.

File metadata

  • Download URL: nexusbridgehub-0.1.0.tar.gz
  • Upload date:
  • Size: 19.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for nexusbridgehub-0.1.0.tar.gz
Algorithm Hash digest
SHA256 8ffbebe521e7fd2148dd2d1d509d43fda3edbb6c23d76f2a02cd0447b71a10ef
MD5 914d3244ebb9171f43ad32b771f871fd
BLAKE2b-256 7960819f8ac9d071c378d782b7455963c84e8f7cafb1d71f3d391fbc048e7502

See more details on using hashes here.

Provenance

The following attestation bundles were made for nexusbridgehub-0.1.0.tar.gz:

Publisher: publish.yml on rxzwu/NexusBridgeHub

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nexusbridgehub-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: nexusbridgehub-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 20.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for nexusbridgehub-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cc8f52e91e2fada8b9000fd4cdd11f5d3b58ea4fd69005a4ce2fda0a6d6aa494
MD5 c44be3a61febc5a4bc78ef8bc27364e6
BLAKE2b-256 fb3e415695123bb806f308f318ec6e72de73dee53a995f628938278f1071572d

See more details on using hashes here.

Provenance

The following attestation bundles were made for nexusbridgehub-0.1.0-py3-none-any.whl:

Publisher: publish.yml on rxzwu/NexusBridgeHub

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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