]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-139707: Add docs for optional modules (GH-140171)
authorPetr Viktorin <encukou@gmail.com>
Thu, 6 Nov 2025 10:49:44 +0000 (11:49 +0100)
committerGitHub <noreply@github.com>
Thu, 6 Nov 2025 10:49:44 +0000 (11:49 +0100)
Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
Co-authored-by: Emma Smith <emma@emmatyping.dev>
Co-authored-by: Author: Terry Jan Reedy <tjreedy@udel.edu>
Co-authored-by: Victor Stinner <vstinner@python.org>
20 files changed:
Doc/glossary.rst
Doc/includes/optional-module.rst [new file with mode: 0644]
Doc/library/bz2.rst
Doc/library/compression.zstd.rst
Doc/library/ctypes.rst
Doc/library/curses.rst
Doc/library/ensurepip.rst
Doc/library/gzip.rst
Doc/library/idle.rst
Doc/library/lzma.rst
Doc/library/readline.rst
Doc/library/sqlite3.rst
Doc/library/ssl.rst
Doc/library/tarfile.rst
Doc/library/tkinter.rst
Doc/library/turtle.rst
Doc/library/zipfile.rst
Doc/library/zlib.rst
Doc/using/configure.rst
Doc/using/unix.rst

index c0ca0be304ebe4e55a91a582598f4a23dc7bd050..a4066d42927f64e67de0b15c00b1af47373e0c5a 100644 (file)
@@ -1025,6 +1025,15 @@ Glossary
       applied to all scopes, only those relying on a known set of local
       and nonlocal variable names are restricted to optimized scopes.
 
+   optional module
+      An :term:`extension module` that is part of the :term:`standard library`,
+      but may be absent in some builds of :term:`CPython`,
+      usually due to missing third-party libraries or because the module
+      is not available for a given platform.
+
+      See :ref:`optional-module-requirements` for a list of optional modules
+      that require third-party libraries.
+
    package
       A Python :term:`module` which can contain submodules or recursively,
       subpackages.  Technically, a package is a Python module with a
diff --git a/Doc/includes/optional-module.rst b/Doc/includes/optional-module.rst
new file mode 100644 (file)
index 0000000..262e73f
--- /dev/null
@@ -0,0 +1,9 @@
+This is an :term:`optional module`.
+If it is missing from your copy of CPython,
+look for documentation from your distributor (that is,
+whoever provided Python to you).
+If you are the distributor, see :ref:`optional-module-requirements`.
+
+.. Similar notes appear in the docs of the modules:
+   - zipfile
+   - tarfile
index ebe2e43febaefa0b11be8e2f61b5d256e09928c1..12650861c0fb5dafbd4dde0687944f4b33b4854a 100644 (file)
@@ -25,6 +25,8 @@ The :mod:`bz2` module contains:
 * The :func:`compress` and :func:`decompress` functions for one-shot
   (de)compression.
 
+.. include:: ../includes/optional-module.rst
+
 
 (De)compression of files
 ------------------------
index a901403621b84f8ebc763b3064027126f123f35a..89b6fe540f5ba7dbed3cbbf93f456f9c11071559 100644 (file)
@@ -33,6 +33,8 @@ The :mod:`!compression.zstd` module contains:
 * The :class:`CompressionParameter`, :class:`DecompressionParameter`, and
   :class:`Strategy` classes for setting advanced (de)compression parameters.
 
+.. include:: ../includes/optional-module.rst
+
 
 Exceptions
 ----------
index d8dac24c8ab532b2713f2f5f9356b47c6e483f2c..9c0b246c095483c0257d595fbc241b9761ea8b7d 100644 (file)
@@ -14,6 +14,8 @@
 data types, and allows calling functions in DLLs or shared libraries.  It can be
 used to wrap these libraries in pure Python.
 
+.. include:: ../includes/optional-module.rst
+
 
 .. _ctypes-ctypes-tutorial:
 
