🐍

1. 🐍 Python Execution Model

CPython, PyPy, Jython, GraalPy — Understanding the engines that power Python

At its core, Python is a high-level, interpreted, dynamically typed, general-purpose programming language. It was created by Guido van Rossum and first released in 1991 with a singular guiding philosophy: code should be readable above all else.

This philosophy is formally captured in PEP 20 — The Zen of Python — a collection of 19 aphorisms that guide Python's design decisions.

Principles like 'Readability counts', 'Explicit is better than implicit', and 'There should be one—and preferably only one—obvious way to do it' shape every aspect of the language.

Python is used across an incredibly wide range of domains: web development (Django, Flask), automation and scripting, data science (Pandas, NumPy), machine learning (TensorFlow, PyTorch), DevOps, scientific computing, and even game development.

This versatility is one of the reasons Python consistently ranks among the most popular programming languages in the world.

A crucial distinction to understand is that Python is strongly typed but dynamically typed. Strongly typed means Python does not perform implicit type coercion — you cannot add a string to an integer without explicitly converting one of them.

Dynamically typed means variable types are determined at runtime, not at compile time.

You never write `int x = 5;` in Python; you simply write `x = 5` and Python figures out the type on the fly.

Furthermore, everything in Python is an object — integers, strings, functions, classes, and even modules are all first-class objects with attributes and methods.

A common misconception is that Python source code is directly executed line by line. In reality, the process is more nuanced.

Python first compiles your source code into an intermediate representation called bytecode, and then a virtual machine interprets that bytecode.

This is fundamentally different from truly compiled languages like C or Go, where source code is transformed directly into machine code that the CPU executes natively.

Python sits in a middle ground — it performs a compilation step, but the output is bytecode for a virtual machine rather than native machine instructions.

This interpreter overhead per instruction is the primary reason Python is slower than C for raw computational tasks.

org. It is written in C, and it is what the vast majority of Python developers use.

pyc` bytecode files, which are then executed by the CPython Virtual Machine.

One of CPython's most significant architectural decisions is the Global Interpreter Lock (GIL), a mutex that allows only one thread to execute Python bytecode at a time, even on multi-core processors.

This simplifies memory management but limits true multi-threaded parallelism for CPU-bound tasks.

PyPy is an alternative Python implementation written in a restricted subset of Python called RPython. Its headline feature is a Just-In-Time (JIT) compiler that can make Python code run 5 to 10 times faster than CPython for long-running, CPU-bound programs.

The JIT works by observing which code paths are executed frequently ('hot loops') and compiling them to optimized machine code on the fly.

The tradeoff is higher memory usage, slower startup time, and imperfect compatibility with some C extension modules.

Jython is Python implemented in Java, running on the Java Virtual Machine (JVM). It can import and use Java libraries directly from Python code, making it a powerful bridge between the two ecosystems.

Notably, Jython has no GIL, enabling true thread-level parallelism.

7 and is no longer actively maintained, limiting its practical use today.

GraalPy is a newer Python implementation running on GraalVM, Oracle's polyglot runtime. GraalVM can run Python alongside JavaScript, Ruby, and R in the same runtime with seamless interoperability.

js ecosystems and is experimental but gaining traction in enterprise environments.

NET enterprise environments.

snippet
import sys
import platform

# Discover which Python engine is running your code
print(f"Implementation: {sys.implementation.name}")
print(f"Platform info: {platform.python_implementation()}")
print(f"Version: {sys.version}")
print(f"Version tuple: {sys.version_info}")

# Everything in Python is an object
x = 42
print(type(x))        # <class 'int'>
print(type(type(x)))   # <class 'type'> — even types are objects!
Code Breakdown
1-2

We import the `sys` and `platform` modules from Python's standard library to introspect the running interpreter.

5

`sys.implementation.name` directly queries the interpreter binary for its internal identifier. On standard Python, this prints `'cpython'`. On PyPy, it would print `'pypy'`.

6

`platform.python_implementation()` provides a more human-readable version, outputting `'CPython'` with proper capitalization.

7

`sys.version` outputs the full version string including build date and compiler information.

8

`sys.version_info` returns a named tuple like `(3, 12, 0, 'final', 0)` that you can use for programmatic version checks.

11-13

We demonstrate that everything is an object. Even `type(x)` returns a type object, and `type(type(x))` shows that types themselves are instances of `type` — showcasing Python's deeply object-oriented nature.

Key Insights

Python is strongly typed but dynamically typed — no implicit type coercion, but types are inferred at runtime.

CPython is the reference implementation with the GIL; PyPy offers JIT compilation for 5-10x speedups.

Jython runs on the JVM (no GIL), GraalPy enables polyglot programming on GraalVM.

Everything in Python is an object — integers, functions, classes, and modules included.

Python compiles to bytecode first, then interpretes it via a virtual machine — it is not purely interpreted.

Developer's Note

When someone asks 'Is Python slow?', the nuanced answer is: CPython is slow for CPU-bound tasks due to interpreter overhead and the GIL. But for I/O-bound work (web servers, file processing, API calls), Python's speed is rarely the bottleneck. And with PyPy, Cython, or C extensions, you can achieve near-C performance where it matters.