Movatterモバイル変換


[0]ホーム

URL:


Following system colour schemeSelected dark colour schemeSelected light colour scheme

Python Enhancement Proposals

PEP 594 – Removing dead batteries from the standard library

Author:
Christian Heimes <christian at python.org>,Brett Cannon <brett at python.org>
Discussions-To:
Discourse thread
Status:
Final
Type:
Standards Track
Created:
20-May-2019
Python-Version:
3.11
Post-History:
21-May-2019, 04-Feb-2022
Resolution:
Discourse message

Table of Contents

Abstract

This PEP proposed a list of standard library modules to be removed from thestandard library. The modules are mostly historic data formats (e.g. Commodoreand SUN file formats), APIs and operating systems that have been superseded along time ago (e.g. Mac OS 9), or modules that have security implications andbetter alternatives (e.g. password and login).

The PEP follows in the footsteps of other PEPS likePEP 3108. TheStandard Library Reorganization proposal removed a bunch of modules fromPython 3.0. In 2007, the PEP referred to maintenance burden as:

“Over the years, certain modules have become a heavy burden upon python-devto maintain. In situations like this, it is better for the module to begiven to the community to maintain to free python-dev to focus more onlanguage support and other modules in the standard library that do not takeup an undue amount of time and effort.”

The withdrawnPEP 206 from 2000 expresses issues with the Python standardlibrary in an unvarnished and forthright manner:

“[…] the standard library modules aren’t always the best choices for ajob. Some library modules were quick hacks (e.g.calendar,commands), some were designed poorly and are now near-impossible tofix (cgi), and some have been rendered obsolete by other, more completemodules […].”

Rationale

Back in the early days of Python, the interpreter came with a large set ofuseful modules. This was often referred to as “batteries included”philosophy and was one of the cornerstones to Python’s success story.Users didn’t have to figure out how to download and install separatepackages in order to write a simple web server or parse email.

Times have changed. With the introduction of PyPI (née Cheeseshop), setuptools,and later pip, it became simple and straightforward to download and installpackages. Nowadays Python has a rich and vibrant ecosystem of third-partypackages. It’s pretty much standard to either install packages from PyPI oruse one of the many Python or Linux distributions.

On the other hand, Python’s standard library is piling up with cruft, unnecessaryduplication of functionality, and dispensable features. This is undesirablefor several reasons.

  • Any additional module increases the maintenance cost for the Python coredevelopment team. The team has limited resources, reduced maintenance costfrees development time for other improvements.
  • Modules in the standard library are generally favored and seen as thede facto solution for a problem. A majority of users only pick third-partymodules to replace a stdlib module, when they have a compelling reason, e.g.lxml instead ofxml. The removal of an unmaintained stdlib moduleincreases the chances of a community-contributed module to become widelyused.
  • A lean and mean standard library benefits platforms with limited resourceslike devices with just a few hundred kilobyte of storage (e.g. BBCMicro:bit). Python on mobile platforms like BeeWare or WebAssembly(e.g. pyodide) also benefit from reduced download size.

The modules in this PEP have been selected for deprecation because theirremoval is either least controversial or most beneficial. For example,least controversial are 30-year-old multimedia formats like thesunauaudio format, which was used on SPARC and NeXT workstations in the late1980s. Thecrypt module has fundamental flaws that are better solvedoutside the standard library.

This PEP also designates some modules as not scheduled for removal. Somemodules have been deprecated for several releases or seem unnecessary atfirst glance. However it is beneficial to keep the modules in the standardlibrary, mostly for environments where installing a package from PyPI is notan option. This can be corporate environments or classrooms where externalcode is not permitted without legal approval.

  • The usage of FTP is declining, but some files are still provided overthe FTP protocol or hosters offer FTP to upload content. Therefore,ftplib is going to stay.
  • Theoptparse andgetopt modules are widely used. They are maturemodules with very low maintenance overhead.
  • According to David Beazley[5] thewave module is easy to teach tokids and can make crazy sounds. Making a computer generate sounds is apowerful and highly motivating exercise for a nine-year-old aspiring developer.It’s a fun battery to keep.

Deprecation schedule

3.11

