Bubba loves python

Our students usually ask what are the differences between Python implementations. Or why we even have different implementations. The easiest way to understand it, is to imagine Python as a specification for a programming language. There’s no “Python” that you can execute. Think about Python like the blueprints to create an implementation of a programming language. Obviously, just having a specification isn’t very helpful, and to write our programs, we need a real programming language. When you go to Python.org and hit the download button, what you’re getting is CPython. Quoting wikipedia, CPython is:

the default, most widely used implementation of the Python programming language.

As the name implies, CPython is written in C, and is maintained by the community, with people from the PSF in charge.

But, CPython is not the only implementation of Python. We can’t even say it’s the “best” one. It’s just one of the several implementation that exist out there. Here’s a list of other Python implementations:

A Python implementation written in Java. Its main advantage is allowing a good interaction with Java libraries and legacy software. Think about being a programmer in a big company where they have all their systems written in Java. You can start a new project by writing Python and still use the legacy libraries and services from your company. We haven’t tried it extensively, but people usually say that Jython is a bit slower than CPython. The JVM consumes a good amount of memory and it takes some time to load, so that might be the case. The bad news are that many libraries from CPython won’t work with Jython (specially the ones written in C). Summary:

Good : Compatibility with Java libraries and services

: Compatibility with Java libraries and services Bad: Arguably slow, lack of compatibility with CPython libraries.

A Python implementation targeting Microsoft’s .NET framework. Similar to Jython, the main advantage of IronPython is the ability to work closely with the .NET framework. “IronPython can use the .NET Framework and Python libraries, and other .NET languages can use Python code just as easily.” Other advantage is being able to use IronPython with Silverlight in a web browser. We could say that it has the same limitations as Jython: many Python libraries (with C bindings) won’t work in IronPython.

Good : Compatibility with the .NET framework and Silverlight.

: Compatibility with the .NET framework and Silverlight. Bad: Lack of compatibility with CPython libraries.

PyPy (my personal favorite) is a Python implementation written in Python 🤔(sounds crazy, we know). The beauty of PyPy is the JIT compiler built within it. It’s arguably the best compiler written for Python. PyPy is crazy fast. As you might know, Python is a highly dynamic programming language, and CPython can’t produce good optimized machine code while executing our programs. That’s why it’s usually said that “python is slow”. PyPy, by using a subset of Python known as RPython, is capable to compile the code to machine code at runtime (just-in-time compilation) and optimize it to be really fast. PyPy is highly compatible with existing Python code, although sometimes it requires a little bit more work. The downside of PyPy is that its current main version is Python 2.7, and the Python 3 support is in beta and moving (arguably) slowly.

Good : Super fast. Good support of standard libraries and community libraries.

: Super fast. Good support of standard libraries and community libraries. Bad: Might require more work to use some libraries. Python 3 support limited.

Other implementation/variants worth checking: