Other meanings of CPython
Programming Languages
CPython is the reference implementation of the Python programming language, written in C and Python. It compiles Python source code into bytecode, which is then executed by its virtual machine. CPython is maintained by the Python Software Foundation and serves as the standard against which all other Python implementations (such as PyPy, Jython, and IronPython) are measured. Its name distinguishes it from these alternative implementations, emphasizing its C-based core and its role as the canonical interpreter.
CPython translates Python source code into an intermediate bytecode format, which is then executed by a stack-based virtual machine. This two-step process (compilation to bytecode, then interpretation) distinguishes CPython from purely interpreted languages and from just-in-time (JIT) compiled implementations like PyPy. The bytecode is cached in .pyc files to speed up subsequent executions.
The interpreter core, known as the evaluator loop or bytecode loop, is written in C and handles the execution of each bytecode instruction. CPython's memory management relies on reference counting augmented by a cyclic garbage collector to reclaim objects involved in reference cycles. The Global Interpreter Lock (GIL) serializes access to Python objects from multiple threads, simplifying memory management but limiting CPU-bound multithreading performance.
CPython is developed openly on GitHub, with proposals for major changes formalized as Python Enhancement Proposals (PEPs). The release cycle follows a predictable annual cadence, with each version undergoing alpha, beta, and release candidate phases before final release. The Python Software Foundation oversees the project, and a core team of committers with long-standing contributions manages the codebase.
Notable releases have introduced significant features: Python 2.0 (2000) added list comprehensions and garbage collection; Python 3.0 (2008) was a major, backward-incompatible overhaul; Python 3.6 (2016) introduced f-strings; and Python 3.11 (2022) delivered substantial performance improvements. Each release is supported with bug fixes for a limited period, typically 18 months for minor versions and five years for major ones.
CPython is often criticized for being slower than compiled languages like C or Java, but it has seen steady performance improvements. Python 3.11 introduced the 'adaptive' interpreter, which specializes bytecode based on runtime types, yielding speedups of 10–60% over previous versions. Python 3.12 further refined this with inline caching and a new bytecode format.
Despite these gains, CPython still lacks a JIT compiler. Projects like PyPy (which uses a tracing JIT) and Cython (which compiles Python-like code to C) exist to address performance needs. CPython's design prioritizes simplicity, portability, and ease of embedding over raw speed, making it the default choice for most Python applications.
CPython's standard library includes a hidden gem: the _testcapi module, used internally for testing the C API. The interpreter also supports a 'limited API' that allows extension modules to remain compatible across Python versions. CPython's source tree contains a 'Tools' directory with scripts for building, debugging, and profiling the interpreter itself.
Historically, CPython was the first Python implementation, created by Guido van Rossum in 1989. The name 'CPython' was coined later to distinguish it from alternative implementations. CPython's bytecode is not guaranteed to be stable across versions, and the interpreter includes a 'dev' mode that enables extra runtime checks. The GIL, often seen as a limitation, was originally introduced to simplify memory management and remains a topic of active research, with efforts like the 'nogil' project aiming to make it optional.
CPython is the default and most widely used Python interpreter, and its behavior defines the language's semantics.
Help improve the encyclopedia. Reports go straight to the site manager.