CPython

term

programming

Kept in this browser · My desk

The canonical implementation of Python, written in C and distributed on python.org, where new language features generally appear first.

It compiles source code to bytecode, cached in .pyc files and not stable between releases, and runs that bytecode on its virtual machine. Its global interpreter lock lets only one thread run Python bytecode at a time but is always released during input and output (I/O), so threads still help a script that waits on sockets. Python 3.13 added an experimental build without the lock, and 3.14 made that free-threaded build officially supported but optional. The language reference also names PyPy, Jython and IronPython as other implementations.

Python is a language described by a reference manual, and CPython is the program that most people mean when they say they ran it. The documentation's glossary calls CPython the canonical implementation of the Python programming language, as distributed on python.org, and says the name is used when it is necessary to distinguish it from others such as Jython or IronPython. The language reference describes it as the original and most-maintained implementation, written in C, where new language features generally appear first, and admits that CPython is the one implementation in widespread use, so its quirks are worth mentioning where it imposes limits. The alternatives the reference lists show the range: Jython is implemented in Java; Python for .NET actually embeds CPython; IronPython, created by Jim Hugunin, who also created Jython, compiles Python to .NET assemblies; and PyPy is written in Python itself and has a just-in-time compiler.

Its history is the history of the language. The documentation's licence page records that Guido van Rossum created Python in the early 1990s at Stichting Mathematisch Centrum (CWI) in the Netherlands as a successor to a language called ABC; in 1995 he continued at the Corporation for National Research Initiatives (CNRI) in Reston, Virginia; in May 2000 the core team moved to BeOpen.com as BeOpen PythonLabs and in October to Digital Creations, later Zope Corporation; and in 2001 the Python Software Foundation (PSF) was formed, a non-profit created to own Python-related intellectual property. Releases 0.9.0 to 1.2, from 1991 to 1995, belonged to CWI. The PSF's copyright notice is part of the licence every release carries; changes to the language and the interpreter are proposed as PEPs (Python Enhancement Proposals), which the Steering Council accepts or rejects; and the Developer's Guide names a release manager for each feature release.

CPython does not interpret source text line by line. It compiles a module to bytecode, which the glossary calls the internal representation of a Python program in the CPython interpreter, caches it in .pyc files so that a second run can skip compilation, and executes it on a virtual machine; the dis module lists the instructions. The glossary is explicit that bytecode is not expected to work between different Python virtual machines, nor to be stable between Python releases, which is why a cache or a virtual environment belongs to one interpreter version. Memory is managed by reference counting: when an object's count drops to zero it is deallocated, sys.getrefcount() shows the number, and since PEP 683 some objects are immortal, their counts never modified, so they live until the interpreter exits. A cyclic garbage collector detects and breaks reference loops, and 3.14 made its collection incremental.

For most of its life CPython was a straightforward interpreter, and the last five years have changed that. PEP 659, written by Mark Shannon in April 2021, introduced a specializing adaptive interpreter, one that speculatively specializes instructions on the types and values it is operating on and adapts when they change, without generating machine code. Python 3.11, the first release with it, was between 10 and 60 per cent faster than 3.10, 1.25 times on average on the standard benchmark suite. PEP 744, by Brandt Bucher and Savannah Ostrowski, added an experimental just-in-time (JIT) compiler in 3.13 built on a technique called copy-and-patch. Python 3.14 added an optional interpreter that uses tail calls between small C functions instead of one large switch statement, 3 to 5 per cent faster with Clang 19 or newer on x86-64 and AArch64, and shipped the experimental JIT in the Windows and macOS binaries. In 3.15 the official Windows 64-bit binaries use the tail-calling interpreter, and the reworked JIT is 7 to 8 per cent faster than the standard interpreter on x86-64 Linux and 11 to 12 per cent faster than the tail-calling one on AArch64 macOS, with individual benchmarks ranging from a 15 per cent slowdown to more than double the speed.

The global interpreter lock (GIL) is the CPython detail with the most practical consequences. In the glossary's words it is the mechanism that assures that only one thread executes Python bytecode at a time; it simplifies the implementation by making the object model, including built-in types such as dict, implicitly safe against concurrent access, at the expense of much of the parallelism of multi-processor machines. Some extension modules release it for computationally intensive work such as compression or hashing, and it is always released during input and output. For network automation this is the decisive fact: a script that spends its time waiting on SSH (Secure Shell) sessions, HTTP (Hypertext Transfer Protocol) requests or SNMP (Simple Network Management Protocol) replies gets real concurrency from threads or asyncio, while a script that parses gigabytes of logs in pure Python does not, and has traditionally reached for multiple processes instead.

PEP 703, by Sam Gross, created in January 2023 and accepted on 24 October 2023, proposed a build of CPython without the GIL, configured with --disable-gil. Removing the lock safely required replacing a great deal of machinery: biased reference counting, immortalization and a limited form of deferred reference counting instead of plain reference counts, a small per-object lock, critical sections in the interpreter, and changes to the mimalloc allocator. The PEP measured an overhead of 5 to 6 per cent for single-threaded programs and 7 to 8 per cent for multi-threaded ones on two processor families, with biased reference counting the largest cost. The Steering Council accepted it with an explicit proviso: a gradual rollout that breaks as little as possible and can be rolled back, entirely if necessary. PEP 779, accepted on 16 June 2025, set the criteria for the second of three phases: phase I, from 3.13, was an explicitly experimental free-threaded build; phase II makes it officially supported but optional, with targets of no more than 15 per cent slower and 20 per cent more memory; phase III, making it the default, is undecided.

Python 3.14, released on 7 October 2025, entered phase II. Its release notes say the PEP 703 implementation was finished, the specializing interpreter was enabled in free-threaded mode, and the single-threaded penalty fell to roughly 5 to 10 per cent depending on platform and compiler; the current free-threading guide gives an average from about 1 per cent on macOS aarch64 to 8 per cent on x86-64 Linux, and warns that memory use is higher. The build announces itself: python -VV and sys.version say free-threading build, and sys._is_gil_enabled() reports whether the lock is actually off, because the GIL can be turned back on with the PYTHON_GIL environment variable or -X gil, and is re-enabled automatically, with a warning, when the process imports a C extension that does not declare support for free threading. Python 3.15, released on 9 October 2026, added a stable application binary interface for free-threaded builds, abi3t, so that extensions built against the stable ABI (application binary interface) can also run on free-threaded builds, and its official macOS binaries now install free-threading support by default.

On 12 November 2026 python.org offered 3.15.2 as the current release, and the Developer's Guide listed 3.15 and 3.14 in their bugfix phase (first released on 9 October 2026 and 7 October 2025), 3.13 and 3.12 in their security phase, with end of life in October 2029 and October 2028, and 3.16 in development for a first release on 6 October 2027. Two habits follow for anyone who runs CPython in production. Check which interpreter and build is really in use, since the installers can put a free-threaded build beside the default one, and an extension that re-enables the GIL removes the benefit with only a warning to show for it. And treat the interpreter like any other dependency with a support window: bytecode caches, virtual environments and compiled wheels are tied to a version, and a branch past its end of life gets no further fixes from CPython's developers.

Also known as: CPython interpreter, reference implementation of Python

Sources

← Back to C Back to the glossary