Starting with Python 3.11, deprecated modules will start issuingDeprecationWarning. The estimated EOL of Python 3.10, the lastversion without the warning, is October 2026.

3.12

There should be no specific change compared to Python 3.11.This is the last version of Python with the deprecated modules,with an estimated EOL of October 2028.

3.13

All modules deprecated by this PEP are removed from themain branchof the CPython repository and are no longer distributed as part of Python.

Deprecated modules

The modules are grouped as data encoding, multimedia, network, OS interface,and misc modules. The majority of modules are for old data formats orold APIs. Some others are rarely useful and have better replacements onPyPI, e.g. Pillow for image processing or NumPy-based projects to deal withaudio processing.

Table 1: Proposed modules deprecations
ModuleDeprecated inTo be removedAdded inHas maintainer?Replacement
aifc3.11 (3.0*)3.131993yes (inactive)-
asynchat3.6 (3.0*)3.121999yesasyncio
asyncore3.6 (3.0*)3.121999yesasyncio
audioop3.11 (3.0*)3.131992yes-
cgi3.11 (2.0**)3.131995no-
cgitb3.11 (2.0**)3.131995no-
chunk3.113.131999no-
crypt3.113.131994yes (inactive)legacycrypt,bcrypt,argon2-cffi,hashlib,passlib
imghdr3.113.131992nofiletype,puremagic,python-magic
mailcap3.113.131995no-
msilib3.113.132006no-
nntplib3.113.131992no-
nis3.11 (3.0*)3.131992no-
ossaudiodev3.113.132002no-
pipes3.113.131992nosubprocess
smtpd3.4.7,3.5.43.122001yesaiosmtpd
sndhdr3.113.131994nofiletype,puremagic,python-magic
spwd3.113.132005nopython-pam
sunau3.11 (3.0*)3.131993no-
telnetlib3.11 (3.0*)3.131997notelnetlib3,Exscript
uu3.113.131994no-
xdrlib3.113.131992/1996no-

Some module deprecations proposed byPEP 3108 for 3.0 andPEP 206 for2.0. Theadded in column illustrates, when a module was originally designedand added to the standard library. Thehas maintainer column refers to theexpert index, a list of domainexperts and maintainers in the DevGuide.

Data encoding modules

uu and the uu encoding

Theuu module providesuuencode format, an old binary encoding format for email from 1980. The uuformat has been replaced by MIME. The uu codec is provided by thebinasciimodule. There’s alsoencodings/uu_codec.py which is a codec for thesame encoding; it should also be deprecated.

xdrlib

Thexdrlib module supportsthe Sun External Data Representation Standard. XDR is an old binaryserialization format from 1987. These days it’s rarely used outsidespecialized domains like NFS.

Multimedia modules

aifc

Theaifc module providessupport for reading and writing AIFF and AIFF-C files. The Audio InterchangeFile Format is an old audio format from 1988 based on Amiga IFF. It was mostcommonly used on the Apple Macintosh. These days only few specializedapplication use AIFF.

A user disclosed[6] that the post production film industry makes heavyuse of the AIFC file format. The usage of theaifc module in closed sourceand internal software was unknown prior to the first posting of this PEP. Thismay be a compelling argument to keep theaifc module in the standardlibrary. The file format is stable and the module does not require muchmaintenance. The strategic benefits for Python may outmatch the burden.

audioop

Theaudioop modulecontains helper functions to manipulate raw audio data and adaptivedifferential pulse-code modulated audio data. The module is implemented inC without any additional dependencies. Theaifc,sunau, andwavemodules depend onaudioop for some operations.

The byteswap operation in thewave module can be substituted with littleextra work. In caseaifc is not deprecated as well, a reduced version oftheaudioop module is converted into a private implementation detail,e.g._audioop withbyteswap,alaw2lin,ulaw2lin,lin2alaw,lin2ulaw, andlin2adpcm.

chunk

Thechunk module providessupport for reading and writing Electronic Arts’ Interchange File Format.IFF is an old audio file format originally introduced for Commodore andAmiga. The format is no longer relevant.

imghdr

Theimghdr module is asimple tool to guess the image file format from the first 32 bytesof a file or buffer. It supports only a limited number of formats andneither returns resolution nor color depth.

