Grandstream UCM6204 IP-PBX monitor/control: WebSocket call events, HTTPS API client, trunk call router, MQTT bridge
pip install somestuff-ucmstuff Copy PIP instructions
Monitor and control a Grandstream UCM6204 IP-PBX from Python: receive real-time call events over WebSocket, act on them via the HTTPS API, route incoming trunk calls by caller, and optionally bridge everything onto MQTT.
The UCM6204 exposes two separate interfaces with different session models:
They are genuinely independent: the API user does not work on the WebSocket, and the WebSocket does not accept HTTPS-API query actions. To both monitor and control calls you run both clients together.
ucm6204_api — the core: UCMEventClient (WebSocket events, auto-reconnect and heartbeat), UCM6204 (HTTPS-API control), TrunkCallRouter / IncomingCall (route incoming calls on a trunk to a caller-based branch), a /healthz server for Kubernetes probes, and the Typer CLI (ucm6204).
ucm6204_api_rest — UCM6204Rest, a subclass adding a named, typed, documented method for every HTTPS-API action (trunks, routes, IVRs, queues, paging, accounts, users, dialing/transfer, ...) on top of the generic api_call.
mqtt_bridge — MqttEventBridge publishes events and parsed incoming calls to MQTT and, optionally, accepts accept / refuse / hangup commands. It is the only module that imports mqttstuff. Topics (base topic defaults to ucm6204), all published with retain=False:
ucm6204/events/ full notify event as JSON ucm6204/calls/ /incoming parsed IncomingCall as JSON ucm6204/calls/ /ended same call once its leg terminates ucm6204/cmd/{accept,refuse,hangup} inbound, payload {"channel": "PJSIP/..."} is the call's inbound_trunk_name, sanitized for use as a topic segment.
example_router — runnable example wiring UCMEventClient, UCM6204 and TrunkCallRouter together from environment variables (see Library).
/healthz — served by the CLI on --health-host / --health-port (default 0.0.0.0:8070); returns 200 with {"connected": true} once the WebSocket is connected and subscribed, otherwise 503. The process only makes outbound connections to the UCM, so no service or ingress is needed.
Logging (loguru, with an intercept for stdlib logging) and the startup banner are shared via somestuff.ucmstuff.
pip install somestuff-ucmstuff somestuff is a PEP 420 namespace; the package is imported as somestuff.ucmstuff and shares the namespace with the other somestuff-* distributions.
Both interfaces negotiate a weak Diffie-Hellman group; the clients lower the OpenSSL security level (@SECLEVEL=1) automatically so the handshake succeeds.
The console script and module invocation are equivalent:
ucm6204 \ --host ucm.example.lan --port 8089 \ --web-user webuser --web-password '...' \ --api-user cdrapi --api-password '...' \ --trunk MyTrunk --trunk AnotherTrunk # repeatable; omit for monitor-only python3 -m somestuff.ucmstuff.ucm6204_api --host ucm.example.lan --web-user webuser --web-password '...' -v Every event is logged; --trunk attaches a TrunkCallRouter and logs incoming calls on those trunks. Add your own branching in code (see Library).
There is no env-file loader: put the variables in a file of your own, for example ucm.local.env, and export them into the shell before starting:
set -a; . ./ucm.local.env; set +a python3 -m somestuff.ucmstuff.example_router ucm6204 --host "$UCM_HOST" --port "$UCM_PORT" --web-user "$UCM_WEB_USER" --web-password "$UCM_WEB_PASSWORD" \ --api-user "$UCM_API_USER" --api-password "$UCM_API_PASSWORD" The repository additionally contains ucm.env.example, a Kubernetes secret example and somestuff_ucm6204_deployment.yml (one pod = events + control, /healthz backing the liveness/readiness probes); they are not part of the installed package: https://github.com/vroomfondel/somestuff/tree/main/somestuff/ucmstuff/
Keep real credentials in *.local.* files that are not committed.
Coordinated monitor + control, as in example_router:
from somestuff.ucmstuff.ucm6204_api import UCM6204, UCMEventClient, TrunkCallRouter, IncomingCall api = UCM6204(host="ucm.example.lan", api_user="cdrapi", api_password="...") api.connect() events = UCMEventClient(host="ucm.example.lan", web_user="webuser", web_password="...") def route(call: IncomingCall) -> None: if call.number == "+491234567": api.accept_call(call.channel) elif call.name.upper().startswith("SPAM"): api.refuse_call(call.channel) events.add_event_handler(TrunkCallRouter("MyTrunk", on_call=route).handle) events.run(block=True) Full API access:
UCMEventClient implements the WebSocket model; the url-POST model is intentionally not used. UCM6204 / UCM6204Rest implement the request/response HTTPS API from the same guide, which is still current.
GNU Lesser General Public License v3 (LGPLv3)
call-routing grandstream mqtt pbx sip ucm6204 voip websocket
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
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.
None of the files in this release were uploaded with provenance metadata.
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.




