A FastAPI extension that provides MQTT client functionality with decorator-based callbacks and Pydantic configuration.
fastapi-mqtt is a FastAPI extension that adds MQTT client capabilities to web applications, allowing them to communicate with MQTT brokers for real-time messaging. It wraps the gmqtt library to provide an async MQTT 5.0 client with decorator-based event handling and Pydantic configuration. This solves the problem of integrating lightweight IoT messaging protocols into modern Python web services without manual client management.
Python developers building FastAPI applications that need to interact with IoT devices, sensors, or other MQTT-based systems for real-time data exchange.
Developers choose fastapi-mqtt for its seamless integration with FastAPI's async ecosystem, declarative decorator API that reduces boilerplate, and type-safe configuration using Pydantic, making MQTT client setup more maintainable and intuitive.
fastapi-mqtt is extension for MQTT protocol
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Uses decorators like @fast_mqtt.on_message() to define MQTT callbacks directly in FastAPI routes, reducing boilerplate and improving code organization as shown in the guide.
Employs Pydantic for the MQTTConfig class, ensuring connection settings are validated and providing IDE autocompletion support, as highlighted in the features.
Designed to work with FastAPI's async lifespan, allowing non-blocking message handling and seamless integration with other async endpoints, evidenced by the use of asynccontextmanager.
Built on gmqtt for full compatibility with MQTT 5.0 features, such as user properties and enhanced error handling, per the README's specification.
Requires running a separate MQTT broker like Mosquitto, adding infrastructure management and potential network latency, as testing relies on external brokers like 'test.mosquitto.org'.
Tightly bound to gmqtt, so any bugs or missing features in the underlying library are inherited without direct fixes, limiting flexibility for advanced use cases.
Integration with FastAPI's lifespan requires manual context managers, as shown in the guide, which can be confusing for developers new to async Python and adds initial overhead.