What does it do?
paho-mqtt implements MQTT, a lightweight messaging protocol specifically designed for devices with weak connections and limited power, like sensors, smart home gadgets, and other Internet of Things devices. It works like a bulletin board system: a device publishes a small update to a named board, like temperature-readings, and any number of interested listeners can subscribe to that board and get notified instantly, without the publisher needing to know who’s listening. This publish-and-subscribe pattern makes MQTT extremely efficient for battery-powered devices sending small, frequent updates over unreliable networks. The library gives Python programs an easy way to both publish and subscribe to these message boards.
See it in action
This connects to a messaging hub over the internet, listens for temperature updates on a named channel, and prints each update as it arrives.
import paho.mqtt.client as mqtt
def on_message(client, userdata, msg):
print(msg.topic, msg.payload)
client = mqtt.Client()
client.on_message = on_message
client.connect("mqtt.example.com", 1883)
client.subscribe("home/temperature")
client.loop_forever()
Why would a non-developer care?
Every smart thermostat, connected doorbell, or industrial sensor sending data to an app on your phone is very likely using MQTT or something like it, precisely because it was built to work reliably even over weak, spotty connections. It’s the quiet plumbing behind a lot of the smart in smart home devices.
Real-world examples
MQTT was originally developed by IBM in 1999 for monitoring oil pipelines over unreliable satellite links, and Facebook Messenger famously used MQTT for years to deliver messages efficiently to mobile devices with limited battery and bandwidth. paho-mqtt, maintained under the Eclipse Foundation, is one of the most widely used Python clients for the protocol across IoT projects big and small.
Who uses it
Developers building Internet of Things projects, from hobbyist smart-home setups to industrial sensor networks, who need lightweight, reliable messaging.
How it compares to alternatives
Compared to heavier messaging systems like pika’s AMQP or gRPC’s RPC model, MQTT is intentionally minimal and built for constrained devices and unreliable networks, trading features for extremely low overhead, which is exactly the trade-off IoT hardware usually needs.
Fun fact
MQTT’s origins tracing back to monitoring remote oil pipelines explains a lot about why the protocol is so obsessively optimized for tiny, infrequent, unreliable connections.