PyPy

PyPy
Pypy logo.png
Initial releasemid 2007; 12 years ago (2007)
Stable release
7.2 / 14 October 2019; 31 days ago (2019-10-14)[1]
bitbucket.org/pypy/pypy Edit this at Wikidata
Written inRPython
Operating systemCross-platform
TypePython interpreter and compiler toolchain
Licensepypy.org

PyPy is an alternative implementation of the Python programming language[2] to CPython (which is the standard implementation). PyPy often runs faster than CPython because PyPy is a just-in-time compiler while CPython is an interpreter. Most Python code runs well on PyPy except for code that depends on CPython extensions, which either doesn't work or incurs some overhead when run in PyPy. Internally, PyPy uses a technique known as meta-tracing, which transforms an interpreter into a tracing just-in-time compiler. Since interpreters are usually easier to write than compilers, but run slower, this technique can make it easier to produce efficient implementations of programming languages. PyPy's meta-tracing toolchain is called RPython.

Details and motivation

PyPy was conceived to be an implementation of Python written in a programming language that is similar to Python. This makes it easy to identify areas where it can be improved and makes PyPy more flexible and easier to experiment with than CPython.[citation needed]

PyPy aims to provide a common translation and support framework for producing implementations of dynamic languages, emphasizing a clean separation between language specification and implementation aspects. It also aims to provide a compliant, flexible and fast implementation of the Python programming language using the above framework to enable new advanced features without having to encode low level details into it.[3][4]

RPython

The PyPy interpreter itself is written in a restricted subset of Python called RPython (Restricted Python).[5] RPython puts some constraints on the Python language such that a variable's type can be inferred at compile time.[6]

The PyPy project has developed a toolchain that analyzes RPython code and translates it into a form of byte code, together with an interpreter written in the C programming language. Much of this code is then compiled into machine code, and the byte code runs on the compiled interpreter.

It allows for pluggable garbage collectors, as well as optionally enabling Stackless Python features. Finally, it includes a just-in-time (JIT) generator that builds a just-in-time compiler into the interpreter, given a few annotations in the interpreter source code. The generated JIT compiler is a tracing JIT.[7]

RPython is now also used to write non-Python language implementations such as Pixie.[8]