Which Python Implementation you should use (Cpython, PyPy, etc.)?
Python as you know it is not just a programming language. The Python that you download from the official Python.org website is a reference implementation. What that means is it implements the Python language specifications, as defined by the Python Software Foundation.
But Python.org's reference implementation is not the only Python implementation available. There are many other some with very specialised use cases and for beginners sometimes this can get confusing. So let's take a look at some key Python implementations available and when
CPython
CPythonThe officiis Python implementation that is used by the Python Software Foundation. Written in C and Python, it is the most popular Python implementation and is used by the vast majority of Python developers. CPython is considered the most mature and "production-quality" Python implementation.
If you're starting out with Python, you should definitely start with CPython as you're least likely to encounter any issues with it.
PyPy
PyPy is a Python implementation written in Python (specifically RPython) and is a replacement for CPython. PyPy's main utility is that it is really fast, in fact, it claims to be almost 5x faster than CPython.
However, PyPy can run most Python code except for when the code depends on CPython extensions which results in either inability to run or significant loss of performance.
PyPy is intended for advanced users who want to optimise their code for performance.
Jython
Jython is a Python implementation written in Python and Java and is designed to run on Java platforms. The key use case for Jython is its ability to import Java classes and that Jython compiles the Python code into Java bytecode which can be run on Java Virtual Machines (JVM).
The typical use case of Jython is when Java classes are needed to be imported, e.g. you could build an Android app using a mix of Jython which can import Java Android packages and a toolkit like Kivy.
CircuitPython
CircuitPython is maintained by Adafruit and is designed to run on certain microcontroller hardware such as the Adafruit Feather M0 and Adafruit Feather M4. Is is written in C and is not exlusive to Adafruit Microcontrollers and can be used for other supported microcontroller hardware as well.
Other notable Python implementations
- Numba is a NumPy aware JIT compiler that can compile a subset of Python code into machine code for faster execution
- Pyston is a relatively new alternate Python implementation designed to be a drop-in replacement for CPython and optimised for performance with claimed improvements of 30% in speed
- RPython is a restricted version of Python is a subset of CPython and is designed to be a framework for creating dynamic languages
Conclusion
For most purposes, CPython is the implementation you should be using, unless you have a specific reason to use another implementation as described above.