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 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
- Non-essential Built-in Functions
- Built-in Constants
- Built-in Types
- Truth Value Testing
- Boolean Operations ---
and
,or
,not
- Comparisons
- Numeric Types ---
int
,float
,long
,complex
- Iterator Types
- Sequence Types ---
str
,unicode
,list
,tuple
,bytearray
,buffer
,xrange
- Set Types ---
set
,frozenset
- Mapping Types ---
dict
- File Objects
- memoryview type
- Context Manager Types
- Other Built-in Types
- Special Attributes
- Built-in Exceptions
- String Services
string
--- Common string operationsre
--- Regular expression operationsstruct
--- Interpret strings as packed binary datadifflib
--- Helpers for computing deltasStringIO
--- Read and write strings as filescStringIO
--- Faster version ofStringIO
textwrap
--- Text wrapping and fillingcodecs
--- Codec registry and base classesunicodedata
--- Unicode Databasestringprep
--- Internet String Preparationfpformat
--- Floating point conversions
- Data Types
datetime
--- Basic date and time typescalendar
--- General calendar-related functionscollections
--- High-performance container datatypesheapq
--- Heap queue algorithmbisect
--- Array bisection algorithmarray
--- Efficient arrays of numeric valuessets
--- Unordered collections of unique elementssched
--- Event schedulermutex
--- Mutual exclusion supportQueue
--- A synchronized queue classweakref
--- Weak referencesUserDict
--- Class wrapper for dictionary objectsUserList
--- Class wrapper for list objectsUserString
--- Class wrapper for string objectstypes
--- Names for built-in typesnew
--- Creation of runtime internal objectscopy
--- Shallow and deep copy operationspprint
--- Data pretty printerrepr
--- Alternaterepr()
implementation
- 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 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()
resultsstatvfs
--- Constants used withos.statvfs()
filecmp
--- 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 operationsdircache
--- Cached directory listingsmacpath
--- Mac OS 9 path manipulation functions
- Data Persistence
pickle
--- Python object serializationcPickle
--- A fasterpickle
copy_reg
--- Registerpickle
support functionsshelve
--- Python object persistencemarshal
--- Internal Python object serializationanydbm
--- Generic access to DBM-style databaseswhichdb
--- Guess which DBM module created a databasedbm
--- Simple "database" interfacegdbm
--- GNU's reinterpretation of dbmdbhash
--- DBM-style interface to the BSD database librarybsddb
--- Interface to Berkeley DB librarydumbdbm
--- Portable DBM implementationsqlite3
--- DB-API 2.0 interface for SQLite databases
- 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 conversionsargparse
--- Parser for command-line options, arguments and sub-commandsoptparse
--- Parser for command line optionsgetopt
--- C-style parser for command line optionslogging
--- Logging facility for Pythonlogging.config
--- Logging configurationlogging.handlers
--- Logging handlersgetpass
--- Portable password inputcurses
--- Terminal handling for character-cell displayscurses.textpad
--- Text input widget for curses programscurses.ascii
--- Utilities for ASCII characterscurses.panel
--- A panel stack extension for cursesplatform
--- Access to underlying platform's identifying dataerrno
--- Standard errno system symbolsctypes
--- A foreign function library for Python
- Optional Operating System Services
select
--- Waiting for I/O completionthreading
--- Higher-level threading interfacethread
--- Multiple threads of controldummy_threading
--- Drop-in replacement for thethreading
moduledummy_thread
--- Drop-in replacement for thethread
modulemultiprocessing
--- Process-based "threading" interfacemmap
--- Memory-mapped file supportreadline
--- GNU readline interfacerlcompleter
--- Completion function for GNU readline
- Interprocess Communication and Networking
subprocess
--- Subprocess managementsocket
--- Low-level networking interfacessl
--- TLS/SSL wrapper for socket objectssignal
--- Set handlers for asynchronous eventspopen2
--- Subprocesses with accessible I/O streamsasyncore
--- Asynchronous socket handlerasynchat
--- Asynchronous socket command/response handler
- Internet Data Handling
email
--- An email and MIME handling packagejson
--- JSON encoder and decodermailcap
--- Mailcap file handlingmailbox
--- Manipulate mailboxes in various formatsmhlib
--- Access to MH mailboxesmimetools
--- Tools for parsing MIME messagesmimetypes
--- Map filenames to MIME typesMimeWriter
--- Generic MIME file writermimify
--- MIME processing of mail messagesmultifile
--- Support for files containing distinct partsrfc822
--- Parse RFC 2822 mail headersbase64
--- 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
HTMLParser
--- Simple HTML and XHTML parsersgmllib
--- Simple SGML parserhtmllib
--- A parser for HTML documentshtmlentitydefs
--- Definitions of HTML general entities- XML Processing Modules
- XML vulnerabilities
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 controllercgi
--- Common Gateway Interface supportcgitb
--- Traceback manager for CGI scriptswsgiref
--- WSGI Utilities and Reference Implementationurllib
--- Open arbitrary resources by URLurllib2
--- extensible library for opening URLshttplib
--- 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 4122urlparse
--- Parse URLs into componentsSocketServer
--- A framework for network serversBaseHTTPServer
--- Basic HTTP serverSimpleHTTPServer
--- Simple HTTP request handlerCGIHTTPServer
--- CGI-capable HTTP request handlercookielib
--- Cookie handling for HTTP clientsCookie
--- HTTP state managementxmlrpclib
--- XML-RPC client accessSimpleXMLRPCServer
--- Basic XML-RPC serverDocXMLRPCServer
--- Self-documenting XML-RPC server
- Multimedia Services
audioop
--- Manipulate raw audio dataimageop
--- Manipulate raw image 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
- Software Packaging and Distribution
- Python Runtime Services
sys
--- System-specific parameters and functionssysconfig
--- Provide access to Python's configuration information__builtin__
--- Built-in objectsfuture_builtins
--- Python 3 builtins__main__
--- Top-level script environmentwarnings
--- Warning controlcontextlib
--- Utilities forwith
-statement contextsabc
--- Abstract Base Classesatexit
--- Exit handlerstraceback
--- Print or retrieve a stack traceback__future__
--- Future statement definitionsgc
--- Garbage Collector interfaceinspect
--- Inspect live objectssite
--- Site-specific configuration hookuser
--- User-specific configuration hookfpectl
--- Floating point exception control
- Custom Python Interpreters
- Restricted Execution
- Importing Modules
- Python Language Services
parser
--- Access Python parse treesast
--- Abstract Syntax Treessymtable
--- 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
- Python compiler package
- 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 passwordsdl
--- Call C functions in shared objectstermios
--- POSIX style tty controltty
--- Terminal control functionspty
--- Pseudo-terminal utilitiesfcntl
--- Thefcntl
andioctl
system callspipes
--- Interface to shell pipelinesposixfile
--- File-like objects with locking supportresource
--- Resource usage informationnis
--- Interface to Sun's NIS (Yellow Pages)syslog
--- Unix syslog library routinescommands
--- Utilities for running commands
- Mac OS X specific services
ic
--- Access to the Mac OS X Internet ConfigMacOS
--- Access to Mac OS interpreter featuresmacostools
--- Convenience routines for file manipulationfindertools
--- The finder's Apple Events interfaceEasyDialogs
--- Basic Macintosh dialogsFrameWork
--- Interactive application frameworkautoGIL
--- Global Interpreter Lock handling in event loops- Mac OS Toolbox Modules
ColorPicker
--- Color selection dialog
- MacPython OSA Modules
- SGI IRIX Specific Services
al
--- Audio functions on the SGIAL
--- Constants used with theal
modulecd
--- CD-ROM access on SGI systemsfl
--- FORMS library for graphical user interfacesFL
--- Constants used with thefl
moduleflp
--- Functions for loading stored FORMS designsfm
--- Font Manager interfacegl
--- Graphics Library interfaceDEVICE
--- Constants used with thegl
moduleGL
--- Constants used with thegl
moduleimgfile
--- Support for SGI imglib filesjpeg
--- Read and write JPEG files
- SunOS Specific Services
- Undocumented Modules