Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,7 @@ peps/pep-0771.rst @pradyunsg
peps/pep-0772.rst @warsaw @pradyunsg
peps/pep-0773.rst @zooba
peps/pep-0774.rst @savannahostrowski
peps/pep-0775.rst @encukou
# ...
peps/pep-0777.rst @warsaw
# ...
Expand Down
139 changes: 139 additions & 0 deletions peps/pep-0775.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
PEP: 775
Title: Make zlib required to build CPython
Author: Gregory P. Smith <greg@krypto.org>,
Stan Ulbrych <stanulbrych@gmail.com>,
Petr Viktorin <encukou@gmail.com>
Discussions-To: https://discuss.python.org/t/23062
Status: Draft
Type: Standards Track
Created: 24-Feb-2025
Python-Version: 3.14
Post-History: `23-Jan-2023 <https://discuss.python.org/t/23062>`__


Abstract
========

Building CPython without the `zlib <https://zlib.net>`_ compression library
will no be longer supported, and the :mod:`zlib` module will be required in
the standard library.
The only exception is `WASI <https://wasi.dev>`_, as zlib is not currently
supported in CPython on WASI.
Building the interpreter without zlib may still be possible,
but formally unsupported.


Motivation
==========

The zlib library, which powers the :mod:`!zlib` Python module,
is available on all supported systems except WASI.

Many wheels on PyPI, including the :pypi:`pip` installer, require zlib.
Users of pip would consider CPython without zlib to be broken,
but mostly don't notice because all major builds of CPython include zlib.

CPython developers don't really notice either. It turns out that at the time
of writing, at least one CPython test fails without zlib (the "skip"
decorator in ``test_peg_generator.test_c_parser`` is applied too late),
but our CI didn't catch this.

This PEP treats this as an issue in documentation and messaging.
In practice, we already don't support building CPython without zlib; we
should just say so.


Rationale
=========

There are possible use cases for zlib-less builds, such as embedding and
bootstrapping, as well as unforeseen ones.
Therefore, we don't *remove* support for zlib-less systems; we mark them
unsupported and invite affected users to do their own testing, or to share
use cases that can make us reconsider this decision.

zlib is not yet used by default on the WASI platform -- mostly because
adding it hasn't yet been a priority there. (Note that `Pyodide`_, the main
"real-world" CPython distribution for WASI, does include zlib.)
We take this as an opportunity to continue testing a platform without
zlib, so that we don't unintentionally break unsupported builds yet.

.. _Pyodide: https://pyodide.org


Specification
=============

In standard library modules that use zlib for optional functionality,
that functionality will raise ``ImportError`` when used.
Code to generate more "friendly" error messages, or to pre-check whether
zlib is available, will be removed.
All functionality unrelated to zlib will still be usable if zlib is
missing.

This affects the following modules, and more that depend on these
transitively:

* :mod:`shutil` (``gztar`` and ``zip`` archive formats)
* :mod:`tarfile`, :mod:`zipfile`, :mod:`zipimport`,
:mod:`zipapp` (archive compression)
* :mod:`codecs` (``zlib_codec``)

``shutil.get_archive_formats()`` will always include ``zip`` and ``gztar``
as registered formats, even if they are unusable due to missing zlib.

The ``configure`` script will issue a warning when zlib is not found on
platforms other than WASI.

``test_zlib`` will fail on platforms other than WASI.
All other tests will continue to be skipped -- that is, uses of
``@test.support.requires_zlib`` will be kept in place -- for the benefit
of WASI, unsupported builds, and any possible reverts.

:pep:`11` will be adjusted to mark "Systems without zlib, except WASI" as
unsupported.


Backwards Compatibility
=======================

In practice, nothing major changes, except in error cases -- for example,
attempts to use tar compression without zlib available will raise
``ImportError`` and not ``CompressionError``.


Security Implications
=====================

None known.


How to Teach This
=================

We don't expect that any instructions will need to change, as zlib is
already available in all relevant contexts.


Reference Implementation
========================

A reference implementation may be found in a pull request to the CPython
repository, `python/cpython#130297
<https://github.com/python/cpython/pull/130297>`_


Future work
===========

In the future, if no use cases for zlib-less builds are found,
zlib may be made fully required.
The main changes needed for that would be making the ``configure`` script
raise a hard error, and removing ``@test.support.requires_zlib``.


Copyright
=========

This document is placed in the public domain or under the
CC0-1.0-Universal license, whichever is more permissive.