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 […].”
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.
lxml instead ofxml. The removal of an unmaintained stdlib moduleincreases the chances of a community-contributed module to become widelyused.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.
ftplib is going to stay.optparse andgetopt modules are widely used. They are maturemodules with very low maintenance overhead.wave 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.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.
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.
All modules deprecated by this PEP are removed from themain branchof the CPython repository and are no longer distributed as part of Python.
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.
| Module | Deprecated in | To be removed | Added in | Has maintainer? | Replacement |
|---|---|---|---|---|---|
| aifc | 3.11 (3.0*) | 3.13 | 1993 | yes (inactive) | - |
| asynchat | 3.6 (3.0*) | 3.12 | 1999 | yes | asyncio |
| asyncore | 3.6 (3.0*) | 3.12 | 1999 | yes | asyncio |
| audioop | 3.11 (3.0*) | 3.13 | 1992 | yes | - |
| cgi | 3.11 (2.0**) | 3.13 | 1995 | no | - |
| cgitb | 3.11 (2.0**) | 3.13 | 1995 | no | - |
| chunk | 3.11 | 3.13 | 1999 | no | - |
| crypt | 3.11 | 3.13 | 1994 | yes (inactive) | legacycrypt,bcrypt,argon2-cffi,hashlib,passlib |
| imghdr | 3.11 | 3.13 | 1992 | no | filetype,puremagic,python-magic |
| mailcap | 3.11 | 3.13 | 1995 | no | - |
| msilib | 3.11 | 3.13 | 2006 | no | - |
| nntplib | 3.11 | 3.13 | 1992 | no | - |
| nis | 3.11 (3.0*) | 3.13 | 1992 | no | - |
| ossaudiodev | 3.11 | 3.13 | 2002 | no | - |
| pipes | 3.11 | 3.13 | 1992 | no | subprocess |
| smtpd | 3.4.7,3.5.4 | 3.12 | 2001 | yes | aiosmtpd |
| sndhdr | 3.11 | 3.13 | 1994 | no | filetype,puremagic,python-magic |
| spwd | 3.11 | 3.13 | 2005 | no | python-pam |
| sunau | 3.11 (3.0*) | 3.13 | 1993 | no | - |
| telnetlib | 3.11 (3.0*) | 3.13 | 1997 | no | telnetlib3,Exscript |
| uu | 3.11 | 3.13 | 1994 | no | - |
| xdrlib | 3.11 | 3.13 | 1992/1996 | no | - |
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.
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.
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.
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.
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.
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.
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.
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.
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.
Thesunau module providessupport for Sun AU sound format. It’s yet another old, obsolete file format.
Theasynchat module is built on top ofasyncore and has been deprecated since Python 3.6.
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.
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'
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.
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.
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.
Thetelnetlib moduleprovides a Telnet class that implements the Telnet protocol.
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.
crypt module is not thread safe. Onlyimplementations withcrypt_r(3) are thread safe.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.
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.
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.
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].
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.
Some modules were originally proposed for deprecation but are no longerlisted as such in this PEP.
| Module | Deprecated in | Replacement |
|---|---|---|
| colorsys | - | colormath, colour, colorspacious, Pillow |
| fileinput | - | argparse |
| getopt | - | argparse, optparse |
| optparse | 3.2 | argparse |
| wave | - |
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.
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.
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.
Theoptparse module isthe predecessor of theargparse module.
Although it has been deprecated for many years, it’s still too widely usedto remove it.
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.
getopt module.msilib.imp 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.socketserver module is questionable.However it’s used to implementhttp.server andxmlrpc.server. Thestdlib doesn’t have a replacement for the servers, yet.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.
parser modulecrypt andspwd are dangerous and badcrypt,imghdr,sndhdr, andspwd sections nowlist suitable substitutionssocketserver is going to stay forhttp.server andxmlrpc.servercgi(thanks Martijn Pieters).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