index e60197ddd89adbc75000e4b58cd9410ebca801b5..057d338edda92a4ea0b37edf7255aa31039432c4 100644 (file)
@@ -23,6 +23,8 @@ Linux and the BSD variants of Unix.
 
 .. include:: ../includes/wasm-mobile-notavail.rst
 
+.. include:: ../includes/optional-module.rst
+
 .. note::
 
    Whenever the documentation mentions a *character* it can be specified
index fa102c4a08010367276d4cb3fa91a1446edc5779..165b9a9f823154c008f52d8afa2a235ae124cb19 100644 (file)
@@ -30,6 +30,8 @@ when creating a virtual environment) or after explicitly uninstalling
    needed to bootstrap ``pip`` are included as internal parts of the
    package.
 
+.. include:: ../includes/optional-module.rst
+
 .. seealso::
 
    :ref:`installing-index`
index 4bdcec66088db206df9de4c39361eba929505558..cb36be42a83f12a44a19a7867b699cc16e64b67f 100644 (file)
@@ -11,6 +11,8 @@
 This module provides a simple interface to compress and decompress files just
 like the GNU programs :program:`gzip` and :program:`gunzip` would.
 
+.. include:: ../includes/optional-module.rst
+
 The data compression is provided by the :mod:`zlib` module.
 
 The :mod:`gzip` module provides the :class:`GzipFile` class, as well as the
index 10ec7f0a6f14c90a56e92970ca39ee768d6cde44..52e3726a0f5af5bb1c32aac1f19f0fd8fd2671aa 100644 (file)
@@ -37,6 +37,10 @@ IDLE has the following features:
 
 * configuration, browsers, and other dialogs
 
+The IDLE application is implemented in the :mod:`idlelib` package.
+
+.. include:: ../includes/optional-module.rst
+
 Menus
 -----
 
index 69f7cb8d48d7aeef19be4a2d94fdb2c93bfd5778..8a4f68f3502521633a7850f7117a5f9a36d6eecc 100644 (file)
@@ -23,6 +23,8 @@ module. Note that :class:`LZMAFile` and :class:`bz2.BZ2File` are *not*
 thread-safe, so if you need to use a single :class:`LZMAFile` instance
 from multiple threads, it is necessary to protect it with a lock.
 
+.. include:: ../includes/optional-module.rst
+
 
 .. exception:: LZMAError
 
index f649fce5efc3779b9fa3a986f8395d93a3f4f897..75db832c546b64f1d7a5a8bc4cdc891495cf3d4f 100644 (file)
@@ -26,6 +26,8 @@ Readline library in general.
 
 .. include:: ../includes/wasm-mobile-notavail.rst
 
+.. include:: ../includes/optional-module.rst
+
 .. note::
 
   The underlying Readline library API may be implemented by
index 9d56e81dee10d53ffd634b9a084c64ee68c738fd..3b1a9c2f6eefe9ff9f909df2f021870a0769f60a 100644 (file)
@@ -31,7 +31,9 @@ PostgreSQL or Oracle.
 
 The :mod:`!sqlite3` module was written by Gerhard Häring.  It provides an SQL interface
 compliant with the DB-API 2.0 specification described by :pep:`249`, and
-requires SQLite 3.15.2 or newer.
+requires the third-party `SQLite <https://sqlite.org/>`_ library.
+
+.. include:: ../includes/optional-module.rst
 
 This document includes four main sections:
 
