Skip to main content

optio-chat-hub

The optio agent chat hub: an MQTT 5 broker that keeps names, channels, memberships, undelivered messages, avatars and chat attachments in MongoDB, so a restart loses nothing. An optio engine runs one inside unless it uses another hub as a client; the optio-chat-hub command runs one on its own, a fixed meeting point that stays up while optio apps come and go. Agents and people connect to it with optio-chat's client library, its optio-chat command and its agent plugin, and optio engines connect to it in client mode.

Install

pip install optio-chat-hub

Python 3.11 or newer, and a MongoDB the hub can reach.

Run

optio-chat-hub

The hub runs in the foreground until Ctrl-C, SIGTERM or SIGHUP (closing the terminal or tmux pane it runs in), and logs to stderr. At the first start it writes its settings file, with a free port and a generated password; every later start reads it, so the port and the password stay the same. It logs where it listens, its database and prefix, and what other servers need:

... INFO optio_chat_hub.cli: optio-chat-hub: listening on ws://127.0.0.1:40123/ (MQTT over WebSocket; GET /health)
... INFO optio_chat_hub.cli: optio-chat-hub: database optio_chat_hub, prefix hub; settings /home/me/.config/optio-chat-hub/settings.json
... INFO optio_chat_hub.cli: optio-chat-hub: other servers set OPTIO_CHAT_HUB=wss://<your domain>/ and OPTIO_CHAT_SHARED_PASSWORD to the password in /home/me/.config/optio-chat-hub/settings.json

Each optio server that connects is logged once (optio-chat-hub: optio server <id> connected). The password itself never appears in the log, nor do the credentials of the MongoDB URL.

Exit codes: 0 after a clean stop (also one during the start), 1 after an error, 2 when the start is refused (bad settings, MongoDB not answering, another hub on the same database and prefix, a taken port) or another hub took over. Code 2 covers refusals that pass as well as ones that last: after a reboot MongoDB or the bind address may not be up yet, and a killed hub's lease holds for up to 30 s. A supervisor (systemd, a restart loop) should restart the hub on every exit code, after a pause.

The settings file

~/.config/optio-chat-hub/settings.json (the folder is made with mode 0700, the file 0600: it holds the password):

Key Default Rule
bind "127.0.0.1" the interface to listen on
port a free port, picked at the first start 1-65535, then kept
password a generated random secret the hub's shared password
mongo_url "mongodb://localhost:27017" a mongodb:// or mongodb+srv:// URL, its user name and password percent-encoded (urllib.parse.quote_plus)
database "optio_chat_hub" 1-63 letters, digits, _ or -
prefix "hub" as database; the hub's collections are <prefix>_chat_*
max_file_mb 10 the largest chat attachment, whole MiB from 1 to 100
retention_days 7 how long an attachment is kept after the last message that carried it (messages too, once the hub keeps history), whole days from 1 to 36500
max_name_connections 8 how many connections (apps) one person's chat name holds at once, a whole number from 1 to 64; raise it above 8 only after the apps that connect are upgraded (an older optio-chat reads at most 8 profile parts and drops a longer list)

A key you leave out takes its default and is written back. An unknown key or a bad value (a number written as a string, say) stops the start with a message naming the key, and the file stays as it was. The hub makes the file private to you at every start; it stops when it cannot (a file another user owns). When it rewrites the file it replaces it, so a symlinked settings.json becomes a regular file.

Flags and the password variable

  • --bind HOST and --port N set the listen address and are saved to the settings file.
  • --config PATH uses another settings file.
  • OPTIO_CHAT_SHARED_PASSWORD, when set and not empty, is the hub's password instead of the file's (for admins who keep secrets elsewhere). It is never written to the file.

Use a fixed port for a deployment, so your proxy can point at it: start once with --port 8770 (or any free port), and the hub keeps it. If the saved port is taken, the start stops with a message; the hub never moves to another port.

Behind a TLS proxy

TLS is not the hub's concern. One port carries MQTT over WebSocket on / and the health check on /health; put your reverse proxy in front of it. With Caddy:

hub.example.com {
    reverse_proxy 127.0.0.1:8770
}

Caddy forwards WebSocket upgrades as they are, so nothing else is needed. Keep bind on 127.0.0.1 (or the address your proxy reaches) so that the hub is not open to the network without TLS. On a public port, give your proxy a connection limit: before a client has authenticated, the hub may hold up to 6 MiB of one WebSocket message per connection for up to 10 s, and it sets no cap on connections itself.

Health for monitors

GET /health on the hub's port answers 200 {"status": "ok"} while the hub runs and its database answers, else 503 {"status": "unavailable"}, within about two seconds either way (a database that hangs included). A monitor may ask every second.

Two hubs on one machine

Give each its own settings file, port and database (or prefix):

optio-chat-hub --config ~/.config/optio-chat-hub/team-a.json --port 8770
optio-chat-hub --config ~/.config/optio-chat-hub/team-b.json --port 8771

and set a different database or prefix in the second file. Only one hub may serve a database and prefix: the second one to start on the same pair is refused with a message naming it. A hub that was killed holds that pair for up to 30 s more; a clean stop gives it back at once.

The hosts that share a MongoDB this way should keep their clocks in sync: a host whose clock is more than 20 s ahead can take over the pair from a live hub. An optio engine's own hub does not take part in this check, so never point the command at an engine's database and prefix.

What other servers set

On every server that should use this hub, as optio engines read them (client mode), and as optio-chat's optio-chat command and plugin read them:

OPTIO_CHAT_HUB=wss://hub.example.com/
OPTIO_CHAT_SHARED_PASSWORD=<the password from the settings file>

Upgrading

When the hub starts on a store an older hub wrote, it converts the store once, one way: an older hub cannot read it afterwards. A hub upgrade comes before the clients that need its new features (optio-chat's README lists them).

Design: docs/2026-11-28-standalone-chat-hub-design.md in the optio repository.

Metadata

Release files for optio-chat-hub 0.2.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 optio-chat-hub 0.2.0
File Size Uploaded Provenance Actions
optio_chat_hub-0.2.0.tar.gz 374.9 kB Without provenance Details for optio_chat_hub-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for optio-chat-hub 0.2.0
File Interpreter ABI Platform Actions
optio_chat_hub-0.2.0-py3-none-any.whl Python 3 none any Details for optio_chat_hub-0.2.0-py3-none-any.whl

Total release size: 523.8 kB

Release files / optio_chat_hub-0.2.0.tar.gz

Download URL optio_chat_hub-0.2.0.tar.gz
Size 374.9 kB
Tags Source
SHA-256 checksum
How to use checksums
2faf8e4a5b7fcd2ba14da50cedb4ad0b475b3ebc93295692bf2c297a453a0dc6
BLAKE2b-256 checksum
How to use checksums
9a18af56604b43b3ca3fc40c3539e51db36be72e3ae192239490321053dd95a0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.5

Release files / optio_chat_hub-0.2.0-py3-none-any.whl

Download URL optio_chat_hub-0.2.0-py3-none-any.whl
Size 148.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b46d688a9d5475f1dc46365a769176adc72d990bb47f97ad73042f707cd9de7c
BLAKE2b-256 checksum
How to use checksums
97091c0a9b803687d7d66c0544a4d02ffb8f5e42bfb13a359fe2868574215cc3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.5

Security for optio-chat-hub 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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