ossaudiodev

Theossaudiodevmodule provides support for Open Sound System, an interface to soundplayback and capture devices. OSS was initially free software, but latersupport for newer sound devices and improvements were proprietary. Linuxcommunity abandoned OSS in favor of ALSA[1]. Some operating systems likeOpenBSD and NetBSD provide an incomplete[2] emulation of OSS.

To best of my knowledge, FreeBSD is the only widespread operating systemthat uses Open Sound System as of today. Theossaudiodev hasn’t seen anyimprovements or new features since 2003. All commits since 2003 areproject-wide code cleanups and a couple of bug fixes. It would be beneficialfor both FreeBSD community and core development, if the module would bemaintained and distributed by people that care for it and use it.

The standard library used to have more audio-related modules. The otheraudio device interfaces (audiodev,linuxaudiodev,sunaudiodev)were removed in 2007 as part of thePEP 3108 stdlib re-organization.

sndhdr

Thesndhdr module issimilar to theimghdr module but for audio formats. It guesses fileformat, channels, frame rate, and sample widths from the first 512 bytes ofa file or buffer. The module only supports AU, AIFF, HCOM, VOC, WAV, andother ancient formats.

sunau

Thesunau module providessupport for Sun AU sound format. It’s yet another old, obsolete file format.

Networking modules

asynchat

Theasynchat module is built on top ofasyncore and has been deprecated since Python 3.6.

asyncore

Theasyncore module wasthe first module for asynchronous socket service clients and servers. Ithas been replaced by asyncio and is deprecated since Python 3.6.

Theasyncore module is also used in stdlib tests. The tests forftplib,logging,smptd,smtplib, andssl are partlybased onasyncore. These tests must be updated to use asyncio orthreading.

cgi

Thecgi module is a supportmodule for Common Gateway Interface (CGI) scripts. CGI is deemed asinefficient because every incoming request is handled in a new process.PEP 206 considers the module as:

“[…] designed poorly and are now near-impossible to fix (cgi) […]”

Replacements for the various parts ofcgi which are not directlyrelated to executing code are:

  • parse withurllib.parse.parse_qs (parse is just a wrapper)
  • parse_header withemail.message.Message (see example below)
  • parse_multipart withemail.message.Message (same MIME RFCs)
  • FieldStorage/MiniFieldStorage has no direct replacement, but cantypically be replaced by usingmultipart (forPOST andPUTrequests) orurllib.parse.parse_qsl (forGET andHEADrequests)
  • valid_boundary (undocumented) withre.compile("^[-~]{0,200}[!-~]$")

As an explicit example of how closeparse_header andemail.message.Message are:

>>>fromcgiimportparse_header>>>fromemail.messageimportMessage>>>parse_header(h)('application/json', {'charset': 'utf8'})>>>m=Message()>>>m['content-type']=h>>>m.get_params()[('application/json', ''), ('charset', 'utf8')]>>>m.get_param('charset')'utf8'

cgitb

Thecgitb module is ahelper for thecgi module for configurable tracebacks.

Thecgitb module is not used by any major Python web framework (Django,Pyramid, Plone, Flask, CherryPy, or Bottle). Only Paste uses it in anoptional debugging middleware.

smtpd

Thesmtpd module providesa simple implementation of a SMTP mail server. The module documentationmarks the module as deprecated and recommendsaiosmtpd instead. Thedeprecation message was added in releases 3.4.7, 3.5.4, and 3.6.1.

nntplib

Thenntplib moduleimplements the client side of the Network News Transfer Protocol (nntp). Newsgroups used to be a dominant platform for online discussions. Over the lasttwo decades, news has been slowly but steadily replaced with mailing listsand web-based discussion platforms. Twisted is alsoplanning to deprecate NNTPsupport andpynntp hasn’t seen anyactivity since 2014. This is a good indicator that the public interest inNNTP support is declining.

Thenntplib tests have been the cause of additional work in the recentpast. Python only contains the client side of NNTP, so the tests connect toexternal news servers. The servers are sometimes unavailable, too slow, or donot work correctly over IPv6. The situation causes flaky test runs onbuildbots.

