Skip to main content

Simplified MQTT pub/sub wrapper with auto-reconnect

Project description

philiprehberger-mqtt-client

Tests PyPI version License

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


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

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for philiprehberger_mqtt_client-0.1.6.tar.gz
Algorithm Hash digest
SHA256 28e28f3b1ac41aac07a6b0effaa09de863e0f640d850782bcab3404e0782006b
MD5 5b9a02d9b318437dfc970791c169674c
BLAKE2b-256 5e73522ee148718688f9b3931ac857d57be78de70b2ddf90606658cb4417a281

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for philiprehberger_mqtt_client-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 8dd4a444087398985787742af0d7f10cb9110afbebfab2bbb73048aaf7c26fbf
MD5 478d6b782773c508ff69306824433d1a
BLAKE2b-256 1cc794c347eb3e2623c7ab35c3fc5ddc0b6be03e2bbf49fda2121c1a44ebf303

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