pyguides

Reference

Modules

Popular standard-library modules and how to use them.

  1. abc module

    Define abstract base classes in Python with ABCMeta, @abstractmethod, and virtual subclass registration.

  2. argparse

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

  3. ast

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

  4. asyncio

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

  5. atexit module

    The atexit module registers functions to run when the Python interpreter exits normally. Covers register(), unregister(), LIFO order, and limitations.

  6. base64

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

  7. bisect

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

  8. calendar

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

  9. collections

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

  10. concurrent.futures

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

  11. configparser

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

  12. contextlib

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

  13. copy

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

  14. cProfile module

    Profile Python code to find performance bottlenecks using the cProfile module.

  15. csv

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

  16. dataclasses

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

  17. datetime

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

  18. decimal

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

  19. difflib

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

  20. dis module

    The dis module disassembles Python bytecode, exposing what CPython actually runs. Covers dis(), Bytecode, Instruction objects, and bytecode analysis.

  21. email module

    Parse, construct, and manipulate email messages. Build MIME messages, handle encoding, and work with email addresses using Python's standard library.

  22. enum

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

  23. fractions

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

  24. functools

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

  25. gc module

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

  26. glob

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

  27. gzip

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

  28. hashlib

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

  29. heapq

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

  30. html

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

  31. 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.

  32. inspect

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

  33. io module

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

  34. ipaddress

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

  35. itertools

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

  36. json

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

  37. logging

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

  38. lzma module

    Compress and decompress data with LZMA compression in Python. Use LZMAFile for files, compress/decompress for raw bytes, and tune preset levels.

  39. math

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

  40. mimetypes module

    Map filenames to MIME types and back using the Python mimetypes module — covering guess_type, guess_extension, add_type, and the MimeTypes class.

  41. multiprocessing

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

  42. operator

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

  43. os module

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

  44. os.path

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

  45. pathlib

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

  46. pdb module

    The Python debugger. Set breakpoints, step through code, inspect variables, and diagnose crashes interactively.

  47. pickle

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

  48. platform

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

  49. pprint

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

  50. queue

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

  51. random

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

  52. re module

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

  53. sched module

    Schedule callable objects to run at specific times using the sched module — covering enter, enterabs, cancel, run, and the timefunc/delayfunc interface.

  54. selectors module

    High-level I/O multiplexing in Python. Monitor multiple sockets or files for readiness using selectors — event-driven networking made simple.

  55. shelve module

    Persist Python objects to a disk-based dictionary with the shelve module. Open, write, read, and manage shelf files with pickle-backed storage.

  56. shutil

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

  57. signal

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

  58. smtplib module

    Send emails from Python using SMTP. Connect to mail servers, authenticate, and send text or HTML messages with attachments via smtplib.

  59. socket

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

  60. 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

  61. statistics

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

  62. string

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

  63. struct

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

  64. subprocess

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

  65. sys

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

  66. tarfile

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

  67. tempfile

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

  68. textwrap

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

  69. threading

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

  70. time

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

  71. timeit

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

  72. tomllib module

    Parse TOML files and strings with Python's built-in tomllib module. Added in Python 3.11.

  73. traceback

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

  74. types module

    Dynamic type creation utilities and type constants for built-in interpreter types, including FunctionType, GeneratorType, ModuleType, SimpleNamespace, and more.

  75. typing

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

  76. unittest

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

  77. unittest.mock module

    Create mock objects for tests. Replace real objects, fake their behavior, and assert how they were called.

  78. urllib.parse

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

  79. uuid

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

  80. warnings

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

  81. weakref

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

  82. zipfile

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

  83. zoneinfo

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