telnetlib

Thetelnetlib moduleprovides a Telnet class that implements the Telnet protocol.

Operating system interface

crypt

Thecrypt module implementspassword hashing based on thecrypt(3) function fromlibcrypt orlibxcrypt on Unix-like platforms. The algorithms are mostly old, of poorquality and insecure. Users are discouraged from using them.

  • The module is not available on Windows. Cross-platform applications needan alternative implementation anyway.
  • Only DES encryption is guaranteed to be available. DES has an extremelylimited key space of 2**56.
  • MD5, salted SHA256, salted SHA512, and Blowfish are optional extensions.SSHA256 and SSHA512 are glibc extensions. Blowfish (bcrypt) is the onlyalgorithm that is still secure. However it’s in glibc and therefore notcommonly available on Linux.
  • Depending on the platform, thecrypt module is not thread safe. Onlyimplementations withcrypt_r(3) are thread safe.
  • The module was never useful to interact with system user and passworddatabases. On BSD, macOS, and Linux, all user authentication andpassword modification operations must go through PAM (pluggableauthentication module); see thespwd deprecation.

nis

Thenis module providesNIS/YP support. Network Information Service / Yellow Pages is an old anddeprecated directory service protocol developed by Sun Microsystems. Itsdesigned successor NIS+ from 1992 never took off. For a long time, libc’sName Service Switch, LDAP, and Kerberos/GSSAPI have been considered a more powerfuland more secure replacement for NIS.

spwd

Thespwd module providesdirect access to Unix shadow password database using non-standard APIs.

In general, it’s a bad idea to usespwd. It circumvents systemsecurity policies, does not use the PAM stack, and is only compatiblewith local user accounts, because it ignores NSS. The use of thespwdmodule for access control must be considered asecurity bug, as it bypassesPAM’s access control.

Furthermore, thespwd module uses theshadow(3) APIs.Functions likegetspnam(3) access the/etc/shadow file directly. Thisis dangerous and even forbidden for confined services on systems with asecurity engine like SELinux or AppArmor.

Misc modules

mailcap

Themailcap packagereadsmail capability files to assist in handling a file attachment inan email. In most modern operating systems the email client itself handles reacting tofile attachments. Operating systems also have their own way to registerhandling files by their file name extension. Finally, the module hasCVE-2015-20107 filedagainst it while having no maintainer to help fix it.

msilib

Themsilib package is aWindows-only package. It supports the creation of Microsoft Installers (MSI).The package also exposes additional APIs to create cabinet files (CAB). Themodule is used to facilitate distutils to create MSI installers with thebdist_msi command. In the past it was used to create CPython’s officialWindows installer, too.

Microsoft is slowly moving away from MSI in favor of Windows 10 Apps (AppX)as a new deployment model[3].

pipes

Thepipes module provideshelpers to pipe the input of one command into the output of another command.The module is built on top ofos.popen. Users are encouraged to usethesubprocess module instead.

Modules to keep

Some modules were originally proposed for deprecation but are no longerlisted as such in this PEP.

Table 2: Withdrawn deprecations
ModuleDeprecated inReplacement
colorsys-colormath, colour, colorspacious, Pillow
fileinput-argparse
getopt-argparse, optparse
optparse3.2argparse
wave-

colorsys

Thecolorsys moduledefines color conversion functions between RGB, YIQ, HSL, and HSV coordinatesystems.

Walter Dörwald, Petr Viktorin, and others requested to keepcolorsys. Themodule is useful to convert CSS colors between coordinate systems. Theimplementation is simple, mature, and does not impose maintenance overheadon core development.

The PyPI packagescolormath,colour, andcolorspacious provide more andadvanced features. The Pillow library is better suited to transform imagesbetween color systems.

fileinput

Thefileinput moduleimplements helpers to iterate over a list of files fromsys.argv. Themodule predates theoptparse andargparse modules. The same functionalitycan be implemented with theargparse module.

Several core developers expressed their interest to keep the module in thestandard library, as it is handy for quick scripts.

getopt

Thegetopt module mimicsC’sgetopt() option parser.

Although users are encouraged to useargparse instead, thegetopt module isstill widely used. The module is small, simple, and handy for C developersto write simple Python scripts.