index e0d85c852fa655fa6df3641a68621ac4d6dcef21..fa0a52347204226028f6ce7a096de4b7f88b2b7d 100644 (file)
@@ -18,8 +18,9 @@
 This module provides access to Transport Layer Security (often known as "Secure
 Sockets Layer") encryption and peer authentication facilities for network
 sockets, both client-side and server-side.  This module uses the OpenSSL
-library. It is available on all modern Unix systems, Windows, macOS, and
-probably additional platforms, as long as OpenSSL is installed on that platform.
+library.
+
+.. include:: ../includes/optional-module.rst
 
 .. note::
 
index c4614bf28a4aeaf32ddff5f9f1f6efeaf447f407..5ff8502bbe219fd99dcf1cdbf8e98c1ae18a5125 100644 (file)
@@ -21,6 +21,14 @@ Some facts and figures:
 * reads and writes :mod:`gzip`, :mod:`bz2`, :mod:`compression.zstd`, and
   :mod:`lzma` compressed archives if the respective modules are available.
 
+  ..
+     The following paragraph should be similar to ../includes/optional-module.rst
+
+  If any of these :term:`optional modules <optional module>` are missing from
+  your copy of CPython, look for documentation from your distributor (that is,
+  whoever provided Python to you).
+  If you are the distributor, see :ref:`optional-module-requirements`.
+
 * read/write support for the POSIX.1-1988 (ustar) format.
 
 * read/write support for the GNU tar format including *longname* and *longlink*
index 22e08c45d01ef913547b7967f6f9975df86162d5..81177533be84c980d2249587d2df9ff9bc0cd588 100644 (file)
@@ -36,6 +36,8 @@ details that are unchanged.
    Most documentation you will find online still uses the old API and
    can be woefully outdated.
 
+.. include:: ../includes/optional-module.rst
+
 .. seealso::
 
    * `TkDocs <https://tkdocs.com/>`_
index b687231bd489cc3813f4d5333e9e74264a40d145..58b99e0d44173af59649eee9b325383d960d4be5 100644 (file)
@@ -29,6 +29,8 @@ introduced in Logo <https://en.wikipedia.org/wiki/Turtle_
 (robot)>`_, developed by Wally Feurzeig, Seymour Papert and Cynthia Solomon
 in 1967.
 
+.. include:: ../includes/optional-module.rst
+
 
 Get started
 ===========
index f6ec33640b60d25c5cb65aa0d25cd1dde6d3753a..5a8bbc8c1aedf7f4bd04686dbaaf1bf112c79ff3 100644 (file)
@@ -23,6 +23,16 @@ decryption of encrypted files in ZIP archives, but it currently cannot
 create an encrypted file.  Decryption is extremely slow as it is
 implemented in native Python rather than C.
 
+..
+   The following paragraph should be similar to ../includes/optional-module.rst
+
+Handling compressed archives requires :term:`optional modules <optional module>`
+such as :mod:`zlib`, :mod:`bz2`, :mod:`lzma`, and :mod:`compression.zstd`.
+If any of them are missing from your copy of CPython,
+look for documentation from your distributor (that is,
+whoever provided Python to you).
+If you are the distributor, see :ref:`optional-module-requirements`.
+
 The module defines the following items:
 
 .. exception:: BadZipFile
index b961f7113d3686b263219e51b4f774c1232e63ac..ce0a22b9456d0b1f7d1793cf1582647238a35691 100644 (file)
@@ -8,9 +8,9 @@
 --------------
 
 For applications that require data compression, the functions in this module
-allow compression and decompression, using the zlib library. The zlib library
-has its own home page at https://www.zlib.net.  zlib 1.2.2.1 is the minium
-supported version.
+allow compression and decompression, using the `zlib library <https://www.zlib.net>`_.
+
+.. include:: ../includes/optional-module.rst
 
 zlib's functions have many options and often need to be used in a particular
 order.  This documentation doesn't attempt to cover all of the permutations;
index 1f773a3a547c2b36dd1ea26bb03aed2902551b04..cdadbe51417499588453edbcb7e5028417c97e77 100644 (file)
@@ -4,10 +4,13 @@ Configure Python
 
 .. highlight:: sh
 
+
+.. _build-requirements:
+
 Build Requirements
 ==================
 
-Features and minimum versions required to build CPython:
+To build CPython, you will need:
 
 * A `C11 <https://en.cppreference.com/w/c/11>`_ compiler. `Optional C11
   features
@@ -22,83 +25,136 @@ Features and minimum versions required to build CPython:
 
 * Support for threads.
 
-To build optional modules:
-
-* `libbz2 <https://sourceware.org/bzip2/>`_ for the :mod:`bz2` module.
-
-* `libb2 <https://github.com/BLAKE2/libb2>`_ (:ref:`BLAKE2 <hashlib-blake2>`)
-  for the :mod:`hashlib` module.
-
-* `libffi <https://sourceware.org/libffi/>`_ 3.3.0 is the recommended
-  minimum version for the :mod:`ctypes` module.
-
-* ``liblzma`` for the :mod:`lzma` module.
-
-* `libmpdec <https://www.bytereef.org/mpdecimal/doc/libmpdec/>`_ 2.5.0
-  for the :mod:`decimal` module.
-
-* ``libncurses`` or ``libncursesw`` for the :mod:`curses` module.
-
-* ``libpanel`` or ``libpanelw`` for the :mod:`curses.panel` module.
-
-* `libreadline <https://tiswww.case.edu/php/chet/readline/rltop.html>`_ or
-  `libedit <https://www.thrysoee.dk/editline/>`_
-  for the :mod:`readline` module.
-
-* `libuuid <https://linux.die.net/man/3/libuuid>`_ for the :mod:`uuid` module.
-
-* `OpenSSL <https://www.openssl.org/>`_ 1.1.1 is the minimum version and
-  OpenSSL 3.0.18 is the recommended minimum version for the
-  :mod:`ssl` and :mod:`hashlib` extension modules.
+.. versionchanged:: 3.5
+   On Windows, Visual Studio 2015 or later is now required.
 
-* `SQLite <https://sqlite.org/>`_ 3.15.2 for the :mod:`sqlite3` extension module.
+.. versionchanged:: 3.6
+   Selected C99 features, like ``<stdint.h>`` and ``static inline`` functions,
+   are now required.
 
-* `Tcl/Tk <https://www.tcl-lang.org/>`_ 8.5.12 for the :mod:`tkinter` module.
+.. versionchanged:: 3.7
+   Thread support is now required.
 
-* `zlib <https://www.zlib.net>`_ 1.2.2.1 is the minimum version for the
-  :mod:`zlib` module.
+.. versionchanged:: 3.11
+   C11 compiler, IEEE 754 and NaN support are now required.
+   On Windows, Visual Studio 2017 or later is required.
 
-* `zstd <https://facebook.github.io/zstd/>`_ 1.4.5 is the minimum version for
-  the :mod:`compression.zstd` module.
+See also :pep:`7` "Style Guide for C Code" and :pep:`11` "CPython platform
+support".
 
-For a full list of dependencies required to build all modules and how to install
-them, see the
-`devguide <https://devguide.python.org/getting-started/setup-building/#install-dependencies>`_.
 
-* Autoconf 2.72 and aclocal 1.16.5 are required to regenerate the
-  :file:`configure` script.
+.. _optional-module-requirements:
+
+Requirements for optional modules
+---------------------------------
+
+Some :term:`optional modules <optional module>` of the standard library
+require third-party libraries installed for development
+(for example, header files must be available).
+
+Missing requirements are reported in the ``configure`` output.
+Modules that are missing due to missing dependencies are listed near the end
+of the ``make`` output,
+sometimes using an internal name, for example, ``_ctypes`` for :mod:`ctypes`
+module.
+
+If you distribute a CPython interpreter without optional modules,
+it's best practice to advise users, who generally expect that
+standard library modules are available.
+
+Dependencies to build optional modules are:
+
+.. list-table::
+   :header-rows: 1
+   :align: left
+
+   * - Dependency
+     - Minimum version
+     - Python module
+   * - `libbz2 <https://sourceware.org/bzip2/>`_
+     -
+     - :mod:`bz2`
+   * - `libffi <https://sourceware.org/libffi/>`_
+     - 3.3.0 recommended
+     - :mod:`ctypes`
+   * - `liblzma <https://tukaani.org/xz/>`_
+     -
+     - :mod:`lzma`
+   * - `libmpdec <https://www.bytereef.org/mpdecimal/doc/libmpdec/>`_
+     - 2.5.0
+     - :mod:`decimal` [1]_
+   * - `libreadline <https://tiswww.case.edu/php/chet/readline/rltop.html>`_ or
+       `libedit <https://www.thrysoee.dk/editline/>`_ [2]_
+     -
+     - :mod:`readline`
+   * - `libuuid <https://linux.die.net/man/3/libuuid>`_
+     -
+     - ``_uuid`` [3]_
+   * - `ncurses <https://gnu.org/software/ncurses/ncurses.html>`_ [4]_
+     -
+     - :mod:`curses`
+   * - `OpenSSL <https://openssl-library.org/>`_
+     - | 3.0.18 recommended
+       | (1.1.1 minimum)
+     - :mod:`ssl`, :mod:`hashlib` [5]_
+   * - `SQLite <https://sqlite.org/>`_
+     - 3.15.2
+     - :mod:`sqlite3`
+   * - `Tcl/Tk <https://www.tcl-lang.org/>`_
+     - 8.5.12
+     - :mod:`tkinter`, :ref:`IDLE <idle>`, :mod:`turtle`
+   * - `zlib <https://www.zlib.net>`_
+     - 1.2.2.1
+     - :mod:`zlib`, :mod:`gzip`, :mod:`ensurepip`
+   * - `zstd <https://facebook.github.io/zstd/>`_
+     - 1.4.5
+     - :mod:`compression.zstd`
+
+.. [1] If *libmpdec* is not available, the :mod:`decimal` module will use
+   a pure-Python implementation.
+   See :option:`--with-system-libmpdec` for details.
+.. [2] See :option:`--with-readline` for choosing the backend for the
+   :mod:`readline` module.
+.. [3] The :mod:`uuid` module uses ``_uuid`` to generate "safe" UUIDs.
+   See the module documentation for details.
+.. [4] The :mod:`curses` module requires the ``libncurses`` or ``libncursesw``
+   library.
+   The :mod:`curses.panel` module additionally requires the ``libpanel`` or
+   ``libpanelw`` library.
+.. [5] If OpenSSL is not available, the :mod:`hashlib` module will use
+   bundled implementations of several hash functions.
+   See :option:`--with-builtin-hashlib-hashes` for *forcing* usage of OpenSSL.
+
+Note that the table does not include all optional modules; in particular,
+platform-specific modules like :mod:`winreg` are not listed here.
+
+.. seealso::
+
+   * The `devguide <https://devguide.python.org/getting-started/setup-building/#install-dependencies>`_
+     includes a full list of dependencies required to build all modules and
+     instructions on how to install them on common platforms.
+   * :option:`--with-system-expat` allows building with an external
+     `libexpat <https://libexpat.github.io/>`_ library.
+   * :ref:`configure-options-for-dependencies`
 
 .. versionchanged:: 3.1
-   Tcl/Tk version 8.3.1 is now required.
+   Tcl/Tk version 8.3.1 is now required for :mod:`tkinter`.
 
 .. versionchanged:: 3.5
-   On Windows, Visual Studio 2015 or later is now required.
-   Tcl/Tk version 8.4 is now required.
-
-.. versionchanged:: 3.6
-   Selected C99 features are now required, like ``<stdint.h>`` and ``static
-   inline`` functions.
+   Tcl/Tk version 8.4 is now required for :mod:`tkinter`.
 
 .. versionchanged:: 3.7
-   Thread support and OpenSSL 1.0.2 are now required.
+   OpenSSL 1.0.2 is now required for :mod:`hashlib` and :mod:`ssl`.
 
 .. versionchanged:: 3.10
-   OpenSSL 1.1.1 is now required.
-   Require SQLite 3.7.15.
+   OpenSSL 1.1.1 is now required for :mod:`hashlib` and :mod:`ssl`.
+   SQLite 3.7.15 is now required for :mod:`sqlite3`.
 
 .. versionchanged:: 3.11
-   C11 compiler, IEEE 754 and NaN support are now required.
-   On Windows, Visual Studio 2017 or later is required.
-   Tcl/Tk version 8.5.12 is now required for the :mod:`tkinter` module.
+   Tcl/Tk version 8.5.12 is now required for :mod:`tkinter`.
 
 .. versionchanged:: 3.13
-   Autoconf 2.71, aclocal 1.16.5 and SQLite 3.15.2 are now required.
-
-.. versionchanged:: 3.14
-   Autoconf 2.72 is now required.
-
-See also :pep:`7` "Style Guide for C Code" and :pep:`11` "CPython platform
-support".
+   SQLite 3.15.2 is now required for :mod:`sqlite3`.
 
 
 Generated files
@@ -127,8 +183,19 @@ The container is optional, the following command can be run locally::
 
     autoreconf -ivf -Werror
 
-The generated files can change depending on the exact ``autoconf-archive``,
-``aclocal`` and ``pkg-config`` versions.
+The generated files can change depending on the exact versions of the
+tools used.
+The container that CPython uses has
+`Autoconf <https://gnu.org/software/autoconf>`_ 2.72,
+``aclocal`` from `Automake <https://www.gnu.org/software/automake>`_ 1.16.5,
+and `pkg-config <https://www.freedesktop.org/wiki/Software/pkg-config/>`_ 1.8.1.
+
+.. versionchanged:: 3.13
+   Autoconf 2.71 and aclocal 1.16.5 and are now used to regenerate
+   :file:`configure`.
+
+.. versionchanged:: 3.14
+   Autoconf 2.72 is now used to regenerate :file:`configure`.
 
 
 .. _configure-options:
@@ -409,6 +476,8 @@ Linker options
    Name for machine-dependent library files.
 
 
+.. _configure-options-for-dependencies:
+
 Options for third-party dependencies
 ------------------------------------
 
@@ -431,12 +500,6 @@ Options for third-party dependencies
 
    C compiler and linker flags for ``gdbm``.
 
-.. option:: LIBB2_CFLAGS
-.. option:: LIBB2_LIBS
-
-   C compiler and linker flags for ``libb2`` (:ref:`BLAKE2 <hashlib-blake2>`),
-   used by :mod:`hashlib` module, overriding ``pkg-config``.
-
 .. option:: LIBEDIT_CFLAGS
 .. option:: LIBEDIT_LIBS
 
@@ -902,6 +965,13 @@ Libraries options
    .. versionchanged:: 3.13
       Default to using the installed ``mpdecimal`` library.
 
+   .. versionchanged:: 3.15
+
+      A bundled copy of the library will no longer be selected
+      implicitly if an installed ``mpdecimal`` library is not found.
+      In Python 3.15 only, it can still be selected explicitly using
+      ``--with-system-libmpdec=no`` or ``--without-system-libmpdec``.
+
    .. deprecated-removed:: 3.13 3.16
       A copy of the ``mpdecimal`` library sources will no longer be distributed
       with Python 3.16.
index 9ec4e3419321a4e6d569a416647e0c8c2381f494..a9950ef75254976299eb47831946dfe27136dbd2 100644 (file)
@@ -84,11 +84,17 @@ On FreeBSD and OpenBSD
 Building Python
 ===============
 
+.. seealso::
+
+   If you want to contribute to CPython, refer to the
+   `devguide <https://devguide.python.org/getting-started/setup-building/>`_,
+   which includes build instructions and other tips on setting up environment.
+
 If you want to compile CPython yourself, first thing you should do is get the
 `source <https://www.python.org/downloads/source/>`_. You can download either the
-latest release's source or just grab a fresh `clone
-<https://devguide.python.org/setup/#get-the-source-code>`_.  (If you want
-to contribute patches, you will need a clone.)
+latest release's source or grab a fresh `clone
+<https://devguide.python.org/setup/#get-the-source-code>`_.
+You will also need to install the :ref:`build requirements <build-requirements>`.
 
 The build process consists of the usual commands::