How Python is Implemented

CPython, the reference Python implementation, is written in C. It compiles Python source to bytecode and runs that bytecode on a virtual machine implemented in C. Python the language is a specification, so other implementations exist: PyPy (in RPython), Jython (in Java), IronPython (in C#), and MicroPython (in C).

The language vs the implementation

The Python language is defined by a specification and a reference implementation, not by a single source language. When people ask what Python is "written in," they almost always mean CPython, because it is the interpreter nearly everyone runs. CPython's bytecode interpreter, object model, memory manager, and C API are written in C. The C standard library underneath gives Python its low-level system access, threading, and file I/O.

How CPython runs your code

CPython does not execute Python text directly. It first compiles each module to bytecode (cached as .pyc files) and then runs that bytecode in a loop written in C, the CPython virtual machine. A detail that comes from this design is the Global Interpreter Lock (GIL), a mechanism in the C interpreter that lets only one thread execute Python bytecode at a time; recent CPython releases have begun offering an experimental "free-threaded" build that removes it. The reference source lives at github.com/python/cpython.

Alternative Python implementations

ImplementationWritten inWhy use it
CPythonCThe reference interpreter and default runtime
PyPyRPythonJIT compilation, often several times faster on long-running code
JythonJavaRuns Python on the JVM with Java interop
IronPythonC#Runs Python on the .NET runtime
MicroPythonCA tiny Python for microcontrollers

Is Python self-hosting?

No. The standard interpreter, CPython, is written in C, not Python, so Python is not self-hosting the way Rust or Go are. PyPy comes closest: it is written in RPython, a restricted subset of Python designed to be analyzable and compilable to C.

History and influences

Python was created by Guido van Rossum, who began it at CWI in the Netherlands in 1989 and released it in 1991. Its readability and design come directly from the ABC language, where van Rossum had previously worked, with further influence from Modula-3, C, and Lisp. Python in turn influenced Ruby, CoffeeScript, Swift, and many others. See the Python page for the full, sourced relationship map.

View Python in Graph →