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

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.4.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.4-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for philiprehberger_mqtt_client-0.1.4.tar.gz
Algorithm Hash digest
SHA256 a2d8ee0ea4f4f8718b755d210ca8eb0fefe65481d2bab49faeb7bea106fd09b5
MD5 094793d8401750f9a2c7dd9a736e3561
BLAKE2b-256 19b2a3eefa95354827e33e6b50d6b31e2aad665aba63824bf1d2dabf9e1d32db

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for philiprehberger_mqtt_client-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 0bab98a74dec7718721002f7ca2de7071f15761fd687753d608c6e92688410ef
MD5 ad1965fce1effc00361679dc7cf161d3
BLAKE2b-256 c3fbe30473a1c9af4c0c813e306c320aa8fd7942ccef6caa03c7f3107ac2dd79

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