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