optparse

Theoptparse module isthe predecessor of theargparse module.

Although it has been deprecated for many years, it’s still too widely usedto remove it.

wave

Thewave module providessupport for the WAV sound format.

The module is not deprecated, because the WAV format is still relevant thesedays. Thewave module is also used in education, e.g. to show kids howto make noise with a computer.

The module uses one simple function from theaudioop module to performbyte swapping between little and big endian formats. Before 24 bit WAVsupport was added, byte swap used to be implemented with thearraymodule. To removewave’s dependency onaudioop, the byte swapfunction could be either be moved to another module (e.g.operator) orthearray module could gain support for 24-bit (3-byte) arrays.

Discussions

  • Elana Hashman and Alyssa Coghlan suggested to keep thegetopt module.
  • Berker Peksag proposed to deprecate and removemsilib.
  • Brett Cannon recommended to delay active deprecation warnings and removalof modules likeimp until Python 3.10. Version 3.8 will be releasedshortly before Python 2 reaches end-of-life. A delay reduced churn forusers that migrate from Python 2 to 3.8.
  • At one point, distutils was mentioned in the same sentence as this PEP.To avoid lengthy discussion and delay of the PEP, I decided against dealingwith distutils. Deprecation of the distutils package will be handled byanother PEP.
  • Multiple people (Gregory P. Smith, David Beazley, Alyssa Coghlan, …)convinced me to keep thewave module.[4]
  • Gregory P. Smith proposed to deprecatenntplib.[4]
  • Andrew Svetlov mentioned thesocketserver module is questionable.However it’s used to implementhttp.server andxmlrpc.server. Thestdlib doesn’t have a replacement for the servers, yet.

Rejected ideas

Creating/maintaining a separate repo for the deprecated modules

It was previously proposed to create a separate repository containing thedeprecated modules packaged for installation. One of the PEP authors went so faras to create ademo repository. In theend, though, it was decided that the added workload to create and maintain sucha repo officially wasn’t justified, as the source code will continue to beavailable in the CPython repository for people to vendor as necessary. Similarwork has also not been done when previous modules were deprecated and removed,and it seemingly wasn’t an undue burden on the community.

Update history

Update 1

  • Deprecateparser module
  • Keepfileinput module
  • Elaborate whycrypt andspwd are dangerous and bad
  • Improve sections forcgitb,colorsys,nntplib, andsmtpd modules
  • Thecolorsys,crypt,imghdr,sndhdr, andspwd sections nowlist suitable substitutions
  • Mention thatsocketserver is going to stay forhttp.server andxmlrpc.server
  • The future maintenance section now states that the deprecated modulesmay be adopted by Python community members

Update 2

  • Keepcolorsys module
  • Add experts
  • Redirect discussions to discuss.python.org
  • Deprecatetelnetlib
  • Deprecate compat32 policy ofemail package
  • Add creation year to overview table
  • MentionPEP 206 andPEP 3108
  • Update sections foraifc,audioop,cgi, andwave.

Update 3

  • Keep the legacy email API modules. Internal deprecations will behandled separately.

Update 4

  • Add Brett as a co-author.
  • Retarget the PEP for Python 3.11.
  • Examples of how to replace the relevant parts ofcgi(thanks Martijn Pieters).

References

[1]
https://en.wikipedia.org/wiki/Open_Sound_System#History
[2]
https://man.openbsd.org/ossaudio
[3]
https://web.archive.org/web/20221206204209/https://blogs.msmvps.com/installsite/blog/2015/05/03/the-future-of-windows-installer-msi-in-the-light-of-windows-10-and-the-universal-windows-platform/
[4] (1,2)
https://twitter.com/ChristianHeimes/status/1130257799475335169
[5]
https://web.archive.org/web/20220420154535/https://twitter.com/dabeaz/status/1130278844479545351
[6]
https://mail.python.org/pipermail/python-dev/2019-May/157634.html

Copyright

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


Source:https://github.com/python/peps/blob/main/peps/pep-0594.rst

Last modified:2024-05-25 13:48:58 GMT


[8]ページ先頭

©2009-2025 Movatter.jp