Skip to Content

MicroPython Libraries

MicroPython includes an optimized subset of the standard Python library along with specialized libraries designed to interact directly with microcontroller hardware and networking protocols. These libraries are usually prefixed with a “u” (e.g., ujson instead of json) to indicate they are optimized for resource-constrained environments, though many can be imported without the prefix for better compatibility with standard Python code.

The most commonly used libraries can be categorized into the following groups:

Core MicroPython Libraries

These libraries are essential for controlling the basic functions of a microcontroller and its connected peripherals. The machine library provides direct access to and control of hardware blocks like CPU, memory, timers, and buses. It is the foundation for most hardware projects.

Hardware Interface Libraries

These are used for networking and communication over WiFi, Bluetooth (BLE), and sockets. The network library is used to configure and control network connections, such as Wi-Fi on ESP32/ESP8266 boards or wired Ethernet.

Communication Protocol Libraries

These are used for data transfer over HTTP and MQTT and for working with the JSON data format. The ujson library is used for encoding and decoding of JSON data and is essential for exchanging data with web APIs and cloud platforms.

Sensor and Peripheral Libraries

These are used for reading data from some of the commonly used sensors.

Utility Libraries

These are used for common programming tasks such as arithmetic operations, random number generation, regular expressions, and so on.

External (User-Installed) Libraries

In addition to the built-in libraries, you can install additional libraries using the Thonny Package Manager for controlling external devices such as displays and servo motors.