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
