← Back to Pull requests

gh-756: Add a page about frozen modules #1989

Open
VanshajPoonia opened this pull request with 117 lines diff across 2 files
View on GitHub
VanshajPoonia VanshajPoonia commented on Nov 26, 2026 12:53 UTC
Author

Closes #756.

This adds developer-workflow/frozen-modules.rst and links it from the workflow index. It covers what frozen modules are, the three kinds (bootstrap, stdlib and test), how to change which modules are frozen with make regen-frozen, why some stdlib modules are frozen and others are not, the -X frozen_modules setting, and the test helpers in import_helper.

Each claim follows the CPython source: Python/frozen.c, Tools/build/freeze_modules.py, Python/import.c and Python/initconfig.c. The docs build with no new warnings and sphinx-lint passes.

Diff: 117 lines (+117 / -0) across 2 files Reviewer: StanFromIreland Review duration: 8931m
All Vouch review confidence checks passed
Residual risk 0.03 = Change Risk (0.33) × (1 − Review Confidence (0.91)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.33 · 117 lines diff across 2 files
0.33
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.89 · 3 substantive comment(s)
0.89
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 50%
90%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.285
Real PR Conversation Timeline
4 items
read-the-docs-community[bot] read-the-docs-community[bot] commented on Nov 26, 2026 12:54 UTC
Bot

<!-- readthedocs-55693 -->

Documentation build overview

📚 CPython devguide | 🛠️ Build #36192864 | 📁 Comparing b585f2ac12baa5d0bbacd5d42bd94b1e9b4da9f6 against latest (e97d25fcc8aa308531597a75c4e865af56739365)

<kbd> &nbsp; 🔍 Preview build &nbsp; </kbd>

<details open>
<summary>2 files changed</summary>
<br>
<code>+</code> <a href="https://cpython-devguide--1989.org.readthedocs.build/developer-workflow/frozen-modules/index.html"><code>developer-workflow/frozen-modules/index.html</code></a><br>
<code>±</code> <a href="https://cpython-devguide--1989.org.readthedocs.build/genindex/index.html"><code>genindex/index.html</code></a><br>
</details>

StanFromIreland StanFromIreland commented on code on Nov 26, 2026 15:50 UTC
Code Review
developer-workflow/frozen-modules.rst:1
@@ -0,0 +1,124 @@
+.. _frozen-modules:
+
+==============
+Frozen modules
+==============
+
+A *frozen* module is a Python module whose compiled code is built into the
+interpreter. Its marshalled bytecode is stored as an array of bytes in a C
+header file and compiled into the executable, so importing it does not need to
+find and read a ``.py`` or ``.pyc`` file. Python 3.11 froze the modules that
+are essential for startup to make interpreter startup faster
+(see :ref:`What's New in 3.11 <whatsnew311-faster-startup>`).
+
+Frozen modules are imported by :class:`importlib.machinery.FrozenImporter`.
+Their module spec has the origin ``"frozen"``, and frames from their code
+show up in tracebacks as ``<frozen os>`` instead of a file name.
+You can ask :mod:`!_imp` whether a name is frozen with
+``_imp.is_frozen("os")``.
+
+Kinds of frozen modules
+=======================
+
+:cpy-file:`Python/frozen.c` defines three groups of frozen modules.
+
+* **Bootstrap modules** are needed to set up the import system itself.
+  They are :mod:`!importlib._bootstrap` (frozen as ``_frozen_importlib``),
+  :mod:`!importlib._bootstrap_external` (``_frozen_importlib_external``),
+  :mod:`zipimport` and ``_pybuiltins`` (from :cpy-file:`Lib/_pybuiltins.py`,
+  frozen with the ID ``builtins`` so that tracebacks show
+  ``<frozen builtins>``).
+  These are always used, even when frozen modules are turned off.
+* **Stdlib modules** are the standard library modules that are imported
+  during startup.
+  The list is grouped by why they are needed:
+  startup without :mod:`site` (``python -S``), startup with :mod:`site`,
+  the interactive interpreter, and running a module with ``-m``.
+  At the time of writing it contains for example :mod:`os`, :mod:`site`,
+  :mod:`io`, :mod:`codecs`, :mod:`abc`, :mod:`stat` and :mod:`runpy`.
+* **Test modules** exist only to test the frozen module machinery.
+  Like the stdlib modules, they are only used when frozen modules are on.
+  They are ``__hello__``, the package ``__phello__`` with its submodules,
+  a few aliases of them, and ``__hello_only__``, which has no source module
+  in the stdlib.
+
+The module ``getpath`` (:cpy-file:`Modules/getpath.py`) is also frozen,
+but it has its own rule in :cpy-file:`Makefile.pre.in`
+and is not part of the lists above.
+
+Finding and changing the frozen stdlib modules
+==============================================
+
+The source of truth is the ``FROZEN`` list at the top of
+:cpy-file:`Tools/build/freeze_modules.py`.
+Each entry has the form ``frozenid``, ``frozenid : modname`` or
+``frozenid : modname = pyfile``, and is placed in a section.
+The docstring of ``_parse_spec()`` in that file describes the syntax,
+including how to freeze packages and their submodules.
+:cpy-file:`Python/frozen.c` is mostly generated from this list.
+
+To add or remove a frozen module, edit the list and run::
+
+   make regen-frozen
+
+This runs ``Tools/build/freeze_modules.py``.
+According to the notes at the top of :cpy-file:`Python/frozen.c`,
+the script freezes the target modules, updates the includes and the module
+arrays in ``frozen.c``, updates the ``FROZEN_FILES`` variable and the
+per-module targets in :cpy-file:`Makefile.pre.in`, and updates the module
+lists in :cpy-file:`PCbuild/_freeze_module.vcxproj` and
+:cpy-file:`PCbuild/_freeze_module.vcxproj.filters`.
+Commit the changes to all of these files.
+The Makefile may have changed, so run ``make`` again afterwards.
+
+The frozen data itself, in ``Python/frozen_modules/*.h``, is always
+generated by the build and is not kept in the repository.
+Each header has a rule in :cpy-file:`Makefile.pre.in` that depends on the
+module's ``.py`` file, so a normal ``make`` refreshes the header after you
+edit the source of a frozen module.
+The data depends on the bytecode and marshal formats, so changes to the
+compiler, the bytecode or the marshal format need ``make regen-frozen``
+(the comment at the top of :cpy-file:`Python/frozen.c` says so).
+
+Not every module is frozen.
+Only the modules in the lists above are, and the sections show why they are

This is documenting implementation details which are likely to go out of date, let's drop this.

VanshajPoonia VanshajPoonia commented on code on Nov 26, 2026 16:04 UTC
Code Review
developer-workflow/frozen-modules.rst:1
@@ -0,0 +1,124 @@
+.. _frozen-modules:
+
+==============
+Frozen modules
+==============
+
+A *frozen* module is a Python module whose compiled code is built into the
+interpreter. Its marshalled bytecode is stored as an array of bytes in a C
+header file and compiled into the executable, so importing it does not need to
+find and read a ``.py`` or ``.pyc`` file. Python 3.11 froze the modules that
+are essential for startup to make interpreter startup faster
+(see :ref:`What's New in 3.11 <whatsnew311-faster-startup>`).
+
+Frozen modules are imported by :class:`importlib.machinery.FrozenImporter`.
+Their module spec has the origin ``"frozen"``, and frames from their code
+show up in tracebacks as ``<frozen os>`` instead of a file name.
+You can ask :mod:`!_imp` whether a name is frozen with
+``_imp.is_frozen("os")``.
+
+Kinds of frozen modules
+=======================
+
+:cpy-file:`Python/frozen.c` defines three groups of frozen modules.
+
+* **Bootstrap modules** are needed to set up the import system itself.
+  They are :mod:`!importlib._bootstrap` (frozen as ``_frozen_importlib``),
+  :mod:`!importlib._bootstrap_external` (``_frozen_importlib_external``),
+  :mod:`zipimport` and ``_pybuiltins`` (from :cpy-file:`Lib/_pybuiltins.py`,
+  frozen with the ID ``builtins`` so that tracebacks show
+  ``<frozen builtins>``).
+  These are always used, even when frozen modules are turned off.
+* **Stdlib modules** are the standard library modules that are imported
+  during startup.
+  The list is grouped by why they are needed:
+  startup without :mod:`site` (``python -S``), startup with :mod:`site`,
+  the interactive interpreter, and running a module with ``-m``.
+  At the time of writing it contains for example :mod:`os`, :mod:`site`,
+  :mod:`io`, :mod:`codecs`, :mod:`abc`, :mod:`stat` and :mod:`runpy`.
+* **Test modules** exist only to test the frozen module machinery.
+  Like the stdlib modules, they are only used when frozen modules are on.
+  They are ``__hello__``, the package ``__phello__`` with its submodules,
+  a few aliases of them, and ``__hello_only__``, which has no source module
+  in the stdlib.
+
+The module ``getpath`` (:cpy-file:`Modules/getpath.py`) is also frozen,
+but it has its own rule in :cpy-file:`Makefile.pre.in`
+and is not part of the lists above.
+
+Finding and changing the frozen stdlib modules
+==============================================
+
+The source of truth is the ``FROZEN`` list at the top of
+:cpy-file:`Tools/build/freeze_modules.py`.
+Each entry has the form ``frozenid``, ``frozenid : modname`` or
+``frozenid : modname = pyfile``, and is placed in a section.
+The docstring of ``_parse_spec()`` in that file describes the syntax,
+including how to freeze packages and their submodules.
+:cpy-file:`Python/frozen.c` is mostly generated from this list.
+
+To add or remove a frozen module, edit the list and run::
+
+   make regen-frozen
+
+This runs ``Tools/build/freeze_modules.py``.
+According to the notes at the top of :cpy-file:`Python/frozen.c`,
+the script freezes the target modules, updates the includes and the module
+arrays in ``frozen.c``, updates the ``FROZEN_FILES`` variable and the
+per-module targets in :cpy-file:`Makefile.pre.in`, and updates the module
+lists in :cpy-file:`PCbuild/_freeze_module.vcxproj` and
+:cpy-file:`PCbuild/_freeze_module.vcxproj.filters`.
+Commit the changes to all of these files.
+The Makefile may have changed, so run ``make`` again afterwards.
+
+The frozen data itself, in ``Python/frozen_modules/*.h``, is always
+generated by the build and is not kept in the repository.
+Each header has a rule in :cpy-file:`Makefile.pre.in` that depends on the
+module's ``.py`` file, so a normal ``make`` refreshes the header after you
+edit the source of a frozen module.
+The data depends on the bytecode and marshal formats, so changes to the
+compiler, the bytecode or the marshal format need ``make regen-frozen``
+(the comment at the top of :cpy-file:`Python/frozen.c` says so).
+
+Not every module is frozen.
+Only the modules in the lists above are, and the sections show why they are

Done! Thank you :D

Assignees
VanshajPoonia VanshajPoonia
Labels
risk: low confidence: 90.6% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 33% (LOW) · Higher = larger blast radius
33%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 90.6% · Lower = rushed or shallow review
90.6%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 3.1% · Safe to merge
3.1%