tb-paho-mqtt-client
raw JSON → 2.1.2 verified Mon Apr 27 auth: no python
A MQTT version 5.0/3.1.1 client class built on top of paho-mqtt. Version 2.1.2 (Python >=3.7). Active development.
pip install tb-paho-mqtt-client Common errors
error ModuleNotFoundError: No module named 'tb_paho_mqtt_client' ↓
cause Package not installed, or import path wrong.
fix
pip install tb-paho-mqtt-client, then import as
from tb_paho_mqtt_client import Client. error TypeError: __init__() got an unexpected keyword argument 'protocol' ↓
cause Using old v1.x API where protocol was not a parameter.
fix
Upgrade to v2.x and use Client(client_id=..., protocol=3).
error AttributeError: 'Client' object has no attribute 'loop_start' ↓
cause Incorrect import or using a different class.
fix
Ensure you are using
from tb_paho_mqtt_client import Client and not from paho.mqtt.client import Client. Warnings
gotcha Python package name differs from import name. The package is `tb-paho-mqtt-client` but import uses `tb_paho_mqtt_client` (underscores). ↓
fix Use `from tb_paho_mqtt_client import Client`.
breaking Version 2.x changed the public API significantly. Old code using version 1.x direct paho-mqtt wrappers may not work. ↓
fix Migrate to new Client class; see v2 migration guide.
deprecated MQTT v3.1 (protocol=2) is unsupported. Use MQTT v3.1.1 (protocol=3) or v5.0 (protocol=5). ↓
fix Set protocol=3 or 5 when creating Client.
Imports
- Client
from tb_paho_mqtt_client import Client - MQTTv311
from tb_paho_mqtt_client import Client
Quickstart
import os
from tb_paho_mqtt_client import Client
client = Client(client_id='test-client', protocol=3)
client.username_pw_set(
os.environ.get('MQTT_USER', ''),
os.environ.get('MQTT_PASS', '')
)
client.connect(
os.environ.get('MQTT_HOST', 'localhost'),
int(os.environ.get('MQTT_PORT', 1883))
)
client.loop_start()
client.publish('test/topic', 'Hello from tb-paho-mqtt-client')
client.loop_stop()
client.disconnect()