Python’s been around in one form or another for over 30 years. Over that time, it has accumulated a wide and powerful set of modules in its standard library. These modules help developers get started with many common tasks. Fans of Python call this the “batteries included” part of the language.
But over the years, some of those batteries have died—meaning they’ve gone out of maintenance, or been used for technologies that are now obsolete. Some of these “dead batteries” were deprecated in Python 3.12, and will be removed entirely in Python 3.13.
PEP 594 describes these deprecations in detail, but it can be hard to know at a glance which ones matter most.
So, here’s a rundown—in roughly descending order of importance—of the standard library modules being removed in Python 3.13, including what each one does and what new module (if any) has replaced it.
Deprecated Python modules you may still be using
Here are the most important deprecated standard library modules. These are the ones you are most likely still using in existing applications.
The CGI standard for web applications has long been obsolete, but support for it has lingered in Python for two reasons: the many web application frameworks that still support CGI, and the components within
cgitb that are still used elsewhere.
Here are the
cgi features or components that you may be using, even if you don’t realize it, and what you can do to replace them, as per PEP 594:
Additionally, if you’re using
PUT requests on potentially large payloads, you might need to replace
cgi.FieldStorage with a third-party module like multipart. For smaller payloads, the attachment-parsing elements in email.message may suffice.
HEAD requests, you can use urllib.parse.parse_qsl.
smtpd, telnetlib, nntplib
These modules are for working with mail, news, and network connection protocols. In all cases, they’re now superseded by other modules:
smtpd, for work with the SMTP mail protocol, can be replaced with aiosmtpd, which has the additional advantage of being async friendly.
nntp, for working with the USENET news protocol, can be replaced with pynntp.
telnetlib, for working with the Telnet connectivity protocol, can be replaced with telnetlib3, which has the advantages of being a higher-level client and compatible with asyncio.
msilib is available only on Microsoft Windows and is for creating Microsoft Installer (MSI) packages.
distutils, which is also now deprecated, used this module to create MSI installers. Python’s core developers have cited the burden of maintaining
msilib (with relatively few real-world users) as a big reason for removing it.
pipes repackages some of the functionality of
os.popen to redirect input from one command into another command’s output. subprocess in the standard library is the way to handle such things now.
More deprecated Python modules
These modules are far less likely to be in use in any programs you’re writing or maintaining, but it’s worth knowing they have been deprecated.
asynchat/asyncore: For async network operations. Replaced by
asynciosince Python 3.6.
imghdr/sndhdr: Used to make educated guesses about the contents of image or sound files based on their headers. Superseded by third-party libraries like
Pillow(for images) or python-magic (for all kinds of files).
uu: For encoding and decoding data using the
uuencodeprotocol; obsolete since the creation of the MIME format. If you still need the
uucodec for whatever reason, the
binasciimodule in the
mailcap: Used for reading mail capacity files, as a way to work with email attachments. Programs rarely need to do this by themselves anymore.
crypt: For working with Unix-style
libcryptfunctions, which have long been considered obsolete and insecure.
nis: For working with the obsolete Network Information Service protocol, replaced by LDAP and other such protocols.
spwd: For access to the Unix shadow password database. This is considered a security hazard and its use is no longer encouraged.
xdrlib: For working with the Sun External Data Representation Standard, a binary serialization format that is no longer used.
chunk: For reading and writing the Interchange File Format, used on older personal computers like the Commodore and Amiga.
sunau: For working with the obsolete Sun AU audio format.
ossaudiodev: Support for the little-used Open Sound System audio interface standard.
Copyright © 2023 IDG Communications, Inc.