The Python Standard Library¶
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 include 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 an active collection of hundreds of thousands of 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 Types
- Truth Value Testing
- Boolean Operations â
and,or,not - Comparisons
- Numeric Types â
int,float,complex - Boolean Type -
bool - Iterator Types
- Sequence Types â
list,tuple,range - Text and Binary Sequence Type Methods Summary
- Text Sequence Type â
str - Binary Sequence Types â
bytes,bytearray,memoryview - Set Types â
set,frozenset - Mapping Types â
dict - Context Manager Types
- Type Annotation Types â Generic Alias, Union
- Other Built-in Types
- Special Attributes
- Integer string conversion length limitation
- Built-in Exceptions
- Thread Safety Guarantees
- Text Processing Services
stringâ Common string operationsstring.templatelibâ Support for template string literalsreâ Regular expression operationsdifflibâ Helpers for computing deltastextwrapâ Text wrapping and fillingunicodedataâ Unicode Databasestringprepâ Internet String Preparationreadlineâ GNU readline interfacerlcompleterâ Completion function for GNU readline
- Binary Data Services
- Data Types
datetimeâ Basic date and time typeszoneinfoâ IANA time zone supportcalendarâ General calendar-related functionscollectionsâ Container datatypescollections.abcâ Abstract Base Classes for Containersheapqâ Heap queue algorithmbisectâ Array bisection algorithmarrayâ Efficient arrays of numeric valuesweakrefâ Weak referencestypesâ Dynamic type creation and names for built-in typescopyâ Shallow and deep copy operationspprintâ Data pretty printerreprlibâ Alternaterepr()implementationenumâ Support for enumerationsgraphlibâ Functionality to operate with graph-like structures
- Numeric and Mathematical Modules
numbersâ Numeric abstract base classesmathâ Mathematical functionscmathâ Mathematical functions for complex numbersdecimalâ Decimal fixed-point and floating-point arithmeticfractionsâ Rational numbersrandomâ Generate pseudo-random numbersstatisticsâ Mathematical statistics functions
- Functional Programming Modules
- File and Directory Access
pathlibâ Object-oriented filesystem pathsos.pathâ Common pathname manipulationsstatâ 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 operations
- Data Persistence
- Data Compression and Archiving
- The
compressionpackage compression.zstdâ Compression compatible with the Zstandard formatzlibâ Compression compatible with gzipgzipâ Support for gzip filesbz2â Support for bzip2 compressionlzmaâ Compression using the LZMA algorithmzipfileâ Work with ZIP archivestarfileâ Read and write tar archive files
- The
- File Formats
- Cryptographic Services
- Generic Operating System Services
osâ Miscellaneous operating system interfacesioâ Core tools for working with streamstimeâ Time access and conversionsloggingâ Logging facility for Pythonlogging.configâ Logging configurationlogging.handlersâ Logging handlersplatformâ Access to underlying platformâs identifying dataerrnoâ Standard errno system symbolsctypesâ A foreign function library for Python
- Command-line interface libraries
argparseâ Parser for command-line options, arguments and subcommandsoptparseâ Parser for command line optionsgetpassâ Portable password inputfileinputâ Iterate over lines from multiple input streamscursesâ Terminal handling for character-cell displayscurses.textpadâ Text input widget for curses programscurses.asciiâ Utilities for ASCII characterscurses.panelâ A panel stack extension for cursescmdâ Support for line-oriented command interpreters
- Concurrent Execution
threadingâ Thread-based parallelismmultiprocessingâ Process-based parallelismmultiprocessing.shared_memoryâ Shared memory for direct access across processes- The
concurrentpackage concurrent.futuresâ Launching parallel tasksconcurrent.interpretersâ Multiple interpreters in the same processsubprocessâ Subprocess managementschedâ Event schedulerqueueâ A synchronized queue classcontextvarsâ Context Variables_threadâ Low-level threading API
- Networking and Interprocess Communication
- Internet Data Handling
emailâ An email and MIME handling packagejsonâ JSON encoder and decodermailboxâ Manipulate mailboxes in various formatsmimetypesâ Map filenames to MIME typesbase64â Base16, Base32, Base64, Base85 Data Encodingsbinasciiâ Convert between binary and ASCIIquopriâ Encode and decode MIME quoted-printable data
- Structured Markup Processing Tools
htmlâ HyperText Markup Language supporthtml.parserâ Simple HTML and XHTML parserhtml.entitiesâ Definitions of HTML general entities- XML Processing Modules
xml.etree.ElementTreeâ The ElementTree XML APIxml.domâ The Document Object Model APIxml.dom.minidomâ Minimal 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.parsers.expatâ Fast XML parsing using Expat
- Internet Protocols and Support
webbrowserâ Convenient web-browser controllerwsgirefâ WSGI Utilities and Reference Implementationurllibâ URL handling modulesurllib.requestâ Extensible library for opening URLsurllib.responseâ Response classes used by urlliburllib.parseâ Parse URLs into componentsurllib.errorâ Exception classes raised by urllib.requesturllib.robotparserâ Parser for robots.txthttpâ HTTP moduleshttp.clientâ HTTP protocol clientftplibâ FTP protocol clientpoplibâ POP3 protocol clientimaplibâ IMAP4 protocol clientsmtplibâ SMTP protocol clientuuidâ UUID objects according to RFC 9562socketserverâ A framework for network servershttp.serverâ HTTP servershttp.cookiesâ HTTP state managementhttp.cookiejarâ Cookie handling for HTTP clientsxmlrpcâ XMLRPC server and client modulesxmlrpc.clientâ XML-RPC client accessxmlrpc.serverâ Basic XML-RPC serversipaddressâ IPv4/IPv6 manipulation library
- Multimedia Services
- Internationalization
- Graphical user interfaces with Tk
tkinterâ Python interface to Tcl/Tktkinter.colorchooserâ Color choosing dialogtkinter.fontâ Tkinter font wrapper- Tkinter Dialogs
tkinter.messageboxâ Tkinter message promptstkinter.scrolledtextâ Scrolled Text Widgettkinter.dndâ Drag and drop supporttkinter.ttkâ Tk themed widgets- IDLE â Python editor and shell
turtleâ Turtle graphics
- Development Tools
typingâ Support for type hintspydocâ Documentation generator and online help system- Python Development Mode
doctestâ Test interactive Python examplesunittestâ Unit testing frameworkunittest.mockâ mock object libraryunittest.mockâ getting startedtestâ Regression tests package for Pythontest.supportâ Utilities for the Python test suitetest.support.socket_helperâ Utilities for socket teststest.support.script_helperâ Utilities for the Python execution teststest.support.bytecode_helperâ Support tools for testing correct bytecode generationtest.support.threading_helperâ Utilities for threading teststest.support.os_helperâ Utilities for os teststest.support.import_helperâ Utilities for import teststest.support.warnings_helperâ Utilities for warnings tests
- Debugging and Profiling
- Software Packaging and Distribution
- Python Runtime Services
sysâ System-specific parameters and functionssys.monitoringâ Execution event monitoringsysconfigâ Provide access to Pythonâs configuration informationbuiltinsâ Built-in objects__main__â Top-level code environmentwarningsâ Warning controldataclassesâ Data Classescontextlibâ Utilities forwith-statement contextsabcâ Abstract Base Classesatexitâ Exit handlerstracebackâ Print or retrieve a stack traceback__future__â Future statement definitionsgcâ Garbage Collector interfaceinspectâ Inspect live objectsannotationlibâ Functionality for introspecting annotationssiteâ Site-specific configuration hook
- Custom Python Interpreters
- Importing Modules
zipimportâ Import modules from Zip archivespkgutilâ Package extension utilitymodulefinderâ Find modules used by a scriptrunpyâ Locating and executing Python modulesimportlibâ The implementation ofimportimportlib.resourcesâ Package resource reading, opening and accessimportlib.resources.abcâ Abstract base classes for resourcesimportlib.metadataâ Accessing package metadata- The initialization of the
sys.pathmodule search path
- Python Language Services
astâ Abstract syntax treessymtableâ Access to the compilerâs symbol tablestokenâ Constants used with Python parse treeskeywordâ Testing for Python keywordstokenizeâ Tokenizer for Python sourcetabnannyâ Detection of ambiguous indentationpyclbrâ Python module browser supportpy_compileâ Compile Python source filescompileallâ Byte-compile Python librariesdisâ Disassembler for Python bytecodepickletoolsâ Tools for pickle developers
- MS Windows Specific Services
- Unix-specific services
shlexâ Simple lexical analysisposixâ The most common POSIX system callspwdâ The password databasegrpâ The group databasetermiosâ POSIX style tty controlttyâ Terminal control functionsptyâ Pseudo-terminal utilitiesfcntlâ Thefcntlandioctlsystem callsresourceâ Resource usage informationsyslogâ Unix syslog library routines
- Modules command-line interface (CLI)
- Superseded Modules
- Removed Modules
- Security Considerations