Before we get into Python code, we first need an MQTT client library for Python. At the start of this chapter in the Technical requirements section, we installed the Paho-MQTT client library, which was part of requirements.txt.
If you are new to MQTT and have not read the preceding section, Learning MQTT by example, I recommend stopping now and reading it first so you gain an understanding of MQTT concepts and terminology that will be used in the Python examples that follow.
The Paho-MQTT client library comes from the Eclipse Foundation, which also maintains the Mosquitto MQTT broker. In the Further reading section, you will find a link to the official Paho-MQTT Client Library API documentation. After completing this chapter, if you wish to deepen your understanding of this library and its capabilities, I recommend reading through the official documentation and the examples found therein.
The Python Paho-MQTT library...