Skip to main content

Simplified MQTT pub/sub wrapper with auto-reconnect

Project description

philiprehberger-mqtt-client

Simplified MQTT pub/sub wrapper with auto-reconnect.

Install

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

License

MIT

Project details


Download files

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

Source Distribution

philiprehberger_mqtt_client-0.1.1.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

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

philiprehberger_mqtt_client-0.1.1-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

Details for the file philiprehberger_mqtt_client-0.1.1.tar.gz.

File metadata

File hashes

Hashes for philiprehberger_mqtt_client-0.1.1.tar.gz
Algorithm Hash digest
SHA256 75ddeb81ae72d59df824e5a78957432f6a69d618f9dc5c2b1adf40c2ca3665c8
MD5 291a526c7c2ef0041f69804880d4e585
BLAKE2b-256 00f5e418007d1bbbe018f5f041d68d443fd87e462ffb7d9fb6f8618c5efe3a2d

See more details on using hashes here.

File details

Details for the file philiprehberger_mqtt_client-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for philiprehberger_mqtt_client-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1ccc98159a9202f2418b104926d4c4b5eacf6878b4370a1b5862b362b225e0b8
MD5 9273ba8d7ae8063e36b719790d913880
BLAKE2b-256 5327ae37d5ad7bb32eb74f8a5c2ff754f8a08ee757fb78554a9deb386bd03b57

See more details on using hashes here.

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