CPython
By Python Software Foundation
CPython is the reference implementation of the Python programming language, written primarily in C, that compiles Python source code into bytecode and executes it on a stack-based virtual machine. org and used by default on most systems,…
Definition
CPython is the reference implementation of the Python programming language, written primarily in C, that compiles Python source code into bytecode and executes it on a stack-based virtual machine. It is the version of Python distributed from python.org and used by default on most systems, and it defines the de facto behavior that other Python implementations aim to match, from its standard library to the exact semantics of its built-in types.
Overview
CPython is the original and most widely used implementation of Python, existing since the language's creation as the program that turns `.py` source files into running behavior. Because most developers who say "Python" mean this specific implementation, CPython's design choices, including its C-extension API and reference-counted memory model, have become inseparable from what the language is understood to be in practice. Mechanically, CPython works in two stages: a compiler translates source code into a compact bytecode representation stored in `.pyc` files, and then a bytecode interpreter, a large loop written in C, executes those instructions one at a time. Memory management relies on reference counting supplemented by a cyclic garbage collector for reference cycles, and concurrency within a single process is constrained by the Global Interpreter Lock, which allows only one thread to execute Python bytecode at a time even on multi-core machines. This lock simplifies memory safety internally but is the single most discussed limitation of the implementation. CPython differs from alternative implementations such as PyPy, which uses just-in-time compilation for much faster execution of long-running pure-Python code, and from Jython or IronPython, which target the JVM and .NET runtimes respectively. CPython's advantage is not raw speed but universal compatibility: nearly every third-party package, especially those with C extensions like NumPy, is built and tested first against CPython, making it the safest default choice. In practice, CPython is what runs when a developer types `python` or `python3` in a terminal, powers the vast majority of production Python deployments, web servers, and data science notebooks, and serves as the platform the Python Enhancement Proposal process targets when defining new language features. Extension authors write modules in C using CPython's specific C-API, which ties much of the packaging ecosystem to this implementation, and build tools like pip and wheel packaging formats are built assuming CPython's binary interface as the common target. Limitations include the Global Interpreter Lock's ceiling on CPU-bound multithreaded performance, which pushes parallel workloads toward multiprocessing or native extensions instead, and generally slower raw execution speed than compiled languages or JIT-based interpreters for tight numerical loops. Startup and memory overhead also tend to be higher than lighter, purpose-built interpreters for simple scripting tasks. Projects with an interpreter-bound hot path sometimes swap in PyPy or rewrite the hot section in C or Rust, while everything else continues to rely on CPython for its stability, documentation, and near-universal ecosystem compatibility across operating systems and hosting providers.
Key Features
- Reference implementation that defines Python's practical, de facto behavior
- Compiles source code to bytecode before interpretation for repeated runs
- Global Interpreter Lock serializes bytecode execution across threads
- Reference-counted memory management with a supplementary cyclic garbage collector
- C-API enables writing high-performance extension modules in C
- Ships as the default python.org distribution on most platforms
- Backward-compatible bytecode versioning tied to each minor release
- Broadest third-party package compatibility of any Python implementation