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.
Pythons 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
stringCommon string operationsstring.templatelibSupport for template string literalsreRegular expression operationsdifflibHelpers for computing deltastextwrapText wrapping and fillingunicodedataUnicode DatabasestringprepInternet String PreparationreadlineGNU readline interfacerlcompleterCompletion function for GNU readline
- Binary Data Services
- Data Types
datetimeBasic date and time typeszoneinfoIANA time zone supportcalendarGeneral calendar-related functionscollectionsContainer datatypescollections.abcAbstract Base Classes for ContainersheapqHeap queue algorithmbisectArray bisection algorithmarrayEfficient arrays of numeric valuesweakrefWeak referencestypesDynamic type creation and names for built-in typescopyShallow and deep copy operationspprintData pretty printerreprlibAlternaterepr()implementationenumSupport for enumerationsgraphlibFunctionality to operate with graph-like structures
- Numeric and Mathematical Modules
- Functional Programming Modules
- File and Directory Access
pathlibObject-oriented filesystem pathsos.pathCommon pathname manipulationsstatInterpretingstat()resultsfilecmpFile and Directory ComparisonstempfileGenerate temporary files and directoriesglobUnix style pathname pattern expansionfnmatchUnix filename pattern matchinglinecacheRandom access to text linesshutilHigh-level file operations
- Data Persistence
- Data Compression and Archiving
- The
compressionpackage compression.zstdCompression compatible with the Zstandard formatzlibCompression compatible with gzipgzipSupport for gzip filesbz2Support for bzip2 compressionlzmaCompression using the LZMA algorithmzipfileWork with ZIP archivestarfileRead and write tar archive files
- The
- File Formats
- Cryptographic Services
- Generic Operating System Services
osMiscellaneous operating system interfacesioCore tools for working with streamstimeTime access and conversionsloggingLogging facility for Pythonlogging.configLogging configurationlogging.handlersLogging handlersplatformAccess to underlying platforms identifying dataerrnoStandard errno system symbolsctypesA foreign function library for Python
- Command-line interface libraries
argparseParser for command-line options, arguments and subcommandsoptparseParser for command line optionsgetpassPortable password inputfileinputIterate over lines from multiple input streamscursesTerminal handling for character-cell displayscurses.textpadText input widget for curses programscurses.asciiUtilities for ASCII characterscurses.panelA panel stack extension for cursescmdSupport for line-oriented command interpreters
- Concurrent Execution
threadingThread-based parallelismmultiprocessingProcess-based parallelismmultiprocessing.shared_memoryShared memory for direct access across processes- The
concurrentpackage concurrent.futuresLaunching parallel tasksconcurrent.interpretersMultiple interpreters in the same processsubprocessSubprocess managementschedEvent schedulerqueueA synchronized queue classcontextvarsContext Variables_threadLow-level threading API
- Networking and Interprocess Communication
- Internet Data Handling
emailAn email and MIME handling packagejsonJSON encoder and decodermailboxManipulate mailboxes in various formatsmimetypesMap filenames to MIME typesbase64Base16, Base32, Base64, Base85 Data EncodingsbinasciiConvert between binary and ASCIIquopriEncode and decode MIME quoted-printable data
- Structured Markup Processing Tools
htmlHyperText Markup Language supporthtml.parserSimple HTML and XHTML parserhtml.entitiesDefinitions of HTML general entities- XML Processing Modules
xml.etree.ElementTreeThe ElementTree XML APIxml.domThe Document Object Model APIxml.dom.minidomMinimal DOM implementationxml.dom.pulldomSupport for building partial DOM treesxml.saxSupport for SAX2 parsersxml.sax.handlerBase classes for SAX handlersxml.sax.saxutilsSAX Utilitiesxml.sax.xmlreaderInterface for XML parsersxml.parsers.expatFast XML parsing using Expat
- Internet Protocols and Support
webbrowserConvenient web-browser controllerwsgirefWSGI Utilities and Reference ImplementationurllibURL handling modulesurllib.requestExtensible library for opening URLsurllib.responseResponse classes used by urlliburllib.parseParse URLs into componentsurllib.errorException classes raised by urllib.requesturllib.robotparserParser for robots.txthttpHTTP moduleshttp.clientHTTP protocol clientftplibFTP protocol clientpoplibPOP3 protocol clientimaplibIMAP4 protocol clientsmtplibSMTP protocol clientuuidUUID objects according to RFC 9562socketserverA framework for network servershttp.serverHTTP servershttp.cookiesHTTP state managementhttp.cookiejarCookie handling for HTTP clientsxmlrpcXMLRPC server and client modulesxmlrpc.clientXML-RPC client accessxmlrpc.serverBasic XML-RPC serversipaddressIPv4/IPv6 manipulation library
- Multimedia Services
- Internationalization
- Graphical user interfaces with Tk
tkinterPython interface to Tcl/Tktkinter.colorchooserColor choosing dialogtkinter.fontTkinter font wrapper- Tkinter dialogs
tkinter.messageboxTkinter message promptstkinter.scrolledtextScrolled text widgettkinter.dndDrag and drop supporttkinter.ttkTk themed widgets- IDLE Python editor and shell
turtleTurtle graphics
- Development Tools
typingSupport for type hintspydocDocumentation generator and online help system- Python Development Mode
doctestTest interactive Python examplesunittestUnit testing frameworkunittest.mockmock object libraryunittest.mockgetting startedtestRegression tests package for Pythontest.supportUtilities for the Python test suitetest.support.socket_helperUtilities for socket teststest.support.script_helperUtilities for the Python execution teststest.support.bytecode_helperSupport tools for testing correct bytecode generationtest.support.threading_helperUtilities for threading teststest.support.os_helperUtilities for os teststest.support.import_helperUtilities for import teststest.support.warnings_helperUtilities for warnings tests
- Debugging and Profiling
- Software Packaging and Distribution
- Python Runtime Services
sysSystem-specific parameters and functionssys.monitoringExecution event monitoringsysconfigProvide access to Pythons configuration informationbuiltinsBuilt-in objects__main__Top-level code environmentwarningsWarning controldataclassesData ClassescontextlibUtilities forwith-statement contextsabcAbstract Base ClassesatexitExit handlerstracebackPrint or retrieve a stack traceback__future__Future statement definitionsgcGarbage Collector interfaceinspectInspect live objectsannotationlibFunctionality for introspecting annotationssiteSite-specific configuration hook
- Custom Python Interpreters
- Importing Modules
zipimportImport modules from Zip archivespkgutilPackage extension utilitymodulefinderFind modules used by a scriptrunpyLocating and executing Python modulesimportlibThe implementation ofimportimportlib.resourcesPackage resource reading, opening and accessimportlib.resources.abcAbstract base classes for resourcesimportlib.metadataAccessing package metadata- The initialization of the
sys.pathmodule search path
- Python Language Services
astAbstract syntax treessymtableAccess to the compilers symbol tablestokenConstants used with Python parse treeskeywordTesting for Python keywordstokenizeTokenizer for Python sourcetabnannyDetection of ambiguous indentationpyclbrPython module browser supportpy_compileCompile Python source filescompileallByte-compile Python librariesdisDisassembler for Python bytecodepickletoolsTools for pickle developers
- MS Windows Specific Services
- Unix-specific services
shlexSimple lexical analysisposixThe most common POSIX system callspwdThe password databasegrpThe group databasetermiosPOSIX style tty controlttyTerminal control functionsptyPseudo-terminal utilitiesfcntlThefcntlandioctlsystem callsresourceResource usage informationsyslogUnix syslog library routines
- Modules command-line interface (CLI)
- Superseded Modules
- Removed Modules
- Security Considerations