The Python Standard Library
Release:3.1Date:April 09, 2012 While The Python Language Referencedescribes the exact syntax andsemantics of the Python language, this library reference manualdescribes the standard library that is distributed with Python. It alsodescribes some of the optional components that are commonly includedin Python distributions.
Python’s standard library is very extensive, offering a wide range offacilities as indicated by the long table of contents listed below. Thelibrary contains built-in modules (written in C) that provide access tosystem functionality such as file I/O that would otherwise beinaccessible to Python programmers, as well as modules written in Pythonthat provide standardized solutions for many problems that occur ineveryday programming. Some of these modules are explicitly designed toencourage and enhance the portability of Python programs by abstractingaway platform-specifics into platform-neutral APIs.
The Python installers for the Windows platform usually includesthe entire standard library and often also include many additionalcomponents. For Unix-like operating systems Python is normally providedas a collection of packages, so it may be necessary to use the packagingtools provided with the operating system to obtain some or all of theoptional components.
In addition to the standard library, there is a growing collection ofseveral thousand components (from individual programs and modules topackages and entire application development frameworks), available fromthe Python Package Index.
1. Introduction
2. Built-in Functions
3. Built-in Constants
3.1. Constants added by the sitemodule
4. Built-in Objects
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, complex
5.5. Iterator Types
5.6. Sequence Types — str, bytes, bytearray, list, tuple, range
5.7. Set Types — set, frozenset
5.8. Mapping Types — dict
5.9. memoryview Types
5.10. Context Manager Types
5.11. Other Built-in Types
5.12. Special Attributes
6. Built-in Exceptions
6.1. Exception hierarchy
7. String Services
7.1. string— Common string operations
7.2. re— Regular expression operations
7.3. struct— Interpret bytes as packed binary data
7.4. difflib— Helpers for computing deltas
7.5. textwrap— Text wrapping and filling
7.6. codecs— Codec registry and base classes
7.7. unicodedata— Unicode Database
7.8. stringprep— Internet String Preparation
8. Data Types
8.1. datetime— Basic date and time types
8.2. calendar— General calendar-related functions
8.3. collections— Container datatypes
8.4. heapq— Heap queue algorithm
8.5. bisect— Array bisection algorithm
8.6. array— Efficient arrays of numeric values
8.7. sched— Event scheduler
8.8. queue— A synchronized queue class
8.9. weakref— Weak references
8.10. types— Names for built-in types
8.11. copy— Shallow and deep copy operations
8.12. pprint— Data pretty printer
8.13. reprlib— Alternate repr()implementation
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
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— Interpreting stat()results
10.4. filecmp— File and Directory Comparisons
10.5. tempfile— Generate temporary files and directories
10.6. glob— Unix style pathname pattern expansion
10.7. fnmatch— Unix filename pattern matching
10.8. linecache— Random access to text lines
10.9. shutil— High-level file operations
10.10. macpath— Mac OS 9 path manipulation functions