# CPython

CPython is the reference implementation of the Python programming language. Written in C and Python, CPython is the default and most widely used implementation of the Python language.
CPython can be defined as both an interpreter and a compiler as it compiles Python code into bytecode before interpreting it. It has a foreign function interface with several languages, including C, in which one must explicitly write bindings in a language other than Python.

## Design

A particular feature of CPython is that it makes use of a global interpreter lock (GIL) such that for each CPython interpreter process, only one thread may be processing bytecode at a time. This does not mean that there is no point in multithreading; the most common multithreading scenario is where threads 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 a database 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 a multitasking operating system. This complicates communication between concurrent Python processes, though the multiprocessing module mitigates this somewhat; it means that applications that really can benefit from concurrent Python-code execution can be implemented with limited overhead.
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".
After several debates, a project was launched in 2023 to propose making the GIL optional from version 3.13 of Python, which is scheduled for release in October 2024.

## History

In 2009, a Google sponsored branch named Unladen Swallow was created to incorporate a just-in-time compiler into CPython. Development ended in 2011 without it being merged into the main implementation, though some of its code, such as improvements to the cPickle module, made it in.
In 2021, a "specializing adaptive interpreter" was proposed, which was measured to improve performance by 10-60% by specializing commonly executed instructions displaying apparent type stability into faster, type specific instructions, and which could de-specialize instructions when necessary. 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.
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%. As of February 2025, the compiler is still experimental.

## Distribution

Officially supported tier-1 platforms are Linux for 64-bit Intel using a GCC toolchain, macOS for 64-bit Intel and ARM, and Microsoft 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 for s390x.
More platforms have working implementations, including:

### Unix-like

* AIX
* BSD
* Darwin
* FreeBSD
* HP-UX
* illumos
* Linux
* macOS
* NetBSD
* OpenBSD
* Plan 9
* Solaris
* Tru64

### Special and embedded

* Android
* Apple iOS (support for outdated Python 3.6 and 2.7 available)
* BlackBerry 10
* GP2X
* iPodLinux
* Nintendo DS
* GameCube
* Symbian OS Series60
* Nokia 770 Internet Tablet
* Nokia N800
* Nokia N810
* Nokia N900
* Openmoko
* Palm OS
* PlayStation 2
* PlayStation 3 (FreeBSD)
* Psion
* QNX
* Sharp Zaurus
* Xbox/XBMC
* VxWorks

### Other

* AROS
* OS/390
* Windows 8 and later
* z/OS
PEP 11 lists platforms which are not supported in CPython by the Python Software Foundation. These platforms can still be supported by external ports. These ports include:
* AtheOS (unsupported since 2.6)
* BeOS (unsupported since 2.6)
* DOS (unsupported since 2.0)
* IRIX 4 (unsupported since 2.3)
* IRIX 5 and later (unsupported since 3.2, 3.7)
* Mac OS 9 (unsupported since 2.4)
* MINIX (unsupported since 2.3)
* OpenVMS (unsupported since 3.3)
* OS/2 (unsupported since 3.3)
* RISC OS (unsupported since 3.0)
* Windows: Generally, Windows versions continue to receive full tier-1 support for as long as they are still covered by Microsoft's extended support lifecycle policy. Once Microsoft's extended support period expires for an older version of Windows, the project will no longer support that version of Windows in the next major (X.Y.0) release of Python. However, bug fix releases (0.0.Z) for each release branch will retain support for all versions of Windows that were supported in the initial X.Y.0 release. Editions of Windows targeting embedded and IoT systems are considered outside the scope of Python's official support policy.
** Windows 8 (no official support in any major releases of Python since January 10, 2023)
** Windows 7 (no official support in any major releases of Python since January 14, 2020)
** Windows Vista (unsupported since 3.9)
** Windows XP (unsupported since 3.5)
** Windows 2000 (unsupported since 3.3)
** Windows 3.x (unsupported since 2.0)
** Windows 9x (unsupported since 2.6)
** Windows NT4 (unsupported since 2.6)
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:
* Amiga: AmigaPython
* IBM i: iSeriesPython
* DOS using DJGPP: PythonD
* MorphOS: Python 2 and 3
* PlayStation Portable: Stackless Python for PSP
* Symbian OS: Python for S60
* Windows CE/Pocket PC: Python Windows CE port
* OpenVMS: Ports of Python 3.x are maintained by VSI

### Enterprise Linux

