Python 1.5 - Flavours/implementations of Python
Flavours/implementations of Python
Flavours of the Python refer to the different types of
compilers available. Python offers different types of implementations who work
for different purposes. These compilers/flavours are used to integrate various
programming languages into Python. A programmer may choose any Python
implementation according to his requirements. We have already understood that
Python is a “compiled interpreted language” so don’t get confused here. Python
code is first compiled to Byte code by a compiler and then Byte code is
executed by Interpreter(PVM). Python flavours contain both the compiler and
interpreter but we generally say that these are Python compilers. So Python has
many compilers, following are some of them –
Python Flavour/Implementation = Python compiler + Python
Interpreter
1. CPython
It is the standard compiler for Python that is developed in
C language. CPython converts the source code into byte code using C language
functions. The advantage is that we can execute C and C++ functions and
programs in CPython. We will be writing Python programs in CPython. If
you download Python from https://www.python.org/downloads/,
then you will be downloading CPython by default. Again, CPython compiler does
not mean that it is only a Compiler, rather it has both the compiler and
interpreter. The same thing also applies with the rest of the compilers.
2. Jython
It is completely developed in Java. It was earlier called
JPython. Jython was developed to run on Java platforms. Jython first converts the
Python source code into Java Byte code, then this Byte code is executed by JVM
(Java virtual machine) to get the output. We can run this Byte code (created by
Jython) on any Java platform.
3. PyPy
This is Python implementation which was developed in Python
language. Actually, PyPy is written in language called ‘RPython’ which was
created in Python language. Rpython is a programming language that is most
suitable for creating interpreters. PyPy is faster than the other compilers
because its PVM has a JIT (just in time) compiler. When Python source code is
compiled into Byte code by PyPy, then that Byte code is executed very fast by
PVM because this PVM contains a JIT compiler. And we know that the compiler is
faster than just an Interpreter. The conclusion is that, PVM contains both
the interpreter and a compiler(JIT) in PyPy implementation. But other flavours
such as ‘CPython’ have only interpreter in their PVM. That is why PyPy is much
faster than the standard CPython flavour.
Now the question arises that if PyPy is faster than CPython, then why do we not use PyPy instead of CPython. So the answer is that “We cannot execute C functions and programs in PyPy while we can in CPython”, and PyPy also does not support many libraries. CPython is more stable than PyPy.
Okay, so that is why pypy is faster than CPython.
ReplyDelete