Skip to main content

ebus-mqtt-client

PyPI version Ruff

Standalone MQTT client wrapper around paho-mqtt v2.

Features

  • TLS support (secure with CA verification, insecure, or plaintext)
  • Resilient connect: construction never blocks or raises on a down broker (connect_async); the connection is established and retried on the network loop started by start()
  • Automatic reconnection with configurable backoff
  • Subscription recovery on reconnect
  • Topic pattern matching via paho's MQTTMatcher
  • Last Will and Testament (LWT)
  • MQTTv3 and MQTTv5 protocol support
  • Factory method for dict-based configuration
  • Bounded, broker-independent shutdown: stop(timeout=...) returns promptly even against a dead broker
  • Bounded publish flush: publish_and_flush(...) lands a final message before a clean disconnect, no fixed sleep

Install

pip install ebus-mqtt-client

Quick start

from ebus_mqtt_client import MqttClient

client = MqttClient(
    client_id="my-client",
    endpoint="broker.example.com",
    port=1883,
)
client.start()

client.subscribe("sensors/#", callback_param)
client.publish("sensors/temp", "22.5")

client.stop()

Graceful shutdown

Publish a final retained message and flush it (bounded) before disconnecting, then stop within a time bound even when the broker is unreachable:

# Land a final state update, waiting up to 1s for it to actually be sent.
# Returns True on flush; False (without blocking or raising) if not connected,
# the publish fails, or the flush exceeds the timeout.
client.publish_and_flush(
    "devices/my-client/state", "disconnected", retain=True, timeout=1.0
)

# Returns within ~timeout seconds even if the broker is gone.
client.stop(timeout=2.0)

publish() also returns paho's MQTTMessageInfo (or None if there is no client), so you can wait for a single message yourself: client.publish(topic, data).wait_for_publish(1.0).

From a config dict

cfg = {
    "host": "broker.example.com",
    "port": 8883,
    "use_tls": True,
    "tls_insecure": False,
    "tls_ca_cert": "/path/to/ca.pem",
    "authentication": {
        "type": "USER_PASS",
        "username": "user",
        "password": "secret",
    },
}

client = MqttClient.from_config(cfg, client_id="my-client")
client.start()

mTLS (client-certificate authentication)

When the broker authenticates the client via the TLS handshake (no username/password), supply a client cert and key. File-path form:

cfg = {
    "host": "broker.example.com",
    "port": 8883,
    "use_tls": True,
    "tls_insecure": False,
    "tls_ca_cert": "/path/to/ca.pem",
    "tls_client_cert": "/path/to/client.crt",
    "tls_client_key": "/path/to/client.key",
    # "tls_client_key_password": "...",  # only if the key is encrypted
}

client = MqttClient.from_config(cfg, client_id="my-client")
client.start()

In-memory form — useful when the cert/key are fetched from a secret store rather than the filesystem. If both the path and *_data forms are supplied for the same item, the *_data form wins and a warning is logged:

cfg = {
    "host": "broker.example.com",
    "port": 8883,
    "use_tls": True,
    "tls_insecure": False,
    "tls_ca_data": ca_pem_str,
    "tls_client_cert_data": client_cert_pem_str,
    "tls_client_key_data": client_key_pem_str,
}

client = MqttClient.from_config(cfg, client_id="my-client")
client.start()

Releasing

The version lives in exactly one place: __version__ in src/ebus_mqtt_client/__init__.py. pyproject.toml reads it dynamically, the setup.py legacy shim reads it by regex, and the publish workflow refuses to release a tag that disagrees with it. To cut a release:

  1. Bump __version__ in src/ebus_mqtt_client/__init__.py (the only place).
  2. Move the CHANGELOG's [Unreleased] entries under a new version heading.
  3. Commit: git commit -am "Release X.Y.Z".
  4. Tag it to match, v-prefixed: git tag vX.Y.Z.
  5. Push the tag: git push --tags (a plain git push does not trigger a release).

Pushing a v* tag runs the publish workflow, which verifies the tag equals v$__version__ (a mismatch fails before anything is built), builds the sdist and wheel, and publishes to PyPI via Trusted Publishing (OIDC, no stored token).

Contributing

See CONTRIBUTING.md for how to file Discussions, Issues, and pull requests. The library is intentionally a thin MQTT-only layer — Homie / eBus features belong in ebus-sdk.

License

MIT License — Copyright (c) 2026 Clark Communications Corporation

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ebus_mqtt_client-0.1.8.tar.gz (17.2 kB view details)

Uploaded Source

Built Distribution

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

ebus_mqtt_client-0.1.8-py3-none-any.whl (10.5 kB view details)

Uploaded Python 3

File details

Details for the file ebus_mqtt_client-0.1.8.tar.gz.

File metadata

  • Download URL: ebus_mqtt_client-0.1.8.tar.gz
  • Upload date:
  • Size: 17.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for ebus_mqtt_client-0.1.8.tar.gz
Algorithm Hash digest
SHA256 282347fbdca2b2baa395a03b677eb78bb320a9a17dadd1b0d73862b8da736833
MD5 4c3bda4d3a6634019a580552b7ea4dff
BLAKE2b-256 163b8c80258871abe09f90e3a11218485294ebed0fe88f80546d07fd58c62158

See more details on using hashes here.

Provenance

The following attestation bundles were made for ebus_mqtt_client-0.1.8.tar.gz:

Publisher: publish.yml on electrification-bus/ebus-mqtt-client

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

File details

Details for the file ebus_mqtt_client-0.1.8-py3-none-any.whl.

File metadata

File hashes

Hashes for ebus_mqtt_client-0.1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 7a2876a148e7c31be13fc7dc4a0f819f7ee51949bf2588c6996a5e00889a105e
MD5 bbb8c7eb37446528cf8470a32d1f139b
BLAKE2b-256 af42f8e4565adf3e13f52690172bd6e8f925a8adfbbea12c4b9eb9d1004061bf

See more details on using hashes here.

Provenance

The following attestation bundles were made for ebus_mqtt_client-0.1.8-py3-none-any.whl:

Publisher: publish.yml on electrification-bus/ebus-mqtt-client

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