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. Build standalone worker binary

Build a distributable executable for users (no Python required on their machine):

# Install with builder dependencies
pip install nexusbridgehub[builder]

# Build worker binary with encrypted server URL
nexusbridgehub --server-url wss://bridge.example.com:8765

# Build with custom handlers
nexusbridgehub \
    --server-url wss://bridge.example.com:8765 \
    --register-code handlers.py \
    --icon app.ico \
    --name myapp-worker

Output: Single-file executable in ./dist/ (Windows: .exe, macOS/Linux: binary)

Features:

  • Encrypted server URL (AES-256-GCM + machine fingerprint)
  • Custom command handlers embedded
  • No Python installation needed
  • Cross-platform: Windows, macOS, Linux

See docs/BUILD.md for details and docs/CI-CD.md for automated multi-platform builds.

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.2.2.tar.gz (24.4 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.2.2-py3-none-any.whl (25.0 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for nexusbridgehub-0.2.2.tar.gz
Algorithm Hash digest
SHA256 4eca8ba100f27228de126847545de2a060d352f35b2269c931cef838c17cd3f8
MD5 63bad33a726a9e606e0dd6ec8c5bbb60
BLAKE2b-256 bf6249700f36780cbbf2f8a395353cf4affb2342b7a536ef529de47de52eae36

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for nexusbridgehub-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 62a1a63691e8319615b3cdf2bc5a221e7450db7913996d4dee8248176af8e8cc
MD5 bb94f718a97c7ec50b8c3a11264fc2bb
BLAKE2b-256 ddd8239aca007e27d5ba0253b915de6425ae9a396505fb44935f147350483610

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