python /

CPython

Live map
Snapshotmain · c144799

How the reference Python implementation parses a script, produces bytecode, evaluates objects, and imports more code.

Click a building or route
Choose a path

Trace source from CLI selection through PEG parsing and compilation into bytecode-driven object operations and managed memory.

System map8 components · 9 connections
130%
CPython architectureStart at the command-line gate. The source pipeline runs across the upper and middle rows into the bytecode evaluator; objects and memory sit below it, while imports loop new modules back through compilation.filename or command st…decoded source, gramma…AST module, source fil…PyCodeObject, globals,…stack values, type slo…object size, reference…freed objects, finaliz…Python CLIPEG parserSource runnerBytecodecompilerBytecodeevaluatorObjectprotocolImport systemAllocatorand GC
Connections
BuildingsEntryServiceComputeStorageRuntimeToolingExternal

Terms, in plain English

PEG parserA Parsing Expression Grammar parser chooses ordered grammar alternatives and can express Python's syntax directly.

How to study this repo

  1. 1
    Watch source become bytecode

    Use Python's `ast` and `dis` modules on a tiny function, then match those two representations to Parser/pegen.c and Python/compile.c.

  2. 2
    Trace one instruction

    Choose a familiar opcode in Python/bytecodes.c and follow the object protocol calls and reference-count changes it performs.

  3. 3
    Study an import miss

    Follow _find_and_load in importlib/_bootstrap.py and note the cache checks, lock, module creation, execution, and cleanup order.