What is CPython, Jython and Pypy.

To understand what is CPython, Jython and Pypy let’s first see the components in which Python as a whole is divided:

Python Language: It is just the syntax and the basic definition of the language. It defines the syntax and the describes how the language should convey itself to the interpreter. It tells the user and the system about various patterns that have to be followed.

Python Implementation: It is the implementation of the Python. It describes the way in which the underlying interpreter is written in. When you download Python from python.org, you download its implementation. The language also comes with the package.

ByteCode: It is the code which is formed by the interpreter by converting source code into machine code. This is the code which gets executed by the machine. Instructions you write in your program are written in machine language in this code. 

Now, this may confuse you about the language and the implementation is the different thing. But in general, a programming language is just the set of rules, notations for writing computer programs, which are specifications of a computation or algorithm.

A language is all about rules and syntax. How this language will be implemented is completely a different process.

Now it makes sense to say that there can be multiple implementations of a single language. People can interpret it same as long as the output remains same.

CPython

CPython is the implementation of the python which is written in C language.

It simply means the interpreter which interprets your Python code is written in C language.

When a python code is interpreted via this interpreter, it produces the stack-machine based instruction set which is Python specific and it then executes it.

This is the default python interpreter which is downloaded by default from its official website and is the most common one.

Python language development is always done keeping CPython as the base. So any update in the Python language first appears in the CPython implementation and then the other implementations follows.

Advantages of using CPython:

  1. It is fast and provides a C runtime environment for the execution of code.
  2. Python as a language is developed keeping CPython as the base. So updates are fast and frequent.
  3. Greater support.
  4. Widely used and supported everywhere.
  5. Extensible in c and c++.

Jython

Jython is the implementation of the python which is written in Java language.

Interpreter of Jython is written in Java and after interpretation of Python code via Jython, you will end up with a java byte code. It is 100% Java implementation of Python language.

The development of Jython is done trying to keep up the pace with that of CPython.

Jython is better to use in embedded scripting and Rapid application development.

Python programs are generally 5 to 10X smaller than java code. So Jython provides a great interface for combining both the language and execute tasks in a convenient way.

Advantages of using Jython:

  1. Interactive experimentation – Jython provides an interactive interpreter that can be used to interact with Java packages or with running Java applications.
  2. Support of all the java packages in the form of extension modules
  3. Jython includes the built-in module jarray — which allows Python programmers to create and manipulate Java array objects.

Though in active development, Jython stills miss out on many parts in comparison to CPython.

For instance, popen() and system() are from OS module are missing in Jython. Also from sys module exitfunc() is missing in Jython. ALso, CPython’s thread modules define some aliases that Jython’s doesn’t.

There are many other aspects and methods on which Jython still have to grep on.

Suggested Read: Things that can be done via Python.

Pypy

Pypy is an implementation of Python language which is itself written in Python (Irony!). Since the implementation is done in Python, it provides competitive advantages over the c implementation of Python in terms of better memory utilization, faster execution time etc. Also, the Just In Time compiler in pypy provides great optimisation in time complexity of the code. 

It’s Stacklessness, sandboxing and memory usage makes it the first choice of developers. 

The use of each other completely depends upon one’s need and the type of application. Don’t hesitate to experiment a little!

  • Add Your Comment