![]() | This article has multiple issues. Please helpimprove it or discuss these issues on thetalk page.(Learn how and when to remove these messages) (Learn how and when to remove this message)
|
![]() | |
Original author(s) | Guido van Rossum |
---|---|
Developer(s) | Python core developers and the Python community, supported by thePython Software Foundation |
Initial release | 26 January 1994; 31 years ago (1994-01-26) |
Stable release | |
Repository | https://github.com/python/cpython |
Written in | C,Python |
Platform | 42 platforms; see§ Distribution |
Available in | English |
Type | Python Programming Language Interpreter |
License | Python Software Foundation License |
Website | www |
CPython is thereference implementation of thePython programming language. Written inC and Python, CPython is the default and most widely used implementation of the Python language.
CPython can be defined as both aninterpreter and acompiler as it compiles Python code intobytecode before interpreting it. It has aforeign function interface with several languages, including C, in which one must explicitly writebindings in a language other than Python.
A particular feature of CPython is that it makes use of aglobal interpreter lock (GIL) such that for each CPython interpreterprocess, only one thread may be processingbytecode at a time.[2] This does not mean that there is no point inmultithreading; the most common multithreading scenario is wherethreads are mostly waiting on external processes to complete.
This can happen when multiple threads are servicing separate clients. One thread may be waiting for a client to reply, and another may be waiting for adatabase query to execute, while the third thread is actually processing Python code.
However, the GIL does mean that CPython is not suitable for processes that implement CPU-intensive algorithms in Python code that could potentially be distributed across multiple cores.
In real-world applications, situations where the GIL is a significant bottleneck are quite rare. This is because Python is an inherently slow language and is generally not used for CPU-intensive or time-sensitive operations. Python is typically used at the top level and calls functions in libraries to perform specialized tasks. These libraries are generally not written in Python, and Python code in another thread can be executed while a call to one of these underlying processes takes place. The non-Python library being called to perform the CPU-intensive task is not subject to the GIL and may concurrently execute many threads on multiple processors without restriction.
Concurrency of Python code can only be achieved with separate CPython interpreter processes managed by amultitasking operating system. This complicates communication betweenconcurrent Python processes, though themultiprocessing module mitigates this somewhat; it means that applications that really can benefit from concurrent Python-code execution can be implemented with limitedoverhead.
The presence of the GIL simplifies the implementation of CPython, and makes it easier to implement multi-threaded applications that do not benefit from concurrent Python code execution. However, without a GIL, multiprocessing apps must make sure all common code is thread safe.
Although many proposals have been made to eliminate the GIL, the general consensus has been that in most cases, the advantages of the GIL outweigh the disadvantages; in the few cases where the GIL is a bottleneck, the application should be built around the multiprocessing structure. To help allow more parallelism, an improvement was released in October 2023 to allow a separate GIL per subinterpreter in a single Python process and have been described as "threads with opt-in sharing".[3][4]
After several debates, a project was launched in 2023 to propose making the GIL optional from version 3.13 of Python,[5] which is scheduled for release in October 2024.[6]
![]() | This sectionneeds expansion. You can help byadding to it.(February 2025) |
In 2009, aGoogle sponsored branch namedUnladen Swallow was created to incorporate ajust-in-time compiler into CPython.[7][8] Development ended in 2011 without it being merged into the main implementation,[9] though some of its code, such as improvements to the cPickle module, made it in.[10][7]
In 2021, a "specializing adaptive interpreter" was proposed, which was measured to improve performance by 10-60% by specializing commonly executed instructions displaying apparenttype stability into faster, type specific instructions, and which could de-specialize instructions when necessary.[11] The SAI was first included in Python 3.11, which was measured to be 25% faster on average than Python 3.10 by the "pyperformance" benchmark suite.[12]
In 2024, an experimental Just-in-time compiler was merged into CPython's main development branch. At the time of the merge, the compiler was still not included in CPython's default build configurations, and it offered roughly equal performance to the SAI; one of the conditions for its full adoption was a performance increase of at least 5%.[13] As of February 2025, the compiler is still experimental.
Officially supported tier-1 platforms areLinux for 64-bit Intel using a GCC toolchain,macOS for 64-bit Intel and ARM, andMicrosoft Windows for 32- and 64-bit Intel. Official tier-2 support exists for Linux for 64-bit ARM, wasm32 (Web Assembly) with WASI runtime support, and Linux for 64-bit Intel using a clang toolchain. Official supported tier-3 systems include 64-bit ARM Windows, 64-bit iOS,Raspberry Pi OS (Linux for armv7 with hard float), Linux for 64-bit PowerPC in little-endian mode, and Linux fors390x.
More platforms have working implementations, including:[14]
PEP 11[15] lists platforms which are not supported in CPython by thePython Software Foundation. These platforms can still be supported by external ports. These ports include:
External ports not integrated to Python Software Foundation's official version of CPython, with links to its main development site, often include additional modules for platform-specific functionalities, like graphics and sound API for PSP and SMS and camera API for S60. These ports include:
These Python versions are distributed with currently-supported enterprise Linux distributions.[24] The support status of Python in the table refers to support from the Python core team, and not from the distribution maintainer.
Distribution version | Distributionend-of-life | Python version | |
---|---|---|---|
Ubuntu 22.04 LTS (Jammy Jellyfish) | 3.10[1] | ||
Ubuntu 20.04 LTS (Focal Fossa) | 2030-04[25][needs update] | [26] | Old version, still maintained: 3.8[27][needs update] |
Ubuntu 18.04 LTS (Bionic Beaver) | 2028-04[28] | Old version, not maintained: 2.7[29] | Old version, not maintained: 3.6[30] |
Ubuntu 16.04 LTS (Xenial Xerus) | 2021-04-30[31][needs update] | Old version, not maintained: 2.7[29] | Old version, not maintained: 3.5[30] |
Debian 12 | 2028-06[32] | Old version, still maintained: 3.11[32] | |
Debian 11 | 2026-06[33] | Old version, still maintained: 3.9[33] | |
Debian 10 | 2024-06[34][needs update] | Old version, not maintained: 2.7[35] | Old version, still maintained: 3.7[36][needs update] |
Debian 9 | 2022-06-30[37][needs update] | Old version, not maintained: 2.7[38] | Old version, not maintained: 3.5[39] |
Red Hat Enterprise Linux 8 | 2029 | Old version, not maintained: 2.7[40] | Old version, not maintained: 3.6 |
Red Hat Enterprise Linux 7 | 2024-11-30[41][needs update] | Old version, not maintained: 2.7[42] | |
CentOS 8 | 2029-05-31 | Old version, not maintained: 2.7 | Old version, not maintained: 3.6 |
CentOS 7 | 2024-06-30[needs update] | Old version, not maintained: 2.7[43] | |
SUSE Linux Enterprise Server 15 | 2031-07-31 | Old version, not maintained: 2.7[44] | Old version, not maintained: 3.6 |
SUSE Linux Enterprise Server 12 | 2027-10-31 | Old version, not maintained: 2.7[45] | |
SUSE Linux Enterprise Server 11 | 2022-03-31[needs update] | Old version, not maintained: 2.7[45] | |
Legend: Old version, not maintained Old version, still maintained Latest version Latest preview version Future version |
CPython is one of several "production-quality"Python implementations including:Jython, written inJava for theJava virtual machine (JVM);PyPy, written inRPython and translated into C; andIronPython, written inC# for theCommon Language Infrastructure. There are also several experimental implementations.[46]