Generated by DeepSeek V3.2| CPython | |
|---|---|
| Name | CPython |
| Developer | Python Software Foundation |
| Released | 20 February 1991 |
| Latest release version | 3.13.0b1 |
| Latest release date | 28 May 2024 |
| Programming language | C and Python |
| Operating system | Cross-platform |
| Genre | Python interpreter |
| License | Python Software Foundation License |
| Website | https://www.python.org/ |
CPython is the reference implementation of the Python programming language, written primarily in the C language. As the original and most widely used interpreter, it executes Python code by compiling it to bytecode for its internal virtual machine. Governed by the Python Software Foundation, its development is steered by a core team including the language's creator, Guido van Rossum, and follows a public specification outlined in Python Enhancement Proposals.
CPython serves as the standard against which other Python implementations, such as PyPy, Jython, and IronPython, are measured. Its architecture is defined by a stack-based virtual machine that processes compiled bytecode, a design that balances dynamism with performance. The interpreter itself is a complex program that manages memory allocation through reference counting and a cyclic garbage collector, interfaces with the underlying operating system, and provides the extensive standard library that is a hallmark of Python. Its development is a collaborative, open-source effort primarily hosted on GitHub, with contributions from corporations like Microsoft, Google, and Meta Platforms.
The core of CPython is implemented in C, with some standard library modules written in Python itself. It translates Python source code into an intermediate representation known as bytecode, which is then executed by its interpreter loop. Key internal structures include the Global Interpreter Lock, which simplifies memory management by allowing only one native thread to execute Python bytecode at a time, and the Python object model, where every value is an object represented by a C structure. The build system historically used distutils and now primarily relies on setuptools and pip.
CPython development follows a rigorous, time-based schedule, with feature releases occurring annually. The process is managed through Python Enhancement Proposals, which are discussed and ratified by the core developers. Major versions, like the transition from Python 2 to Python 3, are infrequent and involve significant, backward-incompatible changes. Release management is overseen by a Release Manager, and builds are automatically tested on a farm of machines running various systems like Windows, Linux, and macOS. The end-of-life for version 2.7 was officially marked in January 2020.
The CPython runtime environment initializes the interpreter state and thread state, setting up essential components like the import system and the memory allocator. When executing a script, it compiles code to bytecode, often caching it in .pyc files within a `__pycache__` directory. The interpreter loop, a central piece of code in Python/ceval.c, fetches and executes bytecode instructions. It also manages call frames for functions and integrates with signal handling and system calls from the host operating system.
A primary strength of CPython is its ability to interface with code written in other languages through its C API, enabling the creation of extension modules and embedding the interpreter into larger applications. The Python/C API allows NumPy, SciPy, and Pandas to deliver high-performance numerical computations. For simpler foreign function interfaces, the standard library includes modules like ctypes and cffi. Furthermore, tools like SWIG and Cython can generate the necessary C code to bridge Python with libraries like the OpenGL API or the Qt framework.
While praised for its simplicity and robustness, CPython is not optimized for raw execution speed, a trade-off inherent in its dynamic, interpreted design. The Global Interpreter Lock can be a bottleneck for CPU-bound parallel tasks. Consequently, several alternative implementations have been created: PyPy uses a JIT compiler for significant speedups, Jython compiles to Java bytecode for the Java virtual machine, and IronPython targets the .NET Framework. For specific performance-critical sections, developers often use the Cython compiler or integrate libraries like NumPy that execute optimized C or Fortran code.
Category:Free software programmed in C Category:Python (programming language) implementations Category:1991 software