Python MQTT libraries

Updated Nov 2026

Python MQTT libraries connect devices and services to an MQTT broker to publish and subscribe to messages on topics. A client either runs its own network loop in a thread or exposes the connection through asyncio. These libraries let IoT devices, home automation systems, and backend services exchange sensor data and commands.

Popularity

paho-mqtt has the most monthly downloads in this comparison, at 11.6M.

LibraryMonthly downloadsStarsLast releaseLicense
paho-mqtt
11.6M
2.4KNov 2026EPL-2.0 OR BSD-3-Clause
aiomqtt
1.6M
581Mar 2026BSD-3-Clause
awsiotsdk
1.0M
447Jul 2026Apache-2.0
gmqtt
189.3K
454Nov 2026MIT
aMQTT
92.8K
222Nov 2026MIT
AWSIoTPythonSDK
45.1K
688Oct 2026Apache-2.0
mqttools
3.3K
66Dec 2021MIT
Downloads: PyPI, last thirty days. Stars and releases: GitHub. Amber: no release in over a year.

Features compared

LibraryMQTT version fiveEmbedded brokerQoS level two
paho-mqttBuilt-inUnsupportedBuilt-in
aiomqttBuilt-inUnsupportedBuilt-in
awsiotsdkBuilt-inUnsupportedUnsupported
gmqttBuilt-inUnsupportedBuilt-in
aMQTTUnsupportedBuilt-inBuilt-in
AWSIoTPythonSDKUnsupportedUnsupportedUnsupported
mqttoolsBuilt-inBuilt-inUnsupported
Built-inNot supported

Libraries and code examples

Connects Python applications to MQTT brokers through callback-based publish and subscription APIs.

Downloads / mo
11.6M
Stars
2.4K
Last release
2.2.0
License
EPL-2.0 OR BSD-3-Clause

Strengths

  • Supports several MQTT protocol generations. Connect to brokers using the newer or older supported protocol versions.
  • Offers several network-loop integrations. Choose blocking, threaded, or external-event-loop integration for the application.

Limitations

  • Persistent sessions remain in memory. With clean_session=False, recreating the client loses its saved session state.
  • Accepted publishes can remain pending. Wait for completion before treating an accepted publish as sent.

Quickstart

From README.rst
$ python -m pip install paho-mqtt
import paho.mqtt.publish as publish
publish.single('paho/test/topic', 'hello', hostname='localhost')

paho-mqtt examples

From open-source projects on GitHub

Wraps stable Paho clients with awaitable MQTT operations and asynchronous context management.

Downloads / mo
1.6M
Stars
581
Last release
2.5.1
License
BSD-3-Clause

Strengths

  • Awaits publishing and subscriptions. Use async context management and consume messages through asynchronous iteration.
  • Raises exceptions for MQTT failures. Handle MQTT failures through MqttError in the application.

Limitations

  • Reconnection needs an application loop. Catch MqttError and re-enter the client context after a suitable delay.
  • Windows needs selector event loops. Use an event loop that supports add_reader on Windows.

Quickstart

From reconnection.html
$ python -m pip install aiomqtt
import asyncio
import aiomqtt
async def main():
    async with aiomqtt.Client('localhost') as client:
        await client.publish('temperature/outside', payload=28.4)
asyncio.run(main())

aiomqtt examples

From open-source projects on GitHub

Connects to AWS IoT through the AWS Common Runtime.

Downloads / mo
1.0M
Stars
447
Last release
1.31.0
License
Apache-2.0
$ python -m pip install awsiotsdk
from awsiot import mqtt_connection_builder
connection = mqtt_connection_builder.mtls_from_path(
    endpoint='YOUR_ENDPOINT', client_id='example',
    cert_filepath='device.pem.crt', pri_key_filepath='private.pem.key',
)
connection.connect().result()
connection.disconnect().result()

Provides an asyncio MQTT client with configurable reconnect behavior and protocol properties.

Downloads / mo
189.3K
Stars
454
Last release
0.10.0
License
MIT

Strengths

  • Connects through native asyncio. Await connection and disconnection while retaining MQTT event callbacks.
  • Configures reconnect attempts and delays. Set retry limits and backoff settings for lost connections.

Limitations

  • Reconnect attempts are unlimited initially. Set reconnect_retries when a disconnected client should eventually stop trying.
  • Older brokers can reject negotiation. Force the older protocol when a broker cannot parse the initial connection.

Quickstart

From README.md
$ python -m pip install gmqtt
import asyncio
from gmqtt import Client
async def main():
    client = Client('example')
    await client.connect('localhost')
    client.publish('example/topic', 'hello', qos=0)
    await client.disconnect()
asyncio.run(main())

gmqtt examples

From open-source projects on GitHub

Provides both an MQTT broker and a client implemented with Python asyncio.

Downloads / mo
92.8K
Stars
222
Last release
0.12.2
License
MIT

Strengths

  • Embeds a Python MQTT broker. Run a broker and client within an asyncio-based application.
  • Supports encrypted MQTT transports. Use TLS-protected TCP or secure WebSocket connections.

Limitations

  • Default broker allows anonymous clients. Replace the default anonymous plugin when the broker must authenticate its clients.

Quickstart

From client_publish.py
$ python -m pip install amqtt
import asyncio
from amqtt.client import MQTTClient
async def main():
    client = MQTTClient()
    await client.connect('mqtt://localhost/')
    await client.publish('example/topic', b'hello', qos=0)
    await client.disconnect()
asyncio.run(main())

AWSIoTPythonSDK

Connects Python applications to AWS IoT.

Downloads / mo
45.1K
Stars
688
Last release
1.6.2
License
Apache-2.0

Quickstart

From index.html
$ python -m pip install AWSIoTPythonSDK
from AWSIoTPythonSDK.MQTTLib import AWSIoTMQTTClient
client = AWSIoTMQTTClient('example')
client.configureEndpoint('YOUR_ENDPOINT', 8883)
client.configureCredentials('root-ca.pem', 'private.pem.key', 'device.pem.crt')
client.connect()
client.disconnect()

AWSIoTPythonSDK examples

From open-source projects on GitHub

Provides MQTT tools.

Downloads / mo
3.3K
Stars
66
Last release
0.50.0
License
MIT

Quickstart

From README.md
$ python -m pip install mqttools
import asyncio
import mqttools
async def publisher():
    async with mqttools.Client('localhost', 1883) as client:
        client.publish(mqttools.Message('/test/mqttools/foo', b'bar'))
asyncio.run(publisher())

FAQ

paho-mqtt suits most clients, with callbacks and threaded, blocking, or external network loops. aiomqtt suits asyncio applications. awsiotsdk suits devices that connect to AWS IoT.

paho-mqtt is an MQTT client class with callbacks and a choice of threaded, blocking, or external network loops. It stores session state only in memory.

aiomqtt is an asyncio MQTT client built on Paho MQTT. It opens connections as async context managers and delivers incoming messages through its messages property.

aMQTT includes an asyncio broker with configurable listeners and plugins for authentication and authorization.

For coding agents

Found your MQTT library? Help your agent use it.

Connect Exa so your coding agent can find the library’s documentation, check its API, and look up implementations while you build.

Run in your terminal

claude plugin install exa@claude-plugins-official