Python Interpreters, Compilers, Translators

by Alex
Python Interpreters, Compilers, Translators

Python is an interpreted programming language. This means that the code is executed “on the fly”, line by line. For example, using the Python Shell, you can enter code one line at a time and each line will be immediately executed by the interpreter. There are alternative implementations of the interpreter and even compilers. The Python interpreter works as follows: – First, the source code, which is written by the programmer and stored in files with the extension .py, is converted into bytecode (files with the extension .pyc). Bytecode is an intermediate layer between human-readable code and processor language code. – Bytecode is then executed by a virtual machine. As you can see, the process is split into two steps. This is done for the sole purpose of speeding it up. This is how the standard implementation, CPython, works, but there are others.


This implementation of the interpreter is the benchmark, as it is the one supplied as part of the language from Python’s official website. As you can guess from the name, it is written in C and developed with support from the Python Software Foundation. A distinctive feature of CPython can be called global interpreter locking (GIL). This architectural solution has caused an enormous amount of controversy. The bottom line is this: this locking prevents threads from running in parallel. This saves the developer a lot of headaches, such as synchronization, memory sharing and so on. On the other hand, because of GIL, parallel programming is only available when using separate processes, which is noticeably slower than parallel threads. The main proponent of global locking is the creator of the language himself, Guido van Rossum. Basically from the complaints about GIL, dynamic typing and Python’s own speed, other variants of the interpreter were born.


The essence of this interpreter is that it compiles source code not to Python Virtual Machine (PVM) byte code, but to Java Virtual Machine (JVM) byte code. This allows Java classes to be used in Python code. The main advantage is that the JVM is faster, especially after recent big optimizations and, in some tests, faster than C++.


This interpreter crosses Python and the .NET Framework. Here they can interact freely – use each other’s libraries, Windows Forms, C# and all other infrastructure becomes available in Python. Like CPython, the interpreter is written in C.


This is another implementation aimed mainly at Windows users. This is basically standard CPython with some documentation and manuals.


Although current versions of CPython are very stable on the Windows operating system, WinPython has a few exclusive features. Since WinPython is a standalone distribution for Python, you only need to download and unzip it to get started. WinPython also comes with some of the most popular Python libraries for data science and machine learning, such as NumPy, Pandas, and SciPy. Consequently, you can work with these Python libraries right away. WinPython comes with many built-in features that are not required in most cases, such as the C compiler and C ++ compiler. This can be a serious limitation, as there is no way to select and load only those functions that are needed.


Nuitka is not only a compiler (it can create executable files), but also a transpiler. What is a transpilation? Transpilation is a program conversion where the source code of a program written in one programming language is used as source data, and the equivalent source code in another programming language is produced. In this case this language is C or C++. Nuitka is written entirely in Python.


The PyJS compiler translates Python code into equivalent JavaScript code so that it can be executed inside a web browser. It uses the abstract syntax tree of Python itself to do this.

Stackless Python

Stackless Python is an enhanced version of the Python interpreter. It is so named because it refuses to use the standard C call stack in favor of its own stack. A special feature of Stackless is that it features tasklets (micro-threads) that avoid the excessive consumption of system resources inherent in standard operating system threads. It allows the programmer to take advantage of multi-threaded programming without performance degradation on synchronization primitives and without problems with “race conditions”. If properly used, cheap and lightweight Stackless micro-threads allow to improve program structure, get more readable code and increase programmer’s productivity.


Cython is more than just a compiler for Python; it is a language superset of the Python language that supports interaction with C/C ++. CPython is written in C, so it is a language that usually meshes well with Python. At its core, it is an intermediate layer between Python and C/C++. Cython allows you to write regular Python code with some minor modifications, which is then directly translated into C code. But remember that you have to specify types of all variables yourself – goodbye dynamic typing type yourself – goodbye dynamic typing.


Guido van Rossum once said: “If you want your code to run faster, you should probably just use PyPy”. PyPy is written in Python and requires no changes to the code. It’s a fast and efficient alternative to CPython. By running your program with it, you can get up to a hundred times the speed increase without making a single change to the code. However, there are a number of limitations: – It may not work correctly with C libraries connected to Python code – Makes a lot of manipulations on the code before launching it for optimization purposes. This makes it pointless to use it in small scripts.


Pythran is designed to efficiently compile scientific programs using multiple cores and SIMD instructions.


Speed-oriented Pyston is an adaptation of Python. It uses just-in-time compilation and many other techniques to speed things up. According to some tests, it runs 30% faster than the original Python implementation. The Pyston developers have gone to great lengths to make the implementation as painless to use as possible. The main goal is that Python can be used simply by typing “Pyston” instead of “Python”.


Skulpt is an implementation of Python in a browser, there is no need for additional processing, plugins, or server-side support needed to run Python in a web browser. Any Python code written in Skulpt runs directly in a web browser. While Skulpt translates Python code into JS code, it doesn’t make the latter easier to execute.


The Python compiler follows a simplified and powerful syntax without requiring additional extensions. Transcrypt precompiles into fast, readable JS code that can be debugged from Python source code. In addition to seamless access to any JS library, Transcrypt can also run on top of Node.js. With support for hierarchical modules, local classes, and multiple inheritance, Transcrypt boasts a flexible and stable overall structure.


Despite all the variety of interpreters, compilers and translators Python, it is worth remembering that the most stable and relevant, albeit slow, will be the standard implementation of the interpreter – CPython. It is also the best choice for beginners who only need to learn the language, not the nuances of its implementation. If you need to run Python in a browser, it is worth considering translators into JavaScript. Just as a solution may be a relatively young but very promising technology beyond the scope of this lesson – Web Assembly. Well, for extra speed, it is probably worth turning to PyPy.

Related Posts