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 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.
stringβ Common string operations - 7.2.
reβ Regular expression operations - 7.3.
structβ Interpret strings as packed binary data - 7.4.
difflibβ Helpers for computing deltas - 7.5.
StringIOβ Read and write strings as files - 7.6.
cStringIOβ Faster version ofStringIO - 7.7.
textwrapβ Text wrapping and filling - 7.8.
codecsβ Codec registry and base classes - 7.9.
unicodedataβ Unicode Database - 7.10.
stringprepβ Internet String Preparation - 7.11.
fpformatβ Floating point conversions
- 7.1.
- 8. Data Types
- 8.1.
datetimeβ Basic date and time types - 8.2.
calendarβ General calendar-related functions - 8.3.
collectionsβ High-performance container datatypes - 8.4.
heapqβ Heap queue algorithm - 8.5.
bisectβ Array bisection algorithm - 8.6.
arrayβ Efficient arrays of numeric values - 8.7.
setsβ Unordered collections of unique elements - 8.8.
schedβ Event scheduler - 8.9.
mutexβ Mutual exclusion support - 8.10.
Queueβ A synchronized queue class - 8.11.
weakrefβ Weak references - 8.12.
UserDictβ Class wrapper for dictionary objects - 8.13.
UserListβ Class wrapper for list objects - 8.14.
UserStringβ Class wrapper for string objects - 8.15.
typesβ Names for built-in types - 8.16.
newβ Creation of runtime internal objects - 8.17.
copyβ Shallow and deep copy operations - 8.18.
pprintβ Data pretty printer - 8.19.
reprβ Alternaterepr()implementation
- 8.1.
- 9. Numeric and Mathematical Modules
- 9.1.
numbersβ Numeric abstract base classes - 9.2.
mathβ Mathematical functions - 9.3.
cmathβ Mathematical functions for complex numbers - 9.4.
decimalβ Decimal fixed point and floating point arithmetic - 9.5.
fractionsβ Rational numbers - 9.6.
randomβ Generate pseudo-random numbers - 9.7.
itertoolsβ Functions creating iterators for efficient looping - 9.8.
functoolsβ Higher-order functions and operations on callable objects - 9.9.
operatorβ Standard operators as functions
- 9.1.
- 10. File and Directory Access
- 10.1.
os.pathβ Common pathname manipulations - 10.2.
fileinputβ Iterate over lines from multiple input streams - 10.3.
statβ Interpretingstat()results - 10.4.
statvfsβ Constants used withos.statvfs() - 10.5.
filecmpβ File and Directory Comparisons - 10.6.
tempfileβ Generate temporary files and directories - 10.7.
globβ Unix style pathname pattern expansion - 10.8.
fnmatchβ Unix filename pattern matching - 10.9.
linecacheβ Random access to text lines - 10.10.
shutilβ High-level file operations - 10.11.
dircacheβ Cached directory listings - 10.12.
macpathβ Mac OS 9 path manipulation functions
- 10.1.
- 11. Data Persistence
- 11.1.
pickleβ Python object serialization - 11.2.
cPickleβ A fasterpickle - 11.3.
copy_regβ Registerpicklesupport functions - 11.4.
shelveβ Python object persistence - 11.5.
marshalβ Internal Python object serialization - 11.6.
anydbmβ Generic access to DBM-style databases - 11.7.
whichdbβ Guess which DBM module created a database - 11.8.
dbmβ Simple βdatabaseβ interface - 11.9.
gdbmβ GNUβs reinterpretation of dbm - 11.10.
dbhashβ DBM-style interface to the BSD database library - 11.11.
bsddbβ Interface to Berkeley DB library - 11.12.
dumbdbmβ Portable DBM implementation - 11.13.
sqlite3β DB-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.
osβ Miscellaneous operating system interfaces - 15.2.
ioβ Core tools for working with streams - 15.3.
timeβ Time access and conversions - 15.4.
argparseβ Parser for command-line options, arguments and sub-commands - 15.5.
optparseβ Parser for command line options - 15.6.
getoptβ C-style parser for command line options - 15.7.
loggingβ Logging facility for Python - 15.8.
logging.configβ Logging configuration - 15.9.
logging.handlersβ Logging handlers - 15.10.
getpassβ Portable password input - 15.11.
cursesβ Terminal handling for character-cell displays - 15.12.
curses.textpadβ Text input widget for curses programs - 15.13.
curses.asciiβ Utilities for ASCII characters - 15.14.
curses.panelβ A panel stack extension for curses - 15.15.
platformβ Access to underlying platformβs identifying data - 15.16.
errnoβ Standard errno system symbols - 15.17.
ctypesβ A foreign function library for Python
- 15.1.
- 16. Optional Operating System Services
- 16.1.
selectβ Waiting for I/O completion - 16.2.
threadingβ Higher-level threading interface - 16.3.
threadβ Multiple threads of control - 16.4.
dummy_threadingβ Drop-in replacement for thethreadingmodule - 16.5.
dummy_threadβ Drop-in replacement for thethreadmodule - 16.6.
multiprocessingβ Process-based βthreadingβ interface - 16.7.
mmapβ Memory-mapped file support - 16.8.
readlineβ GNU readline interface - 16.9.
rlcompleterβ Completion function for GNU readline
- 16.1.
- 17. Interprocess Communication and Networking
- 17.1.
subprocessβ Subprocess management - 17.2.
socketβ Low-level networking interface - 17.3.
sslβ TLS/SSL wrapper for socket objects - 17.4.
signalβ Set handlers for asynchronous events - 17.5.
popen2β Subprocesses with accessible I/O streams - 17.6.
asyncoreβ Asynchronous socket handler - 17.7.
asynchatβ Asynchronous socket command/response handler
- 17.1.
- 18. Internet Data Handling
- 18.1.
emailβ An email and MIME handling package - 18.2.
jsonβ JSON encoder and decoder - 18.3.
mailcapβ Mailcap file handling - 18.4.
mailboxβ Manipulate mailboxes in various formats - 18.5.
mhlibβ Access to MH mailboxes - 18.6.
mimetoolsβ Tools for parsing MIME messages - 18.7.
mimetypesβ Map filenames to MIME types - 18.8.
MimeWriterβ Generic MIME file writer - 18.9.
mimifyβ MIME processing of mail messages - 18.10.
multifileβ Support for files containing distinct parts - 18.11.
rfc822β Parse RFC 2822 mail headers - 18.12.
base64β RFC 3548: Base16, Base32, Base64 Data Encodings - 18.13.
binhexβ Encode and decode binhex4 files - 18.14.
binasciiβ Convert between binary and ASCII - 18.15.
quopriβ Encode and decode MIME quoted-printable data - 18.16.
uuβ Encode and decode uuencode files
- 18.1.
- 19. Structured Markup Processing Tools
- 19.1.
HTMLParserβ Simple HTML and XHTML parser - 19.2.
sgmllibβ Simple SGML parser - 19.3.
htmllibβ A parser for HTML documents - 19.4.
htmlentitydefsβ Definitions of HTML general entities - 19.5. XML Processing Modules
- 19.6. XML vulnerabilities
- 19.7.
xml.etree.ElementTreeβ The ElementTree XML API - 19.8.
xml.domβ The Document Object Model API - 19.9.
xml.dom.minidomβ Minimal DOM implementation - 19.10.
xml.dom.pulldomβ Support for building partial DOM trees - 19.11.
xml.saxβ Support for SAX2 parsers - 19.12.
xml.sax.handlerβ Base classes for SAX handlers - 19.13.
xml.sax.saxutilsβ SAX Utilities - 19.14.
xml.sax.xmlreaderβ Interface for XML parsers - 19.15.
xml.parsers.expatβ Fast XML parsing using Expat
- 19.1.
- 20. Internet Protocols and Support
- 20.1.
webbrowserβ Convenient Web-browser controller - 20.2.
cgiβ Common Gateway Interface support - 20.3.
cgitbβ Traceback manager for CGI scripts - 20.4.
wsgirefβ WSGI Utilities and Reference Implementation - 20.5.
urllibβ Open arbitrary resources by URL - 20.6.
urllib2β extensible library for opening URLs - 20.7.
httplibβ HTTP protocol client - 20.8.
ftplibβ FTP protocol client - 20.9.
poplibβ POP3 protocol client - 20.10.
imaplibβ IMAP4 protocol client - 20.11.
nntplibβ NNTP protocol client - 20.12.
smtplibβ SMTP protocol client - 20.13.
smtpdβ SMTP Server - 20.14.
telnetlibβ Telnet client - 20.15.
uuidβ UUID objects according to RFC 4122 - 20.16.
urlparseβ Parse URLs into components - 20.17.
SocketServerβ A framework for network servers - 20.18.
BaseHTTPServerβ Basic HTTP server - 20.19.
SimpleHTTPServerβ Simple HTTP request handler - 20.20.
CGIHTTPServerβ CGI-capable HTTP request handler - 20.21.
cookielibβ Cookie handling for HTTP clients - 20.22.
Cookieβ HTTP state management - 20.23.
xmlrpclibβ XML-RPC client access - 20.24.
SimpleXMLRPCServerβ Basic XML-RPC server - 20.25.
DocXMLRPCServerβ Self-documenting XML-RPC server
- 20.1.
- 21. Multimedia Services
- 21.1.
audioopβ Manipulate raw audio data - 21.2.
imageopβ Manipulate raw image data - 21.3.
aifcβ Read and write AIFF and AIFC files - 21.4.
sunauβ Read and write Sun AU files - 21.5.
waveβ Read and write WAV files - 21.6.
chunkβ Read IFF chunked data - 21.7.
colorsysβ Conversions between color systems - 21.8.
imghdrβ Determine the type of an image - 21.9.
sndhdrβ Determine type of sound file - 21.10.
ossaudiodevβ Access to OSS-compatible audio devices
- 21.1.
- 22. Internationalization
- 23. Program Frameworks
- 24. Graphical User Interfaces with Tk
- 25. Development Tools
- 25.1.
pydocβ Documentation generator and online help system - 25.2.
doctestβ Test interactive Python examples - 25.3.
unittestβ Unit testing framework - 25.4. 2to3 - Automated Python 2 to 3 code translation
- 25.5.
testβ Regression tests package for Python - 25.6.
test.supportβ Utility functions for tests
- 25.1.
- 26. Debugging and Profiling
- 27. Software Packaging and Distribution
- 28. Python Runtime Services
- 28.1.
sysβ System-specific parameters and functions - 28.2.
sysconfigβ Provide access to Pythonβs configuration information - 28.3.
__builtin__β Built-in objects - 28.4.
future_builtinsβ Python 3 builtins - 28.5.
__main__β Top-level script environment - 28.6.
warningsβ Warning control - 28.7.
contextlibβ Utilities forwith-statement contexts - 28.8.
abcβ Abstract Base Classes - 28.9.
atexitβ Exit handlers - 28.10.
tracebackβ Print or retrieve a stack traceback - 28.11.
__future__β Future statement definitions - 28.12.
gcβ Garbage Collector interface - 28.13.
inspectβ Inspect live objects - 28.14.
siteβ Site-specific configuration hook - 28.15.
userβ User-specific configuration hook - 28.16.
fpectlβ Floating point exception control
- 28.1.
- 29. Custom Python Interpreters
- 30. Restricted Execution
- 31. Importing Modules
- 31.1.
impβ Access theimportinternals - 31.2.
importlibβ Convenience wrappers for__import__() - 31.3.
imputilβ Import utilities - 31.4.
zipimportβ Import modules from Zip archives - 31.5.
pkgutilβ Package extension utility - 31.6.
modulefinderβ Find modules used by a script - 31.7.
runpyβ Locating and executing Python modules
- 31.1.
- 32. Python Language Services
- 32.1.
parserβ Access Python parse trees - 32.2.
astβ Abstract Syntax Trees - 32.3.
symtableβ Access to the compilerβs symbol tables - 32.4.
symbolβ Constants used with Python parse trees - 32.5.
tokenβ Constants used with Python parse trees - 32.6.
keywordβ Testing for Python keywords - 32.7.
tokenizeβ Tokenizer for Python source - 32.8.
tabnannyβ Detection of ambiguous indentation - 32.9.
pyclbrβ Python class browser support - 32.10.
py_compileβ Compile Python source files - 32.11.
compileallβ Byte-compile Python libraries - 32.12.
disβ Disassembler for Python bytecode - 32.13.
pickletoolsβ Tools for pickle developers
- 32.1.
- 33. Python compiler package
- 34. Miscellaneous Services
- 35. MS Windows Specific Services
- 36. Unix Specific Services
- 36.1.
posixβ The most common POSIX system calls - 36.2.
pwdβ The password database - 36.3.
spwdβ The shadow password database - 36.4.
grpβ The group database - 36.5.
cryptβ Function to check Unix passwords - 36.6.
dlβ Call C functions in shared objects - 36.7.
termiosβ POSIX style tty control - 36.8.
ttyβ Terminal control functions - 36.9.
ptyβ Pseudo-terminal utilities - 36.10.
fcntlβ Thefcntlandioctlsystem calls - 36.11.
pipesβ Interface to shell pipelines - 36.12.
posixfileβ File-like objects with locking support - 36.13.
resourceβ Resource usage information - 36.14.
nisβ Interface to Sunβs NIS (Yellow Pages) - 36.15.
syslogβ Unix syslog library routines - 36.16.
commandsβ Utilities for running commands
- 36.1.
- 37. Mac OS X specific services
- 37.1.
icβ Access to the Mac OS X Internet Config - 37.2.
MacOSβ Access to Mac OS interpreter features - 37.3.
macostoolsβ Convenience routines for file manipulation - 37.4.
findertoolsβ The finderβs Apple Events interface - 37.5.
EasyDialogsβ Basic Macintosh dialogs - 37.6.
FrameWorkβ Interactive application framework - 37.7.
autoGILβ Global Interpreter Lock handling in event loops - 37.8. Mac OS Toolbox Modules
- 37.9.
ColorPickerβ Color selection dialog
- 37.1.
- 38. MacPython OSA Modules
- 39. SGI IRIX Specific Services
- 39.1.
alβ Audio functions on the SGI - 39.2.
ALβ Constants used with thealmodule - 39.3.
cdβ CD-ROM access on SGI systems - 39.4.
flβ FORMS library for graphical user interfaces - 39.5.
FLβ Constants used with theflmodule - 39.6.
flpβ Functions for loading stored FORMS designs - 39.7.
fmβ Font Manager interface - 39.8.
glβ Graphics Library interface - 39.9.
DEVICEβ Constants used with theglmodule - 39.10.
GLβ Constants used with theglmodule - 39.11.
imgfileβ Support for SGI imglib files - 39.12.
jpegβ Read and write JPEG files
- 39.1.
- 40. SunOS Specific Services
- 41. Undocumented Modules
