Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Python (programming language)
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Implementations== {{See also|List of Python software#Python implementations}} ===Reference implementation=== [[CPython]] is the [[reference implementation]] of Python. This implementation is written in C, meeting the [[C11 (C standard revision)|C11]] standard<ref>{{Cite web |title=PEP 7 β Style Guide for C Code {{!}} peps.python.org |url=https://peps.python.org/pep-0007/ |access-date=2022-04-28 |website=peps.python.org |archive-date=24 April 2022 |archive-url=https://web.archive.org/web/20220424202827/https://peps.python.org/pep-0007/ |url-status=live}}</ref> (since version 3.11, older versions use the [[C89 (C version)|C89]] standard with several select [[C99]] features), but third-party extensions are not limited to older C versionsβe.g., they can be implemented using C11 or C++.<ref>{{Cite web|title=4. Building C and C++ Extensions β Python 3.9.2 documentation|url=https://docs.python.org/3/extending/building.html|access-date=2021-03-01|website=docs.python.org|archive-date=3 March 2021|archive-url=https://web.archive.org/web/20210303002519/https://docs.python.org/3/extending/building.html|url-status=live}}</ref><ref name="AutoNT-66"/> CPython [[compiler|compiles]] Python programs into an intermediate [[bytecode]],<ref name="AutoNT-67"/> which is then executed by a [[virtual machine]].<ref name="AutoNT-68"/> CPython is distributed with a large standard library written in a combination of C and native Python. CPython is available for many platforms, including Windows and most modern [[Unix-like]] systems, including macOS (and [[Apple M1]] Macs, since Python 3.9.1, using an experimental installer). <!-- "Windows Vista support dropped in Python 3.7" -->Starting with Python 3.9, the Python installer intentionally fails to install on [[Windows 7]] and 8<!-- but not 8.1? -->;<ref>{{Cite web |title=Changelog β Python 3.9.0 documentation |url=https://docs.python.org/release/3.9.0/whatsnew/changelog.html#changelog |url-status=live |archive-url=https://web.archive.org/web/20210207001142/https://docs.python.org/release/3.9.0/whatsnew/changelog.html#changelog |archive-date=7 February 2021 |access-date=2021-02-08 |website=docs.python.org}}</ref><ref>{{Cite web |title=Download Python |url=https://www.python.org/downloads/release/python-391 |url-status=live |archive-url=https://web.archive.org/web/20201208045225/https://www.python.org/downloads/release/python-391/ |archive-date=8 December 2020 |access-date=2020-12-13 |website=Python.org |language=en}}</ref> [[Windows XP]] was supported until Python 3.5<!--"Windows XP support dropped in Python 3.5"-->, with unofficial support for [[OpenVMS|VMS]].<!--"Put online a new version of Python 3.10.0a (IA64only)"--><ref>{{Cite web|title=history [vmspython]|url=https://www.vmspython.org/doku.php?id=history|access-date=2020-12-04|website=www.vmspython.org|archive-date=2 December 2020|archive-url=https://web.archive.org/web/20201202194743/https://www.vmspython.org/doku.php?id=history|url-status=live}}</ref> Platform portability was one of Python's earliest priorities.<ref name="AutoNT-69" /> During development of Python 1 and 2, even [[OS/2]] and [[Solaris (operating system)|Solaris]] were supported;<!-- Also python-3.2.2 at http://unixpackages.com/packages/package-list --><ref>{{Cite web|title=Download Python for Other Platforms|url=https://www.python.org/download/other/|access-date=2020-12-04|website=Python.org|language=en|archive-date=27 November 2020|archive-url=https://web.archive.org/web/20201127015815/https://www.python.org/download/other/|url-status=live}}</ref> since that time, support has been dropped for many platforms.<!-- Starting with CPython 3.7.0, *nix platforms are expected to provide at least one of C.UTF-8 (full locale), C.utf8 (full locale) or UTF-8 (LC_CTYPE-only locale) as an alternative to the legacy C locale. --> All current Python versions (since 3.7) support only operating systems that feature multithreading<!-- (then in 3.7 removing support for [[IRIX]]; and before many other operating systems such as [[OS/2]] and [[VMS]]) -->, by now supporting not nearly as many operating systems (dropping many outdated) than in the past. ===Other implementations=== All alternative implementations have at least slightly different semantic. For example, an alternative may include unordered dictionaries<!-- like with Codon; also PyPy? Cython? -->, in contrast to other current Python versions. As another example in the larger Python ecosystem, PyPy does not support the full C Python API. Alternative implementations include the following: * [[PyPy]] is a fast, compliant interpreter of Python 2.7 and <!-- 3.8 (both are outdated CPython versions) --> 3.10.<ref name="AutoNT-70"/><ref>{{Cite web|last=Team|first=The PyPy|date=2019-12-28|title=Download and Install|url=https://www.pypy.org/download.html|access-date=2022-01-08|website=PyPy|language=en|archive-date=8 January 2022|archive-url=https://web.archive.org/web/20220108212951/https://www.pypy.org/download.html|url-status=live}}</ref> PyPy's [[just-in-time compiler]] often improves speed significantly relative to CPython, but PyPy does not support some libraries written in C.<ref name="AutoNT-71"/> PyPy offers support for the [[RISC-V]] instruction-set architecture, for example. * Codon is an implentation with an [[ahead-of-time compilation|ahead-of-time (AOT) compiler]], which compiles a statically-typed Python-like language whose "syntax and semantics are nearly identical to Python's, there are some notable differences"<ref>{{Cite web |title=Codon: Differences with Python |url=https://docs.exaloop.io/codon/general/differences |url-status=live |archive-url=https://web.archive.org/web/20230525002540/https://docs.exaloop.io/codon/general/differences |archive-date=2023-05-25 |access-date=2023-08-28}}</ref> For example, Codon uses 64-bit machine integers for speed, not arbitrarily as with Python; Codon developers claim that speedups over CPython are usually on the order of ten to a hundred times. Codon compiles to machine code (via [[LLVM]]) and supports native multithreading.<ref>{{Cite web |last=Lawson |first=Loraine |date=2023-03-14 |title=MIT-Created Compiler Speeds up Python Code |url=https://thenewstack.io/mit-created-compiler-speeds-up-python-code/ |url-status=live |archive-url=https://web.archive.org/web/20230406054200/https://thenewstack.io/mit-created-compiler-speeds-up-python-code/ |archive-date=2023-04-06 |access-date=2023-08-28 |website=The New Stack |language=en-US}}</ref> <!-- It's compile has a restrictive BSL licence, but it doesn't affect generated code: --> Codon can also compile to Python extension modules that can be imported and used from Python. * [[MicroPython]] and [[CircuitPython]] are Python 3 variants that are optimized for [[microcontroller]]s, including the [[Lego Mindstorms EV3]].<ref>{{Cite web|url=https://education.lego.com/en-us/support/mindstorms-ev3/python-for-ev3|title=Python-for-EV3|website=LEGO Education|language=en|access-date=17 April 2019|archive-date=7 June 2020|archive-url=https://web.archive.org/web/20200607234814/https://education.lego.com/en-us/support/mindstorms-ev3/python-for-ev3|url-status=live}}</ref> * Pyston is a variant of the Python runtime that uses just-in-time compilation to speed up execution of Python programs.<ref>{{cite news|url=https://www.infoworld.com/article/3587591/pyston-returns-from-the-dead-to-speed-python.html|title=Pyston returns from the dead to speed Python|last=Yegulalp|first=Serdar|date=29 October 2020|website=[[InfoWorld]]|access-date=26 January 2021|archive-date=27 January 2021|archive-url=https://web.archive.org/web/20210127113233/https://www.infoworld.com/article/3587591/pyston-returns-from-the-dead-to-speed-python.html|url-status=live}}</ref> * Cinder is a performance-oriented fork of CPython 3.8 that features a number of optimizations, including bytecode inline caching, eager evaluation of coroutines, a method-at-a-time [[Just-in-time compilation|JIT]], and an experimental bytecode compiler.<ref>{{Cite web|url=https://github.com/facebookincubator/cinder|title=cinder: Instagram's performance-oriented fork of CPython.|website=[[GitHub]]|access-date=4 May 2021|language=en|archive-date=4 May 2021|archive-url=https://web.archive.org/web/20210504112500/https://github.com/facebookincubator/cinder|url-status=live}}</ref> * The Snek<!-- (previously named Newt) --><ref>{{Cite web |last=Aroca |first=Rafael |date=2021-08-07 |title=Snek Lang: feels like Python on Arduinos |url=https://rafaelaroca.wordpress.com/2021/08/07/snek-lang-feels-like-python-on-arduinos/ |access-date=2024-01-04 |website=Yet Another Technology Blog |language=en |archive-date=5 January 2024 |archive-url=https://web.archive.org/web/20240105001031/https://rafaelaroca.wordpress.com/2021/08/07/snek-lang-feels-like-python-on-arduinos/ |url-status=live}}</ref><ref>{{Cite web |last=Aufranc (CNXSoft) |first=Jean-Luc |date=2020-01-16 |title=Snekboard Controls LEGO Power Functions with CircuitPython or Snek Programming Languages (Crowdfunding) β CNX Software |url=https://www.cnx-software.com/2020/01/16/snekboard-controls-lego-power-functions-with-circuitpython-or-snek-programming-languages/ |access-date=2024-01-04 |website=CNX Software β Embedded Systems News |language=en-US |archive-date=5 January 2024 |archive-url=https://web.archive.org/web/20240105001031/https://www.cnx-software.com/2020/01/16/snekboard-controls-lego-power-functions-with-circuitpython-or-snek-programming-languages/ |url-status=live}}</ref><ref>{{Cite web |last=Kennedy (@mkennedy) |first=Michael |title=Ready to find out if you're git famous? |url=https://pythonbytes.fm/episodes/show/187/ready-to-find-out-if-youre-git-famous |access-date=2024-01-04 |website=pythonbytes.fm |language=en-US |archive-date=5 January 2024 |archive-url=https://web.archive.org/web/20240105001031/https://pythonbytes.fm/episodes/show/187/ready-to-find-out-if-youre-git-famous |url-status=live}}</ref><!-- https://keithp.com/blogs/newt-lola/ https://bipes.net.br/snek-web-uploader/ --> embedded computing language "is Python-inspired, but it is not Python. It is possible to write Snek programs that run under a full Python system, but most Python programs will not run under Snek."<ref>{{Cite web |last=Packard |first=Keith |date=2022-12-20 |title=The Snek Programming Language: A Python-inspired Embedded Computing Language |url=https://sneklang.org/doc/snek.pdf |access-date=4 January 2024 |archive-date=4 January 2024 |archive-url=https://web.archive.org/web/20240104162458/https://sneklang.org/doc/snek.pdf |url-status=live}}</ref> Snek is compatible with 8-bit [[AVR microcontrollers]] such as [[ATmega|ATmega 328P]]-based Arduino, as well as larger microcontrollers that are compatible with [[MicroPython]]. Snek is an imperative language that (unlike Python) omits [[object-oriented programming]]. Snek supports only one numeric data type, which features 32-bit [[single-precision|single precision]] (resembling [[JavaScript]] numbers, though smaller).<!-- "Snek is a tiny embeddable language targeting processors with only a few kB of flash and ram. Think of something that would have been running BASIC years ago and you'll have the idea. These processors are too small to run MicroPython." "Snekboard is a custom embedded computer designed to run Snek or CircuitPython." --> ===Unsupported implementations=== [[Stackless Python]] is a significant fork of CPython that implements [[microthread]]s. This implementation uses the [[call stack]] differently, thus allowing massively concurrent programs. PyPy also offers a stackless version.<ref name="AutoNT-73"/> Just-in-time Python compilers have been developed, but are now unsupported: * Google began a project named [[Unladen Swallow]] in 2009: this project aimed to speed up the Python interpreter five-fold by using [[LLVM]], and improve [[multithreading (computer architecture)|multithreading]] capability for scaling to thousands of cores,<ref name="AutoNT-74"/> while typical implementations are limited by the [[global interpreter lock]]. * [[Psyco]] is a discontinued [[just-in-time compilation|just-in-time]] [[run-time algorithm specialization|specializing]] compiler, which integrates with CPython and transforms bytecode to machine code at runtime. The emitted code is specialized for certain [[data type]]s and is faster than standard Python code. Psyco does not support Python 2.7 or later. * [[PyS60]] was a Python 2 interpreter for [[Series 60]] mobile phones, which was released by [[Nokia]] in 2005. The interpreter implemented many modules from Python's standard library, as well as additional modules for integration with the [[Symbian]] operating system. The Nokia [[N900]] also supports Python through the [[GTK]] widget library, allowing programs to be written and run on the target device.<ref>{{cite web|title=Python on the Nokia N900|url=http://www.stochasticgeometry.ie/2010/04/29/python-on-the-nokia-n900/|website=Stochastic Geometry|date=29 April 2010|access-date=9 July 2015|archive-date=20 June 2019|archive-url=https://web.archive.org/web/20190620000053/http://www.stochasticgeometry.ie/2010/04/29/python-on-the-nokia-n900/|url-status=live}}</ref> ===Cross-compilers to other languages=== There are several compilers/[[transpiler]]s to high-level object languages; the source language is unrestricted Python, a subset of Python, or a language similar to Python: * Brython,<ref>{{Cite web|title=Brython|url=https://brython.info/|access-date=2021-01-21|website=brython.info|archive-date=3 August 2018|archive-url=https://web.archive.org/web/20180803065954/http://brython.info/|url-status=live}}</ref> Transcrypt,<ref>{{cite web|title=Transcrypt β Python in the browser|url=https://www.transcrypt.org|access-date=22 December 2020|website=transcrypt.org|language=en|archive-date=19 August 2018|archive-url=https://web.archive.org/web/20180819133303/http://www.transcrypt.org/|url-status=live}}</ref><ref>{{Cite web|url=https://www.infoq.com/articles/transcrypt-python-javascript-compiler/|title=Transcrypt: Anatomy of a Python to JavaScript Compiler|website=InfoQ|access-date=20 January 2021|archive-date=5 December 2020|archive-url=https://web.archive.org/web/20201205193339/https://www.infoq.com/articles/transcrypt-python-javascript-compiler/|url-status=live}}</ref> and [[Pyjs]] compile Python to [[JavaScript]]. (The latest release of Pyjs was in 2012.) * [[Cython]] compiles a superset of Python<!-- actually 2.7 by default, but Python 3 by override --> to C. The resulting code can be used with Python via direct C-level API calls into the Python interpreter. * PyJL compiles/transpiles a subset of Python to "human-readable, maintainable, and high-performance Julia source code".<ref name=PyJL>{{Cite web|title=Transpiling Python to Julia using PyJL|url=https://web.ist.utl.pt/antonio.menezes.leitao/ADA/documents/publications_docs/2022_TranspilingPythonToJuliaUsingPyJL.pdf|quote=After manually modifying one line of code by specifying the necessary type information, we obtained a speedup of 52.6Γ, making the translated Julia code 19.5Γ faster than the original Python code.|access-date=20 September 2023|archive-date=19 November 2023|archive-url=https://web.archive.org/web/20231119071525/https://web.ist.utl.pt/antonio.menezes.leitao/ADA/documents/publications_docs/2022_TranspilingPythonToJuliaUsingPyJL.pdf|url-status=live}}</ref> Despite the developers' performance claims, this is not possible for ''arbitrary'' Python code; that is, compiling to a faster language or machine code is known to be impossible in the general case. The semantics of Python might potentially be changed, but in many cases speedup is possible with few or no changes in the Python code. The faster Julia source code can then be used from Python or compiled to machine code. * [[Nuitka]] compiles Python into C<!-- "is the optimizing Python compiler written in Python that creates executables that run without a separate installer"-->.<ref>{{cite web|title=Nuitka Home {{!}} Nuitka Home|url=http://nuitka.net/|access-date=18 August 2017|website=nuitka.net|language=en|archive-date=30 May 2020|archive-url=https://web.archive.org/web/20200530211233/https://nuitka.net/|url-status=live}}</ref> This compiler works with Python 3.4 to 3.12 (and 2.6 and 2.7) for Python's main supported platforms (and Windows 7 or even Windows XP) and for Android. The compiler developers claim full support for Python 3.10, <!-- "also finishes full compatibility with the match statements of 3.10" "From here on, we need to re-visit compatibility. A few more obscured 3.10 features are missing, the 3.11 compatibility is not yet complete" -->partial support for Python 3.11 and 3.12, <!-- "This release bumps the long-awaited 3.12 support to a complete level. Now, Nuitka behaves identically to CPython 3.12 for the most part. .. After being late with 3.12 support, we will now be early with 3.13 support if all goes well." --> and experimental support for Python 3.13. Nuitka supports macOS including Apple Silicon-based versions. <!-- "While arm64 (M1) only builds and x86_64 (Intel) only builds work, the value universal which of course implies twice the size, and as such has other disadvantages, is not yet supported. --> The compiler is free of cost, though it has commercial add-ons (e.g., for hiding source code).<!-- "Container Builds (public + commercial)" --> * [[Numba]] is a JIT compiler that is used from Python; the compiler translates a subset of Python and NumPy code into fast machine code. This tool is enabled by adding a decorator to the relevant Python code. * Pythran compiles a subset of Python 3 to C++ ([[C++11]]).<ref name="Guelton Brunet Amini Merlini 2015 p=014001">{{cite journal |last1=Guelton |first1=Serge |last2=Brunet |first2=Pierrick |last3=Amini |first3=Mehdi |last4=Merlini |first4=Adrien |last5=Corbillon |first5=Xavier |last6=Raynaud |first6=Alan |title=Pythran: enabling static optimization of scientific Python programs |journal=Computational Science & Discovery |publisher=IOP Publishing |volume=8 |issue=1 |date=16 March 2015 |issn=1749-4699 |doi=10.1088/1749-4680/8/1/014001|doi-access=free |page=014001 |bibcode=2015CS&D....8a4001G}}</ref> * [[RPython]] can be compiled to C, and it is used to build the PyPy interpreter for Python. * The Python β 11l β C++ transpiler<ref>{{Cite web |url=https://11l-lang.org/transpiler |title=The Python β 11l β C++ transpiler |access-date=17 July 2022 |archive-date=24 September 2022 |archive-url=https://web.archive.org/web/20220924233728/https://11l-lang.org/transpiler/ |url-status=live}}</ref> compiles a subset of Python 3 to C++ ([[C++17]]). There are also specialized compilers: * [[MyHDL]] is a Python-based [[hardware description language]] (HDL) that converts MyHDL code to [[Verilog]] or [[VHDL]] code. Some older projects existed, as well as compilers not designed for use with Python 3.x and related syntax: * Google's Grumpy [[transpile]]s Python 2 to [[Go (programming language)|Go]].<ref>{{Cite web|url=https://github.com/google/grumpy|title=google/grumpy|date=10 April 2020|via=GitHub|access-date=25 March 2020|archive-date=15 April 2020|archive-url=https://web.archive.org/web/20200415054919/https://github.com/google/grumpy|url-status=live}}</ref><ref>{{Cite web|url=https://opensource.google/projects/|title=Projects|website=opensource.google|access-date=25 March 2020|archive-date=24 April 2020|archive-url=https://web.archive.org/web/20200424191248/https://opensource.google/projects/|url-status=live}}</ref><ref>{{Cite news|url=https://www.theregister.com/2017/01/05/googles_grumpy_makes_python_go/|title=Google's Grumpy code makes Python Go|first=Thomas Claburn in San|last=Francisco|website=www.theregister.com|access-date=20 January 2021|archive-date=7 March 2021|archive-url=https://web.archive.org/web/20210307165521/https://www.theregister.com/2017/01/05/googles_grumpy_makes_python_go/|url-status=live}}</ref> The latest release was in 2017. * [[IronPython]]<!-- (abandoned by Microsoft) --> allows running Python 2.7 programs with the .NET [[Common Language Runtime]].<ref>{{Cite web|title=IronPython.net /|url=https://ironpython.net/|website=ironpython.net|archive-date=17 April 2021|archive-url=https://web.archive.org/web/20210417064418/https://ironpython.net/|url-status=live}}</ref> An [[Software release life cycle#Alpha|alpha]] version (released in 2021), is available for "Python 3.4, although features and behaviors from later versions may be included."<ref>{{Cite web |url=https://github.com/IronLanguages/ironpython3 |title=GitHub β IronLanguages/ironpython3: Implementation of Python 3.x for .NET Framework that is built on top of the Dynamic Language Runtime<!-- Bot generated title --> |website=[[GitHub]] |archive-date=28 September 2021 |archive-url=https://web.archive.org/web/20210928101250/https://github.com/IronLanguages/ironpython3 |url-status=live}}</ref> * [[Jython]] compiles Python 2.7 to Java bytecode, allowing the use of Java libraries from a Python program.<ref>{{Cite web|title=Jython FAQ|url=https://www.jython.org/jython-old-sites/archive/22/userfaq.html|access-date=2021-04-22|website=www.jython.org|archive-date=22 April 2021|archive-url=https://web.archive.org/web/20210422055726/https://www.jython.org/jython-old-sites/archive/22/userfaq.html|url-status=live}}</ref> * [[Pyrex (programming language)|Pyrex]] (last released in 2010) and [[Shed Skin]] (last released in 2013) compile to C and C++ respectively. ===Performance=== A perforance comparison among various Python implementations, using a non-numerical (combinatorial) workload, was presented at EuroSciPy '13.<ref>{{cite conference |title=Performance of Python runtimes on a non-numeric scientific code |last=Murri |first=Riccardo |conference=European Conference on Python in Science (EuroSciPy) |year=2013 |arxiv=1404.6388|bibcode=2014arXiv1404.6388M}}</ref> In addition, Python's performance relative to other programming languages is benchmarked by [[The Computer Language Benchmarks Game]].<ref>{{cite web|title=The Computer Language Benchmarks Game|url=https://benchmarksgame-team.pages.debian.net/benchmarksgame/fastest/python.html|access-date=30 April 2020|archive-date=14 June 2020|archive-url=https://web.archive.org/web/20200614210246/https://benchmarksgame-team.pages.debian.net/benchmarksgame/fastest/python.html|url-status=live}}</ref> There are several approaches to optimizing Python performance, given the inherent slowness of an [[interpreted language]]. These approaches include the following strategies or tools: * [[Just-in-time compilation]]: Dynamically compiling Python code just before it is executed. This technique is used in libraries such as [[Numba]] and [[PyPy]]. * [[Compiler|Static compilation]]: Python code is compiled into machine code sometime before execution. An example of this approach is Cython, which compiles Python into C. * Concurrency and parallelism: Multiple tasks can be run simultaneously. Python contains modules such as `multiprocessing` to support this form of parallelism. Moreover, this approach helps to overcome limitations of the [[Global interpreter lock|Global Interpreter Lock]] (GIL) in CPU tasks. * Efficient data structures: Performance can also be improved by using data types such as <code>Set</code> for membership tests, or <code>deque</code> from <code>collections</code> for [[Queueing theory|queue]] operations.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)