Simplified MQTT pub/sub wrapper with auto-reconnect
Project description
philiprehberger-mqtt-client
Simplified MQTT pub/sub wrapper with auto-reconnect.
Installation
pip install philiprehberger-mqtt-client
Usage
from philiprehberger_mqtt_client import MQTTClient
client = MQTTClient("mqtt://localhost:1883", client_id="my-app")
@client.on("home/temperature")
def on_temperature(topic, payload):
print(f"Temperature: {float(payload)}°C")
@client.on("home/+/status") # wildcard
def on_device_status(topic, payload):
device = topic.split("/")[1]
print(f"{device}: {payload}")
# Publish
client.publish("home/lights/living", "on")
client.publish_json("home/sensors/data", {"temp": 22.5, "humidity": 45})
# Connect (blocks with auto-reconnect)
client.connect()
# Or background mode
client.connect(background=True)
Features
- Decorator-based subscriptions
- MQTT wildcard support (
+and#) - Auto-reconnect with exponential backoff
- JSON publish/subscribe helpers
- TLS support (
mqtts://) - Last will and testament
- Authentication
API
| Function / Class | Description |
|---|---|
MQTTClient(broker_url, client_id, username, password, ...) |
Simplified MQTT client with decorator-based subscriptions and auto-reconnect |
Development
pip install -e .
python -m pytest tests/ -v
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file philiprehberger_mqtt_client-0.1.8.tar.gz.
File metadata
- Download URL: philiprehberger_mqtt_client-0.1.8.tar.gz
- Upload date:
- Size: 4.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
26ebc6bba1c71241a1c03bed010431db02f29c622f2ba94757f8b37275b8441f
|
|
| MD5 |
9e3646327d574d92c493d8ad966b83d5
|
|
| BLAKE2b-256 |
fa4a76a8da93e1817fd3732f43bfa83f91bd832f2ba7aa318e96cd330cda1767
|
File details
Details for the file philiprehberger_mqtt_client-0.1.8-py3-none-any.whl.
File metadata
- Download URL: philiprehberger_mqtt_client-0.1.8-py3-none-any.whl
- Upload date:
- Size: 5.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1d95b9c7f395095bf77daed0e56e619735012d30609eebff6ea4258ded363916
|
|
| MD5 |
02034eafb9620816cd545dc1a1fe715a
|
|
| BLAKE2b-256 |
15429e327198ca6bccce3f21b8252440717c93adf7b3d499a4e45730f671f0ed
|