{"id":23797,"library":"gmqtt","title":"gmqtt","description":"Asynchronous MQTT client for Python (3.5+) using asyncio. Supports QoS 0/1/2, TLS, WebSocket, and MQTT v5.0. Maintained by Wialon. Current version 0.7.0, with irregular releases (last in 2023).","status":"active","version":"0.7.0","language":"python","source_language":"en","source_url":"https://github.com/wialon/gmqtt","tags":["mqtt","asyncio","iot","messaging"],"install":[{"cmd":"pip install gmqtt","lang":"bash","label":"Install with pip"}],"dependencies":[],"imports":[{"note":"Main class for creating MQTT clients.","symbol":"Client","correct":"from gmqtt import Client"},{"note":"Represents an MQTT message.","symbol":"Message","correct":"from gmqtt import Message"}],"quickstart":{"code":"import asyncio\nimport os\nfrom gmqtt import Client as MQTTClient\n\nasync def main():\n    client = MQTTClient(\"client_id\")\n    client.set_auth_credentials(os.environ.get('MQTT_USER', ''), os.environ.get('MQTT_PASS', ''))\n    # Set callbacks\n    def on_message(client, topic, payload, qos, properties):\n        print(f\"Received: {topic} -> {payload}\")\n    client.on_message = on_message\n    await client.connect('localhost', 1883)\n    client.subscribe('test/topic')\n    client.publish('test/topic', 'hello')\n    await asyncio.sleep(2)\n    await client.disconnect()\n\nif __name__ == '__main__':\n    asyncio.run(main())","lang":"python","description":"Basic connect, subscribe, publish with authentication."},"warnings":[{"fix":"Update callback to accept 5 arguments: client, topic, payload, qos, properties.","message":"In version 0.7.0, `on_message` signature changed: new parameter `properties` added. Old code with `client.on_message = on_message(client, topic, payload, qos)` will raise TypeError.","severity":"breaking","affected_versions":">=0.7.0"},{"fix":"Always call `set_auth_credentials(username, password)` if broker expects authentication.","message":"Using `Client` class without calling `set_auth_credentials` when broker requires auth will silently disconnect. No error is raised until publish/subscribe fails.","severity":"gotcha","affected_versions":"all"},{"fix":"Use unique client IDs or set `clean_session=True` when connecting.","message":"Connecting with the same `client_id` to a broker that has session present can cause the previous session to be taken over. The client might not receive messages until reconnection completes.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Update callback to `def on_message(client, topic, payload, qos, properties): ...`.","cause":"Callback signature expects 4 arguments but gmqtt 0.7.0 passes 5 (added 'properties').","error":"TypeError: on_message() takes 4 positional arguments but 5 were given"},{"fix":"Use `client.on_connect = lambda client, flags, rc, properties: ...` (5 args).","cause":"Trying to monkey-patch internal attribute; gmqtt uses public callback `on_connect` with underscore prefix removed.","error":"AttributeError: 'Client' object has no attribute '_on_connect'"},{"fix":"Run `pip install gmqtt` in the correct Python environment.","cause":"Not installed or installed in a different environment.","error":"ModuleNotFoundError: No module named 'gmqtt'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}