The Python Standard Library¶
Release: | 3.0 |
---|---|
Date: | 8月 10, 2025 |
While The Python Language Reference describes the exact syntax and semantics of the Python language, this library reference manual describes the standard library that is distributed with Python. It also describes some of the optional components that are commonly included in Python distributions.
Python’s standard library is very extensive, offering a wide range of facilities as indicated by the long table of contents listed below. The library contains built-in modules (written in C) that provide access to system functionality such as file I/O that would otherwise be inaccessible to Python programmers, as well as modules written in Python that provide standardized solutions for many problems that occur in everyday programming. Some of these modules are explicitly designed to encourage and enhance the portability of Python programs by abstracting away platform-specifics into platform-neutral APIs.
The Python installers for the Windows platform usually includes the entire standard library and often also include many additional components. For Unix-like operating systems Python is normally provided as a collection of packages, so it may be necessary to use the packaging tools provided with the operating system to obtain some or all of the optional components.
In addition to the standard library, there is a growing collection of several thousand components (from individual programs and modules to packages and entire application development frameworks), available from the Python Package Index.
- Introduction
- Built-in Functions
- Built-in Constants
- Built-in Objects
- Built-in Types
- Truth Value Testing
- Boolean Operations —
and
,or
,not
- Comparisons
- Numeric Types —
int
,float
,complex
- Iterator Types
- Sequence Types —
str
,bytes
,bytearray
,list
,tuple
,range
- Set Types —
set
,frozenset
- Mapping Types —
dict
- File Objects
- memoryview Types
- Context Manager Types
- Other Built-in Types
- Special Attributes
- Built-in Exceptions
- String Services
string
— Common string operationsre
— Regular expression operationsstruct
— Interpret bytes as packed binary datadifflib
— Helpers for computing deltastextwrap
— Text wrapping and fillingcodecs
— Codec registry and base classesunicodedata
— Unicode Databasestringprep
— Internet String Preparation
- Data Types
datetime
— Basic date and time typescalendar
— General calendar-related functionscollections
— Container datatypesheapq
— Heap queue algorithmbisect
— Array bisection algorithmarray
— Efficient arrays of numeric valuessched
— Event schedulerqueue
— A synchronized queue classweakref
— Weak referencestypes
— Names for built-in typescopy
— Shallow and deep copy operationspprint
— Data pretty printerreprlib
— Alternaterepr()
implementation
- Numeric and Mathematical Modules
numbers
— Numeric abstract base classesmath
— Mathematical functions- Constants
cmath
— Mathematical functions for complex numbersdecimal
— Decimal fixed point and floating point arithmeticfractions
— Rational numbersrandom
— Generate pseudo-random numbersitertools
— Functions creating iterators for efficient loopingfunctools
— Higher order functions and operations on callable objectsoperator
— Standard operators as functions
- File and Directory Access
os.path
— Common pathname manipulationsfileinput
— Iterate over lines from multiple input streamsstat
— Interpretingstat()
resultsfilecmp
— File and Directory Comparisonstempfile
— Generate temporary files and directoriesglob
— Unix style pathname pattern expansionfnmatch
— Unix filename pattern matchinglinecache
— Random access to text linesshutil
— High-level file operationsmacpath
— Mac OS 9 path manipulation functions
- Data Persistence
- Data Compression and Archiving
- File Formats
- Cryptographic Services
- Generic Operating System Services
os
— Miscellaneous operating system interfacesio
— Core tools for working with streamstime
— Time access and conversionsoptparse
— More powerful command line option parsergetopt
— Parser for command line optionslogging
— Logging facility for Pythongetpass
— Portable password inputcurses
— Terminal handling for character-cell displayscurses.textpad
— Text input widget for curses programscurses.wrapper
— Terminal handler for curses programscurses.ascii
— Utilities for ASCII characterscurses.panel
— A panel stack extension for curses.platform
— Access to underlying platform’s identifying data.errno
— Standard errno system symbolsctypes
— A foreign function library for Python.
- Optional Operating System Services
select
— Waiting for I/O completionthreading
— Higher-level threading interfacedummy_threading
— Drop-in replacement for thethreading
module_thread
— Low-level threading API_dummy_thread
— Drop-in replacement for the_thread
modulemultiprocessing
— Process-based 「threading」 interfacemmap
— Memory-mapped file supportreadline
— GNU readline interfacerlcompleter
— Completion function for GNU readline
- Interprocess Communication and Networking
- Internet Data Handling
email
— An email and MIME handling packagejson
— JSON encoder and decodermailcap
— Mailcap file handlingmailbox
— Manipulate mailboxes in various formatsmimetypes
— Map filenames to MIME typesbase64
— RFC 3548: Base16, Base32, Base64 Data Encodingsbinhex
— Encode and decode binhex4 filesbinascii
— Convert between binary and ASCIIquopri
— Encode and decode MIME quoted-printable datauu
— Encode and decode uuencode files
- Structured Markup Processing Tools
html.parser
— Simple HTML and XHTML parserhtml.entities
— Definitions of HTML general entitiesxml.parsers.expat
— Fast XML parsing using Expatxml.dom
— The Document Object Model APIxml.dom.minidom
— Lightweight DOM implementationxml.dom.pulldom
— Support for building partial DOM treesxml.sax
— Support for SAX2 parsersxml.sax.handler
— Base classes for SAX handlersxml.sax.saxutils
— SAX Utilitiesxml.sax.xmlreader
— Interface for XML parsersxml.etree.ElementTree
— The ElementTree XML API
- Internet Protocols and Support
webbrowser
— Convenient Web-browser controllercgi
— Common Gateway Interface support.cgitb
— Traceback manager for CGI scriptswsgiref
— WSGI Utilities and Reference Implementationurllib.request
— extensible library for opening URLsurllib.response
— Response classes used by urllib.urllib.parse
— Parse URLs into componentsurllib.error
— Exception classes raised by urllib.requesturllib.robotparser
— Parser for robots.txthttp.client
— HTTP protocol clientftplib
— FTP protocol clientpoplib
— POP3 protocol clientimaplib
— IMAP4 protocol clientnntplib
— NNTP protocol clientsmtplib
— SMTP protocol clientsmtpd
— SMTP Servertelnetlib
— Telnet clientuuid
— UUID objects according to RFC 4122socketserver
— A framework for network servershttp.server
— HTTP servershttp.cookies
— HTTP state managementhttp.cookiejar
— Cookie handling for HTTP clientsxmlrpc.client
— XML-RPC client accessxmlrpc.server
— Basic XML-RPC servers
- Multimedia Services
audioop
— Manipulate raw audio dataaifc
— Read and write AIFF and AIFC filessunau
— Read and write Sun AU fileswave
— Read and write WAV fileschunk
— Read IFF chunked datacolorsys
— Conversions between color systemsimghdr
— Determine the type of an imagesndhdr
— Determine type of sound fileossaudiodev
— Access to OSS-compatible audio devices
- Internationalization
- Program Frameworks
- Graphical User Interfaces with Tk
- Development Tools
- Debugging and Profiling
- Python Runtime Services
sys
— System-specific parameters and functionsbuiltins
— Built-in objects__main__
— Top-level script environmentwarnings
— Warning controlcontextlib
— Utilities forwith
-statement contexts.abc
— Abstract Base Classesatexit
— Exit handlerstraceback
— Print or retrieve a stack traceback__future__
— Future statement definitionsgc
— Garbage Collector interfaceinspect
— Inspect live objectssite
— Site-specific configuration hookfpectl
— Floating point exception control
- Custom Python Interpreters
- Importing Modules
- Python Language Services
parser
— Access Python parse trees- Abstract Syntax Trees
symtable
— Access to the compiler’s symbol tablessymbol
— Constants used with Python parse treestoken
— Constants used with Python parse treeskeyword
— Testing for Python keywordstokenize
— Tokenizer for Python sourcetabnanny
— Detection of ambiguous indentationpyclbr
— Python class browser supportpy_compile
— Compile Python source filescompileall
— Byte-compile Python librariesdis
— Disassembler for Python bytecodepickletools
— Tools for pickle developers.distutils
— Building and installing Python modules
- Miscellaneous Services
- MS Windows Specific Services
- Unix Specific Services
posix
— The most common POSIX system callspwd
— The password databasespwd
— The shadow password databasegrp
— The group databasecrypt
— Function to check Unix passwordstermios
— POSIX style tty controltty
— Terminal control functionspty
— Pseudo-terminal utilitiesfcntl
— Thefcntl()
andioctl()
system callspipes
— Interface to shell pipelinesresource
— Resource usage informationnis
— Interface to Sun’s NIS (Yellow Pages)syslog
— Unix syslog library routines
- Undocumented Modules