Install & Compatibility
Where this runs
tested against v0.7.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.242s · 18MB
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 1.5s · import 0.202s · 19MB
16MB installed
● package 16MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
Client
✓ from gmqtt import Client
Main class for creating MQTT clients.
Message
✓ from gmqtt import Message
Represents an MQTT message.
Basic connect, subscribe, publish with authentication.
import asyncio
import os
from gmqtt import Client as MQTTClient
async def main():
client = MQTTClient("client_id")
client.set_auth_credentials(os.environ.get('MQTT_USER', ''), os.environ.get('MQTT_PASS', ''))
# Set callbacks
def on_message(client, topic, payload, qos, properties):
print(f"Received: {topic} -> {payload}")
client.on_message = on_message
await client.connect('localhost', 1883)
client.subscribe('test/topic')
client.publish('test/topic', 'hello')
await asyncio.sleep(2)
await client.disconnect()
if __name__ == '__main__':
asyncio.run(main())
Errors
Common errors & fixes
TypeError: on_message() takes 4 positional arguments but 5 were given
Callback signature expects 4 arguments but gmqtt 0.7.0 passes 5 (added 'properties').
fixUpdate callback to `def on_message(client, topic, payload, qos, properties): ...`.
AttributeError: 'Client' object has no attribute '_on_connect'
Trying to monkey-patch internal attribute; gmqtt uses public callback `on_connect` with underscore prefix removed.
fixUse `client.on_connect = lambda client, flags, rc, properties: ...` (5 args).
ModuleNotFoundError: No module named 'gmqtt'
Not installed or installed in a different environment.
fixRun `pip install gmqtt` in the correct Python environment.
Upgrade
Version history
0.7.0latest on PyPI · released Nov 22, 2024
Audit
Dependencies
No dependency data recorded yet.