This is a quick guide for people who are interested in learning more about CPython's internals. It provides a summary of the source code structure and contains references to resources providing a more in-depth view.
This guide gives an overview of CPython's code structure. It serves as a summary of file locations for modules and builtins.
For Python modules, the typical layout is:
- :file:`Lib/{<module>}.py`
- :file:`Modules/_{<module>}.c` (if there's also a C accelerator module)
- :file:`Lib/test/test_{<module>}.py`
- :file:`Doc/library/{<module>}.rst`
For extension-only modules, the typical layout is:
- :file:`Modules/{<module>}module.c`
- :file:`Lib/test/test_{<module>}.py`
- :file:`Doc/library/{<module>}.rst`
For builtin types, the typical layout is:
- :file:`Objects/{<builtin>}object.c`
- :file:`Lib/test/test_{<builtin>}.py`
- :file:`Doc/library/stdtypes.rst`
For builtin functions, the typical layout is:
Some exceptions:
- builtin type
intis at :file:`Objects/longobject.c` - builtin type
stris at :file:`Objects/unicodeobject.c` - builtin module
sysis at :file:`Python/sysmodule.c` - builtin module
marshalis at :file:`Python/marshal.c` - Windows-only module
winregis at :file:`PC/winreg.c`
For over 20 years the CPython code base has been changing and evolving. Here's a sample of resources about the architecture of CPython aimed at building your understanding of both the 2.x and 3.x versions of CPython:
