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.

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.3.tar.gz (4.2 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.3-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for philiprehberger_mqtt_client-0.1.3.tar.gz
Algorithm Hash digest
SHA256 90ca3d5de291fd515a592906fbfe90103c7781369139ab10a609cd53b700b05a
MD5 d6bdec8009f7d262bc871017cbe2f9ab
BLAKE2b-256 c6d544845c50a71d556e298b91feb206943917c5717e4780c9ee709c9c04fe53

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for philiprehberger_mqtt_client-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 fcdff77e512aa7cccb84c2012a6fedd298c02a9ec92cd9120a1048cd9208eadd
MD5 2da474c26b01fa5fb59f43a390803073
BLAKE2b-256 fce6302c3ef84d2930b0b592a79c63b462f00a3922c3795a3979a73bf238761b

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