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