MicroPython
By the MicroPython project
MicroPython is a compact, efficient implementation of the Python 3 programming language designed to run on microcontrollers and other resource-constrained embedded hardware. It implements a substantial subset of the standard Python…
Definition
MicroPython is a compact, efficient implementation of the Python 3 programming language designed to run on microcontrollers and other resource-constrained embedded hardware. It implements a substantial subset of the standard Python language and library, along with modules for direct hardware interaction, letting developers write embedded firmware in Python instead of C or C++, iterating on hardware code interactively over a live device connection.
Overview
MicroPython exists to bring Python's readability and rapid-development style to embedded hardware, a domain historically dominated by C and C++ because of the tight memory and processing constraints of microcontrollers. Standard CPython assumes resources—memory, a filesystem, an operating system—that a microcontroller with kilobytes of RAM simply does not have, so MicroPython is a separate implementation built from the ground up to fit within those constraints while preserving Python 3 syntax and much of its standard behavior. Mechanically, MicroPython includes its own compact bytecode compiler and virtual machine, written in C, optimized to run with a memory footprint often under a few hundred kilobytes, small enough to fit on many ARM Cortex-M and similar microcontrollers. It supplies hardware-focused modules such as `machine` for GPIO pins, timers, and peripherals, replacing operating-system-dependent standard library modules that don't make sense on bare hardware with embedded-appropriate equivalents, and it exposes an interactive REPL directly over a serial connection to the device. MicroPython differs from CPython not merely in size but in scope: it deliberately omits or slims down parts of the standard library that assume an underlying OS or abundant memory, and it adds embedded-specific APIs that have no CPython equivalent. It differs from CircuitPython, a fork maintained by Adafruit, mainly in library ecosystem and hardware focus—CircuitPython prioritizes a beginner-friendly experience and broad support for Adafruit's own hardware boards and sensor libraries, while MicroPython supports a wider range of third-party microcontroller boards with a slightly more configurable, less opinionated core. In practice, MicroPython is used for rapid prototyping of embedded projects, educational electronics kits, and production firmware on boards like the ESP32 and Raspberry Pi Pico, where developers write and iterate on hardware-interaction code directly, often over a REPL connected to the device, without needing a full C toolchain rebuild-and-flash cycle for every change. This tight feedback loop is one of its biggest practical advantages over compiled embedded firmware. The trade-offs against C/C++ firmware include somewhat higher memory overhead and slower execution for CPU-intensive tasks, since MicroPython is still an interpreted language even in its compact form, and it is not suitable for the most severely memory-constrained microcontrollers with only a few kilobytes of RAM. For projects requiring hard real-time guarantees or the smallest possible firmware footprint, C remains the more appropriate choice, with MicroPython reserved for prototyping, education, or less timing-critical logic where developer iteration speed and ease of debugging matter more than squeezing out maximum raw execution performance.
Key Features
- Implements a substantial subset of Python 3 for microcontrollers
- Runs with a compact bytecode compiler and virtual machine written in C
- Provides hardware-access modules like machine for GPIO and peripherals
- Supports an interactive REPL for live device programming
- Targets ARM Cortex-M and similar resource-constrained processors
- Fits within a memory footprint of a few hundred kilobytes
- Supports popular boards including the ESP32 and Raspberry Pi Pico
- Enables rapid prototyping without a full C toolchain rebuild cycle