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.0.tar.gz (3.9 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.0-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for philiprehberger_mqtt_client-0.1.0.tar.gz
Algorithm Hash digest
SHA256 8aaa3655e823646dc5400bd0c098684a89e37148cf9704055be2bc3ce596499a
MD5 9c92681a03bb1d10d9c3f67f2e4af469
BLAKE2b-256 9ab7c142ecfb1132983d8b4eb4d77202dcef0ec0f3b85c4511d99b1982b882eb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for philiprehberger_mqtt_client-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5fa8ae3c32d980715680bfc8d2e51184300e7dbc2cc47a12c0bd4e08fffbd487
MD5 e2d1cc16fb5cf1a6cd4457a4ae7bd537
BLAKE2b-256 69d78569750cf8baeb5f18c4fb4b04790c4820fb398fdd4c6150d62a65fb0a54

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