July 14, 2026 · 3 min read
PythonInternalsUnder the Hood: A Tour of the Python Engine
This is Part 1 of a three-part series on Python internals. The series is based on CPython 3.9, the version explored in the source material — the structure described here is broadly stable across versions, but line counts and file layouts drift over time.
Have you ever wondered what actually happens when you type python into your terminal? Most of us treat Python like a magic box: text goes in, behaviour comes out. But that box is actually a massive, well-organized software project called CPython — the reference implementation of the Python language, and almost certainly the "Python" you use every day.
The blueprint of Python
CPython is written in two main languages. It contains roughly 350,000 lines of C code and nearly 600,000 lines of Python code. That surprises people in both directions — there's more Python in Python than C, but the part doing the heavy lifting is C.
When you download the source code, it's organized into specific "neighborhoods", and knowing the map makes the whole project far less intimidating:
Objects/— This is where Python's "DNA" lives. Every basic type you take for granted —int,list,dict,str— is implemented here as C code. When you write[1, 2, 3], the machinery that allocates, grows, and indexes that list lives inObjects/listobject.c.Lib/— The standard library modules you use every day, written in Python itself.json,pathlib,dataclasses— when the job doesn't need C-level performance, CPython's developers write Python like the rest of us.Python/— This is the "brain" of the operation. It contains the compiler and the evaluation loop — the engine that actually runs your code. We'll spend most of Part 3 in this neighborhood.
There are other districts worth knowing — Modules/ holds standard-library modules that are written in C (like math), and Include/ holds the public C API headers — but the three above are where the story mostly happens.
Building the engine
Here's the part that makes CPython feel real rather than magical: before Python can run on your computer, someone had to compile all of that source code into an executable program.
On Linux and macOS, that's the classic two-step:
./configure
make
./configure inspects your system — compiler, libraries, platform quirks — and generates a build recipe. make then follows that recipe, turning hundreds of thousands of lines of C into the single python binary you invoke every day. If you've never done it, compiling CPython yourself is a genuinely great weekend exercise: it converts "Python" from an abstract tool into a program you've watched being born.
Why bother looking inside?
You can write excellent Python for years without reading a line of CPython source. But understanding the engine pays off in unexpected places: debugging performance mysteries, understanding why the GIL exists (Part 2), or knowing what a .pyc file actually saves you (Part 3).
Next up: The Secret Morning Routine of CPython — everything Python does before it looks at your first line of code.