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 |
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 HOSTand--port Nset the listen address and are saved to the settings file.--config PATHuses 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.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| optio_chat_hub-0.1.0.tar.gz | 279.7 kB | Without provenance | Details for optio_chat_hub-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| optio_chat_hub-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for optio_chat_hub-0.1.0-py3-none-any.whl |
Total release size: 395.1 kB
Release files / optio_chat_hub-0.1.0.tar.gz
| Download URL | optio_chat_hub-0.1.0.tar.gz |
|---|---|
| Size | 279.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f7e619702b7655b056986ee0f7973f7ebb5b4599339ecfbf6566ed0bf2e00d83
|
|
BLAKE2b-256 checksum How to use checksums |
c89229b2720e50b8cc24238c46fee18b7c5d2d5a3e1a56f267eb29f4bfedb1af
|
| 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.1.0-py3-none-any.whl
| Download URL | optio_chat_hub-0.1.0-py3-none-any.whl |
|---|---|
| Size | 115.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1abebf910da466451e5ae32fb2792f24234e60440d192f55e64994cbcb372da6
|
|
BLAKE2b-256 checksum How to use checksums |
67ea3cb9d85c58a0b0975ef8a78c6ad556282b326f11d3f7a569aef04b6cc125
|
| 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.1.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.