Skip to content

CPython Internals

A deep read of CPython: architecture, object model, memory management, compilation pipeline, and the evaluation loop.

1. OrientationWhat CPython is, building from source, the repository layout, reading C code, the runtime model, and the path from source code to execution.
6 pages · 67 min
2. Objects and MemoryThe Python object model, PyObject and PyVarObject layout, reference counting, the garbage collector, memory allocators, and built-in type implementations.
11 pages · 141 min
3. Compilation PipelineTokenization, parsing, the AST, symbol tables, compiler passes, code objects, constants and locals, bytecode generation, and bytecode optimization.
9 pages · 103 min
4. The InterpreterThe evaluation loop, frames, stack-based execution, bytecode instructions, function and method calls, attribute lookup, exceptions, generators, coroutines, pattern matching, comprehensions, and closures.
13 pages · 220 min
5. Runtime SystemsModules and imports, packages, the import lock, descriptors, classes and metaclasses, the MRO, the GIL, threads, subinterpreters, signals, context variables, and audit hooks.
12 pages · 195 min
6. Standard Library Interfaces to the CoreHow sys, inspect, dis, gc, types, importlib, ctypes, multiprocessing, and asyncio bridge Python code to CPython internals.
9 pages · 98 min
7. C API and ExtensionsThe Python C API, reference ownership rules, creating extension modules, defining new types, the buffer protocol, capsules, stable ABI, limited API, embedding Python, and cross-language calls.
11 pages · 107 min
8. Performance InternalsInterpreter dispatch, inline caches, the specializing adaptive interpreter, function call fast paths, vectorcall, dictionary and attribute access performance, memory locality, profiling, and benchmarking.
10 pages · 120 min
9. Development WorkflowRunning the test suite, debug builds, GDB and LLDB, sanitizers, tracing memory bugs, writing core tests, documentation, making patches, reading PEPs, and the release process.
10 pages · 83 min
10. Advanced TopicsFree-threaded CPython, immortal objects, per-interpreter GIL, JIT work, stable ABI design tradeoffs, import system edge cases, serialization internals, security boundaries, and future directions.
9 pages · 88 min