These Python versions are distributed with currently-supported enterprise Linux distributions. The support status of Python in the table refers to support from the Python core team, and not from the distribution maintainer.
Enterprise Linux :
| Distribution version | Distribution end-of-life | Python version | Python version |
| Ubuntu 22.04 LTS (Jammy Jellyfish) | | | 3.10 |
| Ubuntu 20.04 LTS (Focal Fossa) | 2030-04 | | class="templateVersion co swatch-maintained" style="color: var(--color-base, #202122); " title="Old version, still maintained" data-sort-value="3.8" | Old version, still maintained: 3.8 |
| Ubuntu 18.04 LTS (Bionic Beaver) | 2028-04 | class="templateVersion co swatch-unsupported" style="color: var(--color-base, #202122); " title="Old version, not maintained" data-sort-value="2.7" | Old version, not maintained: 2.7 | class="templateVersion co swatch-unsupported" style="color: var(--color-base, #202122); " title="Old version, not maintained" data-sort-value="3.6" | Old version, not maintained: 3.6 |
| Ubuntu 16.04 LTS (Xenial Xerus) | 2021-04-30 | class="templateVersion co swatch-unsupported" style="color: var(--color-base, #202122); " title="Old version, not maintained" data-sort-value="2.7" | Old version, not maintained: 2.7 | class="templateVersion co swatch-unsupported" style="color: var(--color-base, #202122); " title="Old version, not maintained" data-sort-value="3.5" | Old version, not maintained: 3.5 |
| Debian 12 | 2028-06 | | class="templateVersion co swatch-maintained" style="color: var(--color-base, #202122); " title="Old version, still maintained" data-sort-value="3.11" | Old version, still maintained: 3.11 |
| Debian 11 | 2026-06 | | class="templateVersion co swatch-maintained" style="color: var(--color-base, #202122); " title="Old version, still maintained" data-sort-value="3.9" | Old version, still maintained: 3.9 |
| Debian 10 | 2024-06 | class="templateVersion co swatch-unsupported" style="color: var(--color-base, #202122); " title="Old version, not maintained" data-sort-value="2.7" | Old version, not maintained: 2.7 | class="templateVersion co swatch-maintained" style="color: var(--color-base, #202122); " title="Old version, still maintained" data-sort-value="3.7" | Old version, still maintained: 3.7 |
| Debian 9 | 2022-06-30 | class="templateVersion co swatch-unsupported" style="color: var(--color-base, #202122); " title="Old version, not maintained" data-sort-value="2.7" | Old version, not maintained: 2.7 | class="templateVersion co swatch-unsupported" style="color: var(--color-base, #202122); " title="Old version, not maintained" data-sort-value="3.5" | Old version, not maintained: 3.5 |
| Red Hat Enterprise Linux 8 | 2029 | class="templateVersion co swatch-unsupported" style="color: var(--color-base, #202122); " title="Old version, not maintained" data-sort-value="2.7" | Old version, not maintained: 2.7 | class="templateVersion co swatch-unsupported" style="color: var(--color-base, #202122); " title="Old version, not maintained" data-sort-value="3.6" | Old version, not maintained: 3.6 |
| Red Hat Enterprise Linux 7 | 2024-11-30 | class="templateVersion co swatch-unsupported" style="color: var(--color-base, #202122); " title="Old version, not maintained" data-sort-value="2.7" | Old version, not maintained: 2.7 | |
| CentOS 8 | 2029-05-31 | class="templateVersion co swatch-unsupported" style="color: var(--color-base, #202122); " title="Old version, not maintained" data-sort-value="2.7" | Old version, not maintained: 2.7 | class="templateVersion co swatch-unsupported" style="color: var(--color-base, #202122); " title="Old version, not maintained" data-sort-value="3.6" | Old version, not maintained: 3.6 |
| CentOS 7 | 2024-06-30 | class="templateVersion co swatch-unsupported" style="color: var(--color-base, #202122); " title="Old version, not maintained" data-sort-value="2.7" | Old version, not maintained: 2.7 | |
| SUSE Linux Enterprise Server 15 | 2031-07-31 | class="templateVersion co swatch-unsupported" style="color: var(--color-base, #202122); " title="Old version, not maintained" data-sort-value="2.7" | Old version, not maintained: 2.7 | class="templateVersion co swatch-unsupported" style="color: var(--color-base, #202122); " title="Old version, not maintained" data-sort-value="3.6" | Old version, not maintained: 3.6 |
| SUSE Linux Enterprise Server 12 | 2027-10-31 | class="templateVersion co swatch-unsupported" style="color: var(--color-base, #202122); " title="Old version, not maintained" data-sort-value="2.7" | Old version, not maintained: 2.7 | |
| SUSE Linux Enterprise Server 11 | 2022-03-31 | class="templateVersion co swatch-unsupported" style="color: var(--color-base, #202122); " title="Old version, not maintained" data-sort-value="2.7" | Old version, not maintained: 2.7 | |
| Legend:Old version, not maintainedOld version, still maintainedLatest versionLatest preview versionFuture version ||||

## Alternatives

CPython is one of several "production-quality" Python implementations including: Jython, written in Java for the Java virtual machine (JVM); PyPy, written in RPython and translated into C; and IronPython, written in C# for the Common Language Infrastructure. There are also several experimental implementations.