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)

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

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for philiprehberger_mqtt_client-0.1.7.tar.gz
Algorithm Hash digest
SHA256 12b758f54711b1c7e2811cac2c3283abb30efa39c4aa5b20aaf59fd82ebd81ac
MD5 ecea1aa6faa2c66505d7f59d8674437d
BLAKE2b-256 649ad8bc221addf5ec793793119c6bc7d1973db20695f0a2e933e4e304744c13

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for philiprehberger_mqtt_client-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 fe0f0738e4ae7445a5985a8370f514cd20c02c0c5728c5ea6ebfaf54bde78d46
MD5 b14a0cf1ffcc0abc05b8634fb223790f
BLAKE2b-256 d68ac31fe7323c8807282fc0207d90a8a1fb9d4f44516b86f046bcd2d8da5c82

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