Python Standard Library (Reference) – Real Python
The Python standard library includes a wide variety of modules and packages that can help you accomplish many common programming tasks, from file input/output (I/O), regular expressions, and mathematical operations to networking, data serialization, and working with dates and times. This wide range of functionality is why the Python community often says that Python is batteries-included.
The standard library is designed to be both broad and deep. It includes modules for low-level system interaction like os, sys, and subprocess, as well as high-level tools like csv for handling structured text, json for working with JSON data, http.server for creating simple web servers, and sqlite3 for embedded databases.
You’ll also find powerful utilities like itertools and functools for functional programming patterns, collections for specialized data structures, and more.
Because these modules are part of the Python distribution itself, you don’t need to install anything separately. That makes it easy to write portable, efficient programs that work out of the box across different environments and platforms.
In practice, the standard library covers a wide variety of use cases, including:
- System scripting and automation
- Web development
- Text and data processing
- Basic networking and client-server communication
- Concurrency and multithreading
- Data storage and serialization
In short, the standard library is one of Python’s greatest strengths. It helps you do more with less by reducing the need for external dependencies while encouraging idiomatic, readable code.
-
abcProvides infrastructure for defining Abstract Base Classes (ABCs). -
argparseProvides a framework for creating user-friendly command-line interfaces (CLI). -
arrayProvides an efficient data structure for creating arrays of values, which are stored more compactly than in standard lists. -
astProvides functionality to work with Abstract Syntax Trees (ASTs). -
asyncioProvides a framework for writing asynchronous programs using coroutines, event loops, and tasks. -
atexitProvides an interface for registering functions to be executed upon the program’s normal termination. -
base64A Python standard library module for encoding binary data as ASCII text using Base16, Base32, Base64, and Base85 schemes. -
bdbA Python standard library module that provides a generic debugger framework for setting breakpoints, stepping through code, and managing trace events. -
calendarProvides classes and functions for calendar operations. -
collectionsProvides specialized container data types that extend the capabilities of Python’s built-in containers like lists, tuples, sets, and dictionaries. -
configparserProvides tools for handling configuration files. -
contextlibProvides utilities for working with context managers, allowing you to allocate and release resources precisely. -
contextvarsSupports managing context state, allowing you to store and retrieve data that is local to a context. -
copyProvides functionality to create shallow and deep copies of objects in Python. -
cProfileProvides a way to measure where time is being spent in your application. -
csvProvides functionality to read from and write to CSV (comma-separated values) files. -
dataclassesProvides functionality for creating user-defined data classes. -
datetimeContains classes and tools for manipulating dates and times. -
decimalProvides support for correctly rounded decimal floating-point arithmetic. -
doctestProvides tools for testing your code by running tests embedded in docstrings. -
emailProvides a library for managing email messages. -
enumProvides support for enumerations of constant values known as members. -
fractionsProvides support for rational number arithmetic. -
functoolsProvides higher-order functions and operations on callable objects. -
gcProvides an interface to the garbage collection facility for Python. -
gettextProvides internationalization (I18N) and localization (L10N) services for your Python applications. -
globProvides tools to find path names matching specified patterns that follow Unix shell rules. -
hashlibProvides a common interface to many secure hash and message digest algorithms, such as SHA-256 and MD5. -
heapqProvides an implementation of the heap queue algorithm, also known as the priority queue algorithm. -
htmlProvides utilities for manipulating HTML data, including escaping and unescaping HTML entities and tags. -
httpProvides a set of modules for working with HTTP requests and responses. -
imaplibProvides tools for interacting with mail servers using the Internet Message Access Protocol (IMAP). -
importlibProvides a framework for the import statement, allowing for the importing of modules in Python. -
inspectProvides several useful functions to help you get information about live objects, such as modules, classes, methods, functions, tracebacks, and the objects’ source code. -
ioProvides the main facilities for dealing with various types of I/O, including reading and writing files, handling binary data, and working with streams. -
ipaddressProvides the capabilities to create, manipulate, and operate on IPv4 and IPv6 addresses. -
itertoolsProvides a collection of tools to perform fast and memory-efficient iteration. -
jsonProvides tools to encode and decode data in JavaScript Object Notation (JSON). -
keywordProvides functionality to work with Python’s reserved keywords. -
localeProvides a way to handle operations related to the localization of programs, such as formatting numbers, dates, and currencies according to the conventions of different locales. -
loggingProvides a framework for generating log messages from Python programs. -
mathProvides a comprehensive collection of mathematical functions and constants. -
mimetypesProvides tools to map filenames to MIME types and vice versa. -
mmapMaps files or devices into memory. -
multiprocessingAllows you to create parallel programs by leveraging multiple processors on your machine. -
numbersProvides an abstract hierarchy of numeric types. -
operatorProvides functions that correspond to the Python operators. -
osProvides tools for using operating system-dependent functionality. -
pathlibProvides an object-oriented approach to handling file system paths. -
pickleProvides tools to serialize and deserialize Python objects. -
platformProvides access to underlying platform-specific data, such as the operating system, interpreter, and hardware architecture. -
pprintProvides the capability to pretty-print data structures in a readable and easy-to-understand way. -
queueProvides reliable thread-safe implementations of the queue data structure. -
randomProvides tools for generating random numbers and performing random operations. -
reProvides support for working with regular expressions. -
secretsProvides a straightforward and secure way to generate cryptographically strong random numbers. -
shutilProvides a higher-level interface for file operations, including copying and removal. -
socketProvides a low-level networking interface that allows you to create and use sockets for network communication. -
sqlite3Provides an interface for interacting with SQLite databases. -
stringProvides a collection of string constants and utility functions for common string operations. -
subprocessAllows you to spawn new processes, connect to their input/output/error pipes, and obtain their return codes. -
sysProvides access to system-specific parameters and functions. -
sysconfigProvides access to Python’s configuration information, which includes details about the installation paths, the build environment, and platform-specific settings. -
tarfileProvides a powerful and flexible way to read and write tar archives. -
tempfileProvides a simple way to create temporary files and directories. -
threadingProvides a higher-level interface for working with threads. -
timeProvides various time-related functions. -
timeitProvides a simple way to measure the execution time of small code snippets. -
tkinterProvides a powerful object-oriented interface to the Tk GUI toolkit. -
tomllibProvides a simple way to parse TOML files. -
tracebackProvides utilities for working with error tracebacks. -
turtleProvides tools to create pictures and shapes by controlling a turtle that draws on a canvas. -
typingProvides support for type hints. -
unittestProvides a framework for creating and running unit tests. -
urllibProvides a collection of modules for working with URLs. -
uuidProvides a way to generate universally unique identifiers (UUIDs). -
venvProvides support for creating isolated Python environments. -
waveProvides an interface to read and write WAV files. -
weakrefProvides tools for creating weak references to objects. -
webbrowserProvides a high-level interface to allow displaying web-based documents to users. -
xmlProvides tools for parsing and creating XML documents. -
zipappProvides tools for creating standalone executable Python applications packaged as ZIP files. -
zipfileProvides tools to create, read, write, and extract ZIP archives.