ThingsBoard MQTT Python Client

raw JSON →
1.13.13 verified Mon Apr 27 auth: no python

Official ThingsBoard Python client SDK for MQTT-based device communication. Current version 1.13.13, actively maintained with monthly releases. Supports telemetry upload, attribute publishing, RPC handling, and provisioning for ThingsBoard IoT platform.

pip install tb-mqtt-client
error ImportError: No module named tb_device_mqtt
cause Installed wrong package or imported incorrect module name.
fix
Install with 'pip install tb-mqtt-client' and import using 'from tb_device_mqtt import TBDeviceMqttClient'.
error tb_device_mqtt.TBDeviceMqttClient: connect() takes 1 positional argument but 2 were given
cause Passing host and port as positional arguments in connect() method; new versions require host in constructor.
fix
Create client with host parameter: TBDeviceMqttClient('host', port=1883) and call client.connect() without arguments.
breaking TBDeviceMqttClient no longer supports direct host passing in constructor with TLS; use TBDeviceMqttClient(host, port=8883, tls=True) or set tls=True explicitly.
fix Use keyword argument tls=True when connecting to TLS endpoints.
deprecated The 'quality_of_service' parameter in send_telemetry is deprecated and will be removed in a future version.
fix Remove qos parameter from send_telemetry calls.
gotcha The client does not auto-reconnect by default; connection loss leads to silent failures.
fix Implement manual reconnection logic using on_disconnect callback or enable automatic reconnect via paho-mqtt options.

Connects to ThingsBoard, sends telemetry using access token authentication.

from tb_device_mqtt import TBDeviceMqttClient
import os

client = TBDeviceMqttClient("demo.thingsboard.io", username=os.environ.get('TB_ACCESS_TOKEN', ''))
client.connect()
client.send_telemetry({"temperature": 22.5})
client.disconnect()