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 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.
- 1. Introduction
- 2. Built-in Functions
- 3. Non-essential Built-in Functions
- 4. Built-in Constants
- 5. Built-in Types
- 5.1. Truth Value Testing
- 5.2. Boolean Operations
and,or,not - 5.3. Comparisons
- 5.4. Numeric Types
int,float,long,complex - 5.5. Iterator Types
- 5.6. Sequence Types
str,unicode,list,tuple,bytearray,buffer,xrange - 5.7. Set Types
set,frozenset - 5.8. Mapping Types
dict - 5.9. File Objects
- 5.10. memoryview type
- 5.11. Context Manager Types
- 5.12. Other Built-in Types
- 5.13. Special Attributes
- 6. Built-in Exceptions
- 7. String Services
- 7.1.
stringCommon string operations - 7.2.
reRegular expression operations - 7.3.
structInterpret strings as packed binary data - 7.4.
difflibHelpers for computing deltas - 7.5.
StringIORead and write strings as files - 7.6.
cStringIOFaster version ofStringIO - 7.7.
textwrapText wrapping and filling - 7.8.
codecsCodec registry and base classes - 7.9.
unicodedataUnicode Database - 7.10.
stringprepInternet String Preparation - 7.11.
fpformatFloating point conversions
- 7.1.
- 8. Data Types
- 8.1.
datetimeBasic date and time types - 8.2.
calendarGeneral calendar-related functions - 8.3.
collectionsHigh-performance container datatypes - 8.4.
heapqHeap queue algorithm - 8.5.
bisectArray bisection algorithm - 8.6.
arrayEfficient arrays of numeric values - 8.7.
setsUnordered collections of unique elements - 8.8.
schedEvent scheduler - 8.9.
mutexMutual exclusion support - 8.10.
QueueA synchronized queue class - 8.11.
weakrefWeak references - 8.12.
UserDictClass wrapper for dictionary objects - 8.13.
UserListClass wrapper for list objects - 8.14.
UserStringClass wrapper for string objects - 8.15.
typesNames for built-in types - 8.16.
newCreation of runtime internal objects - 8.17.
copyShallow and deep copy operations - 8.18.
pprintData pretty printer - 8.19.
reprAlternaterepr()implementation
- 8.1.
- 9. Numeric and Mathematical Modules
- 9.1.
numbersNumeric abstract base classes - 9.2.
mathMathematical functions - 9.3.
cmathMathematical functions for complex numbers - 9.4.
decimalDecimal fixed point and floating point arithmetic - 9.5.
fractionsRational numbers - 9.6.
randomGenerate pseudo-random numbers - 9.7.
itertoolsFunctions creating iterators for efficient looping - 9.8.
functoolsHigher-order functions and operations on callable objects - 9.9.
operatorStandard operators as functions
- 9.1.
- 10. File and Directory Access
- 10.1.
os.pathCommon pathname manipulations - 10.2.
fileinputIterate over lines from multiple input streams - 10.3.
statInterpretingstat()results - 10.4.
statvfsConstants used withos.statvfs() - 10.5.
filecmpFile and Directory Comparisons - 10.6.
tempfileGenerate temporary files and directories - 10.7.
globUnix style pathname pattern expansion - 10.8.
fnmatchUnix filename pattern matching - 10.9.
linecacheRandom access to text lines - 10.10.
shutilHigh-level file operations - 10.11.
dircacheCached directory listings - 10.12.
macpathMac OS 9 path manipulation functions
- 10.1.
- 11. Data Persistence
- 11.1.
picklePython object serialization - 11.2.
cPickleA fasterpickle - 11.3.
copy_regRegisterpicklesupport functions - 11.4.
shelvePython object persistence - 11.5.
marshalInternal Python object serialization - 11.6.
anydbmGeneric access to DBM-style databases - 11.7.
whichdbGuess which DBM module created a database - 11.8.
dbmSimple database interface - 11.9.
gdbmGNUs reinterpretation of dbm - 11.10.
dbhashDBM-style interface to the BSD database library - 11.11.
bsddbInterface to Berkeley DB library - 11.12.
dumbdbmPortable DBM implementation - 11.13.
sqlite3DB-API 2.0 interface for SQLite databases
- 11.1.
- 12. Data Compression and Archiving
- 13. File Formats
- 14. Cryptographic Services
- 15. Generic Operating System Services
- 15.1.
osMiscellaneous operating system interfaces - 15.2.
ioCore tools for working with streams - 15.3.
timeTime access and conversions - 15.4.
argparseParser for command-line options, arguments and sub-commands - 15.5.
optparseParser for command line options - 15.6.
getoptC-style parser for command line options - 15.7.
loggingLogging facility for Python - 15.8.
logging.configLogging configuration - 15.9.
logging.handlersLogging handlers - 15.10.
getpassPortable password input - 15.11.
cursesTerminal handling for character-cell displays - 15.12.
curses.textpadText input widget for curses programs - 15.13.
curses.asciiUtilities for ASCII characters - 15.14.
curses.panelA panel stack extension for curses - 15.15.
platformAccess to underlying platforms identifying data - 15.16.
errnoStandard errno system symbols - 15.17.
ctypesA foreign function library for Python
- 15.1.
- 16. Optional Operating System Services
- 16.1.
selectWaiting for I/O completion - 16.2.
threadingHigher-level threading interface - 16.3.
threadMultiple threads of control - 16.4.
dummy_threadingDrop-in replacement for thethreadingmodule - 16.5.
dummy_threadDrop-in replacement for thethreadmodule - 16.6.
multiprocessingProcess-based threading interface - 16.7.
mmapMemory-mapped file support - 16.8.
readlineGNU readline interface - 16.9.
rlcompleterCompletion function for GNU readline
- 16.1.
- 17. Interprocess Communication and Networking
- 17.1.
subprocessSubprocess management - 17.2.
socketLow-level networking interface - 17.3.
sslTLS/SSL wrapper for socket objects - 17.4.
signalSet handlers for asynchronous events - 17.5.
popen2Subprocesses with accessible I/O streams - 17.6.
asyncoreAsynchronous socket handler - 17.7.
asynchatAsynchronous socket command/response handler
- 17.1.
- 18. Internet Data Handling
- 18.1.
emailAn email and MIME handling package - 18.2.
jsonJSON encoder and decoder - 18.3.
mailcapMailcap file handling - 18.4.
mailboxManipulate mailboxes in various formats - 18.5.
mhlibAccess to MH mailboxes - 18.6.
mimetoolsTools for parsing MIME messages - 18.7.
mimetypesMap filenames to MIME types - 18.8.
MimeWriterGeneric MIME file writer - 18.9.
mimifyMIME processing of mail messages - 18.10.
multifileSupport for files containing distinct parts - 18.11.
rfc822Parse RFC 2822 mail headers - 18.12.
base64RFC 3548: Base16, Base32, Base64 Data Encodings - 18.13.
binhexEncode and decode binhex4 files - 18.14.
binasciiConvert between binary and ASCII - 18.15.
quopriEncode and decode MIME quoted-printable data - 18.16.
uuEncode and decode uuencode files
- 18.1.
- 19. Structured Markup Processing Tools
- 19.1.
HTMLParserSimple HTML and XHTML parser - 19.2.
sgmllibSimple SGML parser - 19.3.
htmllibA parser for HTML documents - 19.4.
htmlentitydefsDefinitions of HTML general entities - 19.5. XML Processing Modules
- 19.6. XML vulnerabilities
- 19.7.
xml.etree.ElementTreeThe ElementTree XML API - 19.8.
xml.domThe Document Object Model API - 19.9.
xml.dom.minidomMinimal DOM implementation - 19.10.
xml.dom.pulldomSupport for building partial DOM trees - 19.11.
xml.saxSupport for SAX2 parsers - 19.12.
xml.sax.handlerBase classes for SAX handlers - 19.13.
xml.sax.saxutilsSAX Utilities - 19.14.
xml.sax.xmlreaderInterface for XML parsers - 19.15.
xml.parsers.expatFast XML parsing using Expat
- 19.1.
- 20. Internet Protocols and Support
- 20.1.
webbrowserConvenient Web-browser controller - 20.2.
cgiCommon Gateway Interface support - 20.3.
cgitbTraceback manager for CGI scripts - 20.4.
wsgirefWSGI Utilities and Reference Implementation - 20.5.
urllibOpen arbitrary resources by URL - 20.6.
urllib2extensible library for opening URLs - 20.7.
httplibHTTP protocol client - 20.8.
ftplibFTP protocol client - 20.9.
poplibPOP3 protocol client - 20.10.
imaplibIMAP4 protocol client - 20.11.
nntplibNNTP protocol client - 20.12.
smtplibSMTP protocol client - 20.13.
smtpdSMTP Server - 20.14.
telnetlibTelnet client - 20.15.
uuidUUID objects according to RFC 4122 - 20.16.
urlparseParse URLs into components - 20.17.
SocketServerA framework for network servers - 20.18.
BaseHTTPServerBasic HTTP server - 20.19.
SimpleHTTPServerSimple HTTP request handler - 20.20.
CGIHTTPServerCGI-capable HTTP request handler - 20.21.
cookielibCookie handling for HTTP clients - 20.22.
CookieHTTP state management - 20.23.
xmlrpclibXML-RPC client access - 20.24.
SimpleXMLRPCServerBasic XML-RPC server - 20.25.
DocXMLRPCServerSelf-documenting XML-RPC server
- 20.1.
- 21. Multimedia Services
- 21.1.
audioopManipulate raw audio data - 21.2.
imageopManipulate raw image data - 21.3.
aifcRead and write AIFF and AIFC files - 21.4.
sunauRead and write Sun AU files - 21.5.
waveRead and write WAV files - 21.6.
chunkRead IFF chunked data - 21.7.
colorsysConversions between color systems - 21.8.
imghdrDetermine the type of an image - 21.9.
sndhdrDetermine type of sound file - 21.10.
ossaudiodevAccess to OSS-compatible audio devices
- 21.1.
- 22. Internationalization
- 23. Program Frameworks
- 24. Graphical User Interfaces with Tk
- 25. Development Tools
- 26. Debugging and Profiling
- 27. Software Packaging and Distribution
- 28. Python Runtime Services
- 28.1.
sysSystem-specific parameters and functions - 28.2.
sysconfigProvide access to Pythons configuration information - 28.3.
__builtin__Built-in objects - 28.4.
future_builtinsPython 3 builtins - 28.5.
__main__Top-level script environment - 28.6.
warningsWarning control - 28.7.
contextlibUtilities forwith-statement contexts - 28.8.
abcAbstract Base Classes - 28.9.
atexitExit handlers - 28.10.
tracebackPrint or retrieve a stack traceback - 28.11.
__future__Future statement definitions - 28.12.
gcGarbage Collector interface - 28.13.
inspectInspect live objects - 28.14.
siteSite-specific configuration hook - 28.15.
userUser-specific configuration hook - 28.16.
fpectlFloating point exception control
- 28.1.
- 29. Custom Python Interpreters
- 30. Restricted Execution
- 31. Importing Modules
- 31.1.
impAccess theimportinternals - 31.2.
importlibConvenience wrappers for__import__() - 31.3.
imputilImport utilities - 31.4.
zipimportImport modules from Zip archives - 31.5.
pkgutilPackage extension utility - 31.6.
modulefinderFind modules used by a script - 31.7.
runpyLocating and executing Python modules
- 31.1.
- 32. Python Language Services
- 32.1.
parserAccess Python parse trees - 32.2.
astAbstract Syntax Trees - 32.3.
symtableAccess to the compilers symbol tables - 32.4.
symbolConstants used with Python parse trees - 32.5.
tokenConstants used with Python parse trees - 32.6.
keywordTesting for Python keywords - 32.7.
tokenizeTokenizer for Python source - 32.8.
tabnannyDetection of ambiguous indentation - 32.9.
pyclbrPython class browser support - 32.10.
py_compileCompile Python source files - 32.11.
compileallByte-compile Python libraries - 32.12.
disDisassembler for Python bytecode - 32.13.
pickletoolsTools for pickle developers
- 32.1.
- 33. Python compiler package
- 34. Miscellaneous Services
- 35. MS Windows Specific Services
- 36. Unix Specific Services
- 36.1.
posixThe most common POSIX system calls - 36.2.
pwdThe password database - 36.3.
spwdThe shadow password database - 36.4.
grpThe group database - 36.5.
cryptFunction to check Unix passwords - 36.6.
dlCall C functions in shared objects - 36.7.
termiosPOSIX style tty control - 36.8.
ttyTerminal control functions - 36.9.
ptyPseudo-terminal utilities - 36.10.
fcntlThefcntlandioctlsystem calls - 36.11.
pipesInterface to shell pipelines - 36.12.
posixfileFile-like objects with locking support - 36.13.
resourceResource usage information - 36.14.
nisInterface to Suns NIS (Yellow Pages) - 36.15.
syslogUnix syslog library routines - 36.16.
commandsUtilities for running commands
- 36.1.
- 37. Mac OS X specific services
- 37.1.
icAccess to the Mac OS X Internet Config - 37.2.
MacOSAccess to Mac OS interpreter features - 37.3.
macostoolsConvenience routines for file manipulation - 37.4.
findertoolsThe finders Apple Events interface - 37.5.
EasyDialogsBasic Macintosh dialogs - 37.6.
FrameWorkInteractive application framework - 37.7.
autoGILGlobal Interpreter Lock handling in event loops - 37.8. Mac OS Toolbox Modules
- 37.9.
ColorPickerColor selection dialog
- 37.1.
- 38. MacPython OSA Modules
- 39. SGI IRIX Specific Services
- 39.1.
alAudio functions on the SGI - 39.2.
ALConstants used with thealmodule - 39.3.
cdCD-ROM access on SGI systems - 39.4.
flFORMS library for graphical user interfaces - 39.5.
FLConstants used with theflmodule - 39.6.
flpFunctions for loading stored FORMS designs - 39.7.
fmFont Manager interface - 39.8.
glGraphics Library interface - 39.9.
DEVICEConstants used with theglmodule - 39.10.
GLConstants used with theglmodule - 39.11.
imgfileSupport for SGI imglib files - 39.12.
jpegRead and write JPEG files
- 39.1.
- 40. SunOS Specific Services
- 41. Undocumented Modules