CPython#Unladen Swallow

{{short description|Python reference implementation}}

{{Distinguish|Cython}}

{{Multiple issues|

{{Cleanup rewrite|date=January 2020}}

{{Primary sources|date=November 2010}}

}}

{{Infobox software

| name = CPython

| logo = Python logo and wordmark.svg

| logo size =

| author = Guido van Rossum

| developer = Python core developers and the Python community, supported by the Python Software Foundation

| released = {{Start date and age|1994|01|26|df=yes}}

| latest release version = {{wikidata|property|edit|reference|P348}}

| latest release date = {{start date and age|{{wikidata|qualifier|P348|P577}}}}

| repo = https://github.com/python/cpython

| programming language = C, Python

| platform = 42 platforms; see {{section link||Distribution}}

| size =

| language = English

| genre = Python Programming Language Interpreter

| license = Python Software Foundation License

| website = {{URL|https://www.python.org/}}

}}

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.{{cite web |title=Initialization, Finalization, and Threads |publisher=Python v3.8.3 documentation |url=https://docs.python.org/3/c-api/init.html |access-date=2020-06-04}} 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 sub-interpreter in a single Python process and have been described as "threads with opt-in sharing".{{Cite web| title = A per-interpreter GIL| work=LWN| author= Jake Edge| date=August 15, 2023| access-date = 2024-01-13| url = https://lwn.net/Articles/941090/}}{{Cite web| title = PEP 684 – A Per-Interpreter GIL {{!}} peps.python.org| access-date = 2024-01-13| url = https://peps.python.org/pep-0684/}}

After several debates, a project was launched in 2023 to propose making the GIL optional from version 3.13 of Python,{{Cite web |title=PEP 703 – Making the Global Interpreter Lock Optional in CPython {{!}} peps.python.org |url=https://peps.python.org/pep-0703/ |access-date=2023-09-17 |website=peps.python.org |language=en}} which was released October 7, 2024, in Python 3.13.0.{{Cite web |title=PEP 719 – Python 3.13 Release Schedule {{!}} peps.python.org |url=https://peps.python.org/pep-0719/#schedule |access-date=2023-09-17 |website=peps.python.org}}{{Cite web |title=Python Release Python 3.13.0 |url=https://www.python.org/downloads/release/python-3130/ |access-date=2025-03-28 |website=Python.org |language=en}}

History

{{Main article|History of Python}}

{{section-stub|date=February 2025}}

In 2009, a Google sponsored branch named Unladen Swallow was created to incorporate a just-in-time compiler into CPython.{{cite web |title=PEP 3146 - Merging Unladen Swallow into CPython |last1=Winter |first1=Collin |last2=Yasskin |first2=Jeffrey |last3=Kleckner |first3=Reid |publisher=Python.org |date=2010-03-17 |url=https://peps.python.org/pep-3146/}}{{cite web |title=Unladen Swallow 2009Q1 |publisher=unladen-swallow, A faster implementation of Python |url=https://code.google.com/p/unladen-swallow/wiki/Release2009Q1 |access-date=19 October 2012}} Development ended in 2011 without it being merged into the main implementation,{{cite web |title=Unladen Swallow Retrospective |website=QINSB is not a Software Blog (qinsb.blogspot.com) |last=Kleckner |first=Reid |date=26 March 2011 |url=https://qinsb.blogspot.com/2011/03/unladen-swallow-retrospective.html}} though some of its code, such as improvements to the cPickle module, made it in.{{cite web |title=Issue 9410: Add Unladen Swallow's optimizations to Python 3's pickle. - Python tracker |website=bugs.python.org |url=https://bugs.python.org/issue9410 |access-date=2019-08-08}}

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.{{Cite web|title=PEP 659 – Specializing Adaptive Interpreter|author=Mark Shannon|date=April 13, 2021|url=https://peps.python.org/pep-0659/}} 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.{{Cite web|title=What's new in Python 3.11 § PEP 659: Specializing Adaptive Interpreter|url=https://docs.python.org/3/whatsnew/3.11.html#whatsnew311-pep659|author=Pablo Galindo Salgado}}

In 2024, an experimental Just-in-time compiler was merged into CPython’s main development branch. This early JIT sits on top of LLVM, aiming to speed up hot code paths. At the time of the merge, the compiler was still not included in CPython’s default build configurations and offered roughly equal performance to the SAI; one of the conditions for its full adoption was a performance increase of at least 5%.{{Cite web|title= PEP 744 {{subst:endash}} JIT Compilation|url=https://peps.python.org/pep-0744/|author1=Brandt Bucher|author2=Savannah Ostrowski|date=April 11, 2024|access-date=February 5, 2025}} It remains disabled by default, though users can enable it to experiment and see how Python might eventually rival other JIT’d languages.{{cite web |url=https://kritimyantra.com/blogs/whats-new-in-python-3-13-3-the-upcoming-3-14-a-beginners-guide |title=What’s New in Python 3.13.3 & the Upcoming 3.14—A Beginner’s Guide |access-date=2025-04-25 |language=en-US}}

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:{{cite web |title=PythonImplementations |url=https://wiki.python.org/moin/PythonImplementations |access-date=19 July 2012}}

; Unix-like:

{{columns-list|colwidth=30em|

}}

; Special and embedded:

{{columns-list|colwidth=30em|

}}

; Other:

{{columns-list|colwidth=30em|

}}

PEP 11{{cite web |title=PEP 11 -- Removing support for little used platforms |website=Python.org |url=https://peps.python.org/pep-0011/ |access-date=2019-08-08}} 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:

{{columns-list|colwidth=30em|

  • 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){{cite web |title=Irix still supported? |date=14 February 2009 |url=https://mail.python.org/pipermail/python-dev/2009-February/086111.html}}
  • 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:

{{columns-list|colwidth=30em|

  • Amiga: AmigaPython{{Cite web|url=http://www.monkeyhouse.eclipse.co.uk/amiga/python/|title=AmigaPython Home Page|website=www.monkeyhouse.eclipse.co.uk|accessdate=Feb 20, 2025}}
  • IBM i: iSeriesPython{{Cite web|url=https://www.iseriespython.com/|title=I | Series | Python|website=I | Series | Python|accessdate=Feb 20, 2025}}
  • DOS using DJGPP: PythonD{{Cite web|url=https://www.caddit.net/pythond/|title=PythonD 32bit Python for DOS and Windows|website=www.caddit.net|accessdate=Feb 20, 2025}}
  • MorphOS: Python 2 and 3http://yellowblue.free.fr/yiki/doku.php/en:dev:python:start Python 2 and 3
  • PlayStation Portable: Stackless Python for PSP{{Cite web|url=https://code.google.com/archive/p/pspstacklesspython|title=Google Code Archive - Long-term storage for Google Code Project Hosting.|website=code.google.com|accessdate=Feb 20, 2025}}
  • Symbian OS: Python for S60
  • Windows CE/Pocket PC: Python Windows CE port{{Cite web|url=https://sourceforge.net/projects/pythonce/|title=Python Windows CE port|date=Jan 22, 2018|website=SourceForge|accessdate=Feb 20, 2025}}
  • OpenVMS: Ports of Python 3.x are maintained by VSI{{cite web |title=Python |website=VSI |url=https://vmssoftware.com/products/python/ |access-date=2021-08-31}}

}}

=Enterprise Linux=

These Python versions are distributed with currently-supported enterprise Linux distributions.{{cite web |title=Support Life Cycles for Enterprise Linux Distributions |url=https://linuxlifecycle.com/ |access-date=2017-10-15 |url-status=dead |archive-url=https://web.archive.org/web/20220830033136/https://linuxlifecycle.com/ |archive-date=2022-08-30}} The support status of Python in the table refers to support from the Python core team, and not from the distribution maintainer.

class="wikitable sortable"

|+ Enterprise Linux

! Distribution version

! Distribution end-of-life

! colspan="2" | Python version

Ubuntu 22.04 LTS (Jammy Jellyfish)

|

|

| 3.10 [https://launchpad.net/ubuntu/jammy/+package/python3]

Ubuntu 20.04 LTS (Focal Fossa)

| 2030-04{{cite web |title=Ubuntu release cycle |website=Ubuntu |url=https://ubuntu.com/about/release-cycle |access-date=2021-01-18}}{{Update after|2021|04|23}}

|{{cite web |title=With Python 2 EOL'ed, Ubuntu 20.04 LTS Moves Along With Its Python 2 Removal - Phoronix |website=phoronix.com |url=https://www.phoronix.com/news/Python-2-EOL-Ubuntu-20.04 |access-date=2020-04-01}}

| {{Version|co|3.8}}{{cite web |title=Binary package "python3" in ubuntu focal |website=Launchpad.net |url=https://launchpad.net/ubuntu/focal/+package/python3}}{{Update after|2024|10}}

Ubuntu 18.04 LTS (Bionic Beaver)

| 2028-04{{cite web |title=Ubuntu 18.04 extended to 2028 |publisher=ServerWatch.com |date=2018-11-15 |url=https://www.serverwatch.com/server-news/canonical-extends-ubuntu-18.04-lts-linux-support-to-10-years.html |access-date=2019-09-09}}{{Update after|2028|04}}

| {{Version|o|2.7}}{{cite web |title=python-defaults package: Ubuntu |publisher=Canonical Ltd. |date=2018-06-08 |url=https://launchpad.net/ubuntu/+source/python-defaults |access-date=2018-06-08}}

| {{Version|o|3.6}}{{cite web |title=python3-defaults package: Ubuntu |publisher=Canonical Ltd. |date=2018-06-08 |url=https://launchpad.net/ubuntu/+source/python3-defaults |access-date=2018-06-08}}

Ubuntu 16.04 LTS (Xenial Xerus)

| 2021-04-30{{cite web |last=Science |first=Carnegie Mellon University School of Computer |title=Ubuntu 16.04 - End of Life in 2021 - SCS Computing Facilities - Carnegie Mellon University |website=computing.cs.cmu.edu |url=https://computing.cs.cmu.edu/news/2020/eol-ubuntu-1604 |access-date=2021-02-15}}{{Update after|2021|04|30}}

| {{Version|o|2.7}}

| {{Version|o|3.5}}

Debian 12

| 2028-06{{cite web |title=Debian 12 bookworm released |website=debian.org |url=https://www.debian.org/News/2023/20230610}}{{Update after|2026|06}}

|

| {{Version|co|3.11}}{{Update after|2025|10}}

Debian 11

| 2026-06{{cite web |title=Debian -- News -- Debian 11 "bullseye" released |website=debian.org |url=https://www.debian.org/News/2021/20210814.en.html |access-date=2022-01-04 |archive-date=2021-08-14 |archive-url=https://web.archive.org/web/20210814210911/https://www.debian.org/News/2021/20210814.en.html |url-status=dead }}{{Update after|2026|06}}

|

| {{Version|co|3.9}}{{Update after|2025|10}}

Debian 10

| 2024-06{{cite web |title=LTS - Debian Wiki |website=wiki.debian.org |url=https://wiki.debian.org/LTS |access-date=2021-02-15}}{{Update after|2024|06}}

| {{Version|o|2.7}}{{cite web |title=Debian -- Details of package python in buster |website=packages.debian.org |url=https://packages.debian.org/buster/python |access-date=2019-09-13}}

| {{Version|co|3.7}}{{cite web |title=Debian -- News -- Debian 10 "buster" released |website=debian.org |url=https://www.debian.org/News/2019/20190706.en.html |access-date=2019-08-09}}{{Update after|2023|06}}

Debian 9

| 2022-06-30{{cite web |title=Debian -- News -- Debian 8 Long Term Support reaching end-of-life |website=debian.org |url=https://www.debian.org/News/2020/20200709.en.html |access-date=2021-02-15}}{{Update after|2022|06|30}}

| {{Version|o|2.7}}{{cite web |title=DistroWatch.com: Debian |publisher=DistroWatch.com |date=2017-10-15 |url=https://distrowatch.com/table.php?distribution=debian |access-date=2017-10-15}}

| {{Version|o|3.5}}{{cite web |title=Debian -- Details of package python3 in stretch |url=https://packages.debian.org/stretch/python3 |access-date=2017-12-19}}

Red Hat Enterprise Linux 8

| 2029{{Update after|2029|04}}

| {{Version|o|2.7}}{{cite web |title=Python in RHEL 8 |website=Red Hat Developer Blog |language=en-US |date=2018-11-14 |url=https://developers.redhat.com/blog/2018/11/14/python-in-rhel-8/ |access-date=2019-05-10 |url-status=dead |archive-url=https://web.archive.org/web/20190510043548/https://developers.redhat.com/blog/2018/11/14/python-in-rhel-8/ |archive-date=2019-05-10}}

| {{Version|o|3.6}}

Red Hat Enterprise Linux 7

| 2024-11-30{{cite web |title=Red Hat Enterprise Linux Life Cycle |website=Red Hat Customer Portal |url=https://access.redhat.com/support/policy/updates/errata |access-date=2020-04-01}}{{Update after|2024|11|30}}

| {{Version|o|2.7}}{{cite web |title=DistroWatch.com: Red Hat Enterprise Linux |publisher=DistroWatch.com |date=2017-09-07 |url=https://distrowatch.com/table.php?distribution=redhat |access-date=2017-10-15}}

|

CentOS 8

| 2029-05-31{{Update after|2029|05|31}}

| {{Version|o|2.7}}

| {{Version|o|3.6}}

CentOS 7

| 2024-06-30{{Update after|2024|06|30}}

| {{Version|o|2.7}}{{cite web |title=DistroWatch.com: CentOS |publisher=DistroWatch.com |date=2017-09-14 |url=https://distrowatch.com/table.php?distribution=centos |access-date=2017-10-15}}

|

SUSE Linux Enterprise Server 15

| 2031-07-31{{Update after|2031|07|31}}

| {{Version|o|2.7}}{{cite web |title=Release Notes {{!}} SUSE Linux Enterprise Desktop/SUSE Linux Enterprise Workstation Extension 15 GA |website=suse.com |url=https://www.suse.com/releasenotes/x86_64/SUSE-SLED/15/index.html#Features.Other |access-date=2019-08-08}}

| {{Version|o|3.6}}

SUSE Linux Enterprise Server 12

| 2027-10-31{{Update after|2027|10|31}}

| {{Version|o|2.7}}{{cite web |title=DistroWatch.com: openSUSE |publisher=DistroWatch.com |date=2017-10-14 |url=https://distrowatch.com/table.php?distribution=opensuse |access-date=2017-10-15}}

|

SUSE Linux Enterprise Server 11

| 2022-03-31{{Update after|2022|03|31}}

| {{Version|o|2.7}}

|

class="sortbottom"

| colspan="4" | {{Version |l |show=011100}}

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.{{cite book |last=Martelli |first=Alex |author-link=Alex Martelli |title=Python in a Nutshell |publisher=O'Reilly |year=2006 |edition=2nd |isbn=978-0-596-10046-9 |pages=5–7}}

References

{{Reflist|30em}}

Further reading

  • {{cite book |last=Shaw |first=Anthony |title=CPython Internals: Your Guide to the Python 3 Interpreter |publisher=Real Python |isbn=9781775093343 |date=2021}}