← Reference

Modules

Popular standard-library modules and how to use them.

argparse

The standard library module for parsing command-line arguments, defining program usage, and generating help messages.

import argparse

ast

The ast module provides classes for parsing, analyzing, and manipulating Python source code as Abstract Syntax Trees

asyncio

The asyncio module provides infrastructure for writing concurrent code using async/await syntax in Python

import asyncio

base64

The base64 module provides functions for encoding and decoding binary data to and from ASCII text format

import base64

bisect

Binary search and sorted insertion helpers for maintaining ordered lists in Python's standard library.

calendar

The calendar module provides functions for working with calendars, including printing text calendars and date calculations

collections

Specialized container datatypes that extend Python's built-in containers for efficient data handling.

concurrent.futures

High-level interface for asynchronously executing callables using threads or processes

configparser

The configparser module provides ConfigParser for reading and writing configuration files in INI format

contextlib

Utilities for context managers: contextmanager, suppress, nullcontext, closing, ExitStack, and redirect functions

copy

The copy module provides functions for creating shallow and deep copies of Python objects

csv

The csv module provides tools for reading and writing CSV files — reader, writer, and DictReader/DictWriter classes.

import csv

dataclasses

The dataclasses module provides a decorator and functions for automatically adding __init__ and __repr__ to user-defined classes

from dataclasses import dataclass, field

datetime

The datetime module provides datetime, date, time, timedelta, and timezone classes for working with dates and times in Python

decimal

The decimal module provides precise fixed-point and floating-point arithmetic with exact decimal representation, configurable precision, and rounding modes

difflib

The difflib module provides tools for comparing sequences and generating differences in various formats

enum

The enum module provides support for enumerations — named constants grouped into classes with useful methods

fractions

The fractions module provides support for rational number arithmetic using the Fraction class

functools

Higher-order functions and operations on callable objects including caching, partial application, and function composition

gc module

The gc module provides interfaces to Python's garbage collector for debugging memory issues and controlling collection behavior.

import gc

glob

The glob module provides Unix-style pathname pattern expansion for finding files matching wildcards like *, ?, and character ranges

glob.glob(pathname, *, root_dir=None, dir_fd=None, recursive=False, include_hidden=False)

gzip

The gzip module provides functions and classes for reading and writing gzip-compressed files, modeled after the GNU gzip utilities

import gzip

hashlib

The hashlib module provides cryptographic hash functions for secure password storage, data integrity verification, and digital signatures

heapq

The heapq module provides functions for working with heaps (priority queues), including push, pop, and merge operations

html

The html module provides utilities for escaping HTML special characters and parsing HTML/XHTML documents

http

The http module provides classes for building HTTP clients and servers, including http.client for making requests and http.server for creating HTTP servers.

import http.client / from http.server import HTTPServer

inspect

Functions for introspecting live objects—modules, classes, functions, tracebacks, frames, and code objects

io module

Core tools for working with text and binary I/O streams in Python.

ipaddress

Work with IPv4 and IPv6 addresses, networks, and interfaces in Python

import ipaddress

itertools

Functions for working with iterators, including infinite generators, combinatorics, and iteration adapters.

import itertools

json

The json module provides functions for encoding and decoding JSON data in Python

import json

logging

The built-in logging module provides a flexible framework for emitting log messages from Python programs

math

The math module provides mathematical functions for floating-point and integer operations

multiprocessing

The multiprocessing module provides process-based parallelism in Python, enabling concurrent execution by spawning separate processes to bypass the GIL

import multiprocessing

operator

The operator module provides functional equivalents to Python's operators, useful for passing operators as arguments to higher-order functions

os module

The os module provides a portable way of using operating system dependent functionality like files, directories, processes, and environment variables.

import os

os.path

The os.path module provides functions for manipulating file paths across different operating systems

pathlib

The standard library module for object-oriented filesystem path manipulation, providing classes for working with files and directories

from pathlib import Path

pickle

The pickle module provides functions for serializing and deserializing Python objects to binary format

import pickle

platform

The platform module provides access to underlying platform identifying data such as OS name, version, machine type, and Python version information

pprint

The pprint module provides pretty-printing capabilities for displaying Python data structures in a readable, formatted output

queue

The standard library queue module provides thread-safe FIFO, LIFO, and priority queues for multi-threaded programming.

import queue

random

The random module generates pseudo-random numbers and provides functions for random selection and sampling

re module

The re module provides regular expression operations for pattern matching, searching, and text manipulation

re.compile(pattern, flags=0)

shutil

The standard library module for high-level file operations including copying, moving, removing, and archiving files and directories.

import shutil

signal

The signal module provides mechanisms for handling asynchronous events in Python, letting you register handlers that run when specific signals arrive.

import signal

socket

The standard library module for low-level network communication, providing access to BSD socket interfaces for creating network clients and servers.

import socket

sqlite3

The sqlite3 module provides a lightweight disk-based database that doesn't require a separate server process, implementing the DB-API 2.0 specification

sqlite3.connect(database, timeout=5.0, detect_types=0, isolation_level='DEFERRED', check_same_thread=True, factory=sqlite3.Connection, cached_statements=128, uri=False, autocommit=sqlite3.LEGACY_TRANSACTION_CONTROL)

statistics

The statistics module provides functions for calculating mathematical statistics like mean, median, mode, variance, and standard deviation

string

A comprehensive reference for Python's string module covering common string constants, functions, and the Formatter class

struct

The struct module converts between Python values and C structs packed into bytes, useful for binary file formats and network protocols

subprocess

The subprocess module allows you to spawn new processes, connect to their input/output/error pipes, and obtain their return codes

sys

The sys module provides access to system-specific parameters and functions, including command-line arguments, the Python interpreter, and platform information

tarfile

The tarfile module provides tools for reading and writing tar archives, including compressed formats like gzip, bzip2, and xz

tempfile

The tempfile module provides functions for creating temporary files and directories securely in Python.

textwrap

Python's textwrap module formats plain text by wrapping, dedenting, and shortening paragraphs.

threading

The threading module provides thread-based parallelism for CPU-bound tasks and I/O-bound concurrency in Python.

time

Python's time module provides functions for working with time, measuring performance, and handling delays.

timeit

The timeit module provides a simple way to time small bits of Python code with high precision, minimizing overhead from measurement.

import timeit

traceback

Extract, format, and print Python stack traces for debugging and error handling

typing

Support for type hints, including generics, protocols, and utility types for annotating Python code

unittest

The unittest module provides a unit testing framework for Python, supporting test fixtures, assertions, and test runners

urllib.parse

The urllib.parse module provides functions for parsing and manipulating URLs and query strings

uuid

Generate and work with universally unique identifiers (UUIDs) according to RFC 9562

warnings

The warnings module provides control over warning messages issued by Python, allowing suppression, filtering, and conversion to exceptions

weakref

Python's weakref module provides weak references to objects, allowing references that don't prevent garbage collection when all other references are gone.

zipfile

The zipfile module provides tools for reading and writing ZIP archives, including support for compressed files and archive members

zoneinfo

The zoneinfo module provides support for IANA time zones in Python, enabling accurate timezone handling for datetime objects

import zoneinfo