Files
awesome-python/website/data/category_intros/implementations.md
T
Vinta ChenandClaude 4d09bcb7ab docs: add Implementations category intro
The page had no guidance on when to run CPython vs MicroPython, Pyodide, Cython, or PyPy.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-09-27 02:43:48 +08:00

3.8 KiB

Unless you need MicroPython on a microcontroller or Pyodide in the browser, CPython is the Python implementation to run. Cython compiles your slow code to C.

How to choose:

  • Most projects: CPython
  • Microcontrollers and other constrained devices: MicroPython
  • Python in the browser or Node.js: Pyodide
  • Slow code to compile, or a C library to wrap: Cython
  • Long-running programs in pure Python: PyPy

CPython is the original and most-maintained implementation of Python, written in C, and new language features generally show up there first. Give each app its own virtual environment from venv, and install packages into it with pip.

MicroPython is a lean implementation of Python 3, optimized to run on microcontrollers and in constrained environments. It includes a small subset of the standard library, plus modules like machine for the hardware. Flash your board with firmware from the download page, then manage it from your computer with mpremote. mpremote mip install installs packages from micropython-lib by default, not PyPI. When RAM runs short, freeze the modules that rarely change into the firmware.

Pyodide is a port of CPython to WebAssembly that runs in the browser and Node.js. It installs any pure Python wheel from PyPI, and many packages with C extensions, like NumPy and pandas, have been ported for it. Install packages with micropip.install(), which its docs recommend for almost everything. In a web page, run Pyodide in a web worker, so long computations don't freeze your UI.

Cython isn't a separate interpreter: it translates Python code to C that runs inside CPython, to speed up slow code or wrap C libraries. Write your code in pure Python syntax to keep the file runnable by the plain interpreter, and use .pyx files for what that syntax can't express. The annotation report from cython -a shows where types help. Build your package with a build backend, and ship prebuilt wheels to your users.

PyPy is a replacement for CPython, and speed is the reason to use it. It works best on long-running programs that spend much of their time in Python code, not on short scripts. Code built on C extension modules is a poor fit, since they often run much slower on PyPy than on CPython. Packages installed for CPython aren't available to PyPy, so install them for PyPy in its own virtual environment with pypy -m pip.

Before you switch implementations or compile anything for speed, measure first to confirm the slowdown is real. Then profile to find the slow parts, and only optimize those.