Libraries
There are a tremendous number of libraries that are available for Python, both that come with the standard installation and available from the web. In this chapter, I will try to give you a list of some of the more “generically” helpful ones. Most of this information was obtained from the official Python Docs page.
Thes libraries provide various tools for dealing with string formatting, regular expressions, strings as files, Unicode strings, and more.
string—Common string operations
The string library contains a number of useful constants and classes, as well as some deprecated legacy functions that are also available as methods on strings.
re—Regular expression operations
The re library provides regular expression matching operations similar to those found in the Perl language. Both patterns and strings to be searched can be Unicode strings as well as 8-bit strings.
StringIO—Read and write strings as files
The StringIO library implements a filelike class that reads and writes a string buffer or memory files (2.x only).
Data Types
These libraries provide specialized data types such as dates and times, fixed type arrays, queues, and sets.
datetime—Basic date and time types
Includes objects such as time, date, timezone, and formatted time/date information.
sets—Extends the set capabilities of Python
Provides classes for constructing and manipulating unordered collections.
Numeric and Mathematical Librarys
Provides numeric and math-related function and data types.
numbers—Numeric abstract base cass
Defines a hierarchy of numeric base classes.
decimal—Decimal fixed point and floating point arithmetic
Offers serveral advantages over the normal ‘float’ datatype.
math—Mathematical functions
Provides functions such as floor, ceil, trigonometric functions, and more.
random—Generate pseudo-random numbers
The random library also provides shuffleing, random sampling functions, and more.
File and Directory Access
Provides libraries for dealing with disk files and directories.
os.path—Common pathname manipulations
Implements useful functions on pathnames.
fileinput—iterate over lines from input streams
Provides helper class and functions to quickly write a loop over standard input or a list of files.
Data Persistance
Supports storing Python data in a persistent form on disk.
pickle—Python object serialization
Implements powerful algorithm for serializing and deserializing a Python object structure.
anydbm—Generic access to DBM-style databases
Generic interface to varients of the DBM database. This library has been renamed to dbm in Python 3.x.
Data Compression and Archiving
Supports data compression with zlib, gzip, bzip2 algorithms, and createion of ZIP and tar format archives.
zlib—Compression compatible with gzip
Allows compression and decompression of archives using the zlib library.
gzip—Support for gzip files
Simple interface to compress and decompress files such as the gzip and gunzip programs.
bz2—Compression compatible with bzip2
Provides a comprehensive interface for the bz2 compression library.
zipfile—Work with ZIP archives
Provides tools to create, read, write, append, and list ZIP files.
File Formats
These libraries parse various miscellaneous file formats that aren’t markup languages or related to e-mail.
csv—CSV File Reading and Writing
Implements classes to read and write tabular data is CSV (Comma Seperated Variable) files.
ConfigParser—Configuration file Parser
Implements a basic configuration file parser language, which provides a structure similar to Microsoft Windows INI files. This library has been renamed to configparser in Python 3.x.
Cryptographic Services
This set of library modules implements various algorithms of a cryptographic nature.
hashlib—Secure hashes and message digest algorithm
Implements a common interface to many different secure hash and message algorithms.
md5—MD5 message digest algorithm
Implements an interface to RSA’s MD5 algorithm.
sha—SHA-1 message digest algorithm
Implements an interface to NIST’s Secure Hash Algorithm.
Generic Operating System Services
There are many libraries in this section that provide interfaces to operating system features.
os—Miscellaneous operating system interfaces.
This library provides a portable way of using operating dependent functionality. Provides functions such as chdir, getenv, file open, and file close.
io—Core tools for working with streams
Provides a Python interface to stream handling.
time—Time access and conversions
Provides various time-related functions.
argparse—Parser for commandline options, arguments, and subcommands
Provides an easy method to write command-line interface processing.
curses—Terminal handling for character displays
Provides an interface to the curses library for portable advanced terminal handling. Provides functions such as colored text, positional printing, and screen clearing in a terminal or command window.
logging—Logging library for Python
The logging library provides functions and classes that implement a flexible event logging system. Very useful for debugging.
Optional Operating system Services
Provides interfaces to operating system features that are generally modeled after Unix interfaces.
threading
Provides higher-level threading interfaces.
Multiprocessing—Process-based “threading” interface
Provides support for spawing processing using an API similar to the threading library.
readline—GNU readline interface
Provides a number of functions to facilitate completion and reading/writing history files.
Interprocess Communication and Networking
ssl—TLS/SSL wrapper for socket objects
Provides access to Transport Layer Security (Secure Sockets Layer) encryption for network sockets.
popen2—Subprocesses with accessible I/O streams
Provides routines to spawn processes and connect to the IO pipes under Unix and Windows.
Provides librarys that support handling data formats commonly used on the Internet.
email—An e-mail and MIME handling package
Library for managing e-mail messages.
json—lightweight data interchange format based on a subset of JavaScript
exposes an API familiar to users of marshal and pickle librarys.
uu—Encode and decode uuencoded files
Provides the ability to encode and decode uuencode format files.
Structured Markup Processing Tools
Provides support for working with various forms of structured data markup.
HTMLParser—Simple HTML and XHTML parser
Provides basis for parsing text files formatted in HTML and XHTML. HTMLParser has been renamed to html.parser in Python 3.x.
htmllib—Parser for HTML documents
Provides a class that allows for parsing text files formatted in HTML. Removed in Python 3.
xml.etree.elementtree—ElementTree XML API
Provides a flexable container object that handles XML files.
xml.dom—The Document Object Module API
Provides an easy way to handls DOM XML files.
xml.sax—Support for SAX2 parsers
Provides a number of librarys for SAX.
Internet Protocols and support
Provides libraries that implement Internet protocols and support for related technology.
webbrowser—Convienient Web-browser controller
Provides a high-level interface to allow displaying Web-based documents to users.
cgi—Common Gateway Interface support
Support library for Common Gateway Interface (CGI) scripts.
urllib—Open arbitrary resources by URL
Provides a high-level interface for fetching data across the World Wide Web. Has been split into parts and renamed in Python 3, named urllib.request, urllib.parse, and urllib.error. urllib.urlopen( ) function has been removed in Python 3.x in favor of urllib2.urlopen().
urllib2—extensible library for opening URSs
Provides functions and classes that help opening URLs. Has been split across several modules in Python 3 named urllib.request and urllib.error.
poplib—POP3 protocol client
Provides a class that allows connection to POP3 servers.
Multimedia Services
Implements various algorithms or interfaces that are useful for multimedia applications.
audioop—Manipulate raw audio data
Provides useful routines for sound fragments.
wave—Read and write WAV files
Provides a convenient interface to the WAV sound format.
Internationalization
Provides libraries that are independent of language and locale.
gettext—Multilngual internationalization services
Provides internationalization and localization services with an API.
locale—Internationalization services
Provides access to the POSIX local database and functionality.
Program Frameworks
This set of libraries are frameworks that are oriented toward writing command-line interfaces.
Cmd—Support for line-oriented command interpreters
Provides a simple framework for writing line-oriented command intrepers. These are often useful for test harnesses, administrative tools, and prototypes.
shlex—Simple lexical analysis
The shlex class makes it easy to write lexical analyzers for simple syntaxes resembling that of the Unix shell.
Graphical User Interfaces with Tk
Tk/Tcl has long been an integral part of Python. It provides a robust and platform independent windowing toolkit.
Tkinter—Python interface to Tcl/Tk
The Tkinter library is the standard Python to the Tk GUI toolkit.
ttk—Tk-themed widgets
The ttk library provides access to the Tk-themed widget set.
turtle—Turtle graphics for Tk
Turtle graphics is a popular way for introducing programming to kids. It was part of the original Logo programming language developed in 1966 by Wally Feurzig and Seymour Papert.
Development Tools
pydoc—Documentation generator and online help system
Automatically generates documentation from Python librarys. The documentation can be presented as pages of text in a terminal or command window or saved to HTML files.
2to3—Automated Python 2 to Python 3 code translation
A Python program that reads Python 2.x source code and applies a series of “fixers” to transfer it into a valid Python 3.x code set.
Debugging and Profiling
The libraries in this section helps with Python development. The debugger enables you to step through code, analyze stack frames and set breakpoints, and so on.
pdb—The Python Debugger
This library defines an interactive source code debugger for Python programs. It supports setting breakpoints and single stepping at the source line level.
hotshot—High performance logging profiler
This library provides a nicer interface to the _hotshot C library.
timeit—Measure execution time of small code snippets
This library provides a simple way to time small bits of Python code.
trace—Trace or track Python statement execution
This library allows you to trace program execution, generate annotated statement coverage listings, print caller/callee relationships and list functions executed during a program run.
Python Runtime Services
These libraries provide a wide range of services related to the Python interpreter and its interaction with its environment.
sys—System-specific parameters and functions
This library provides access to variables and functions that interact with the interpreter.
warnings—Warning control
Supports the use of warning messages in situations in which it is useful to alert the user of some condition in a program where that condition normally doesn’t warrant raising an exception and terminating the program.
Libraries in this section allow for writing interfaces similar to Pythons interactive interpreter.
codeop
Provides utilities on which the Python read-eval-print loop can be emulated.
code—Interpreter base classes
Provides facilities to implement read-eval-print loops in Python.
Importing Librarys
These libraries provide new ways to import other Python librarys and hooks for customizing the import process.
zipimport—Import librarys from Zip archives
Adds the ability to import Python librarys and packages from Zip format archives.
runpy—Locating and executing Python librarys
This library is used to locate and run Python librarys without importing them first.
Python Language Services
Libraries that assist in working with the Python language.
Parser—Access Python parse trees
This library provides an interface to Python’s internal parser and byte-code compiler.
tabnanny—Detection of ambiguous indentation.
This library is intended to be called as a script to check whitespace in a source file.
MS Windows Specific Services
These libraries are only available on MS Windows platforms.
msilib—Read and write Microsoft installer files
Supports creation of Microsoft Installer (.msi) files.
winsound—Sound playing interface for Windows
Provides access to the basic sound-playing functions provided by the Windows platforms.
Unix Specific Services
These libraries provide interfaces to features that are unique to Unix operating system.
posix—The most common POSIX system calls
This library provides access to operating system functionality that is standardized by the C Standard and the POSIX standard. Do not import this library directly. Instead, import the os library which provides a portable version of this interface.
This library provides access to the Unix user account and password database.
tty -Terminal control functions
This library defines functions for putting the tty into cbrake and raw modes.
Mac OS X
Thes libraries are only available on the Mac OS X platform. Many of these libraries are not available when Python is executing in 64-bit mode and have been removed in Python 3.x.
MacOs—Access to Mac OS interpreter fetures
This library provides access to MacOS specific functionality in the Python interpreter. Has been removed in Python 3.x.
Easy Dialogs—Basic Macintosh dialogs
Contains simple dialogs for the Macintosh. This library has been removed in Python 3.x.
MacPython OSA Librarys
These libraries support implementation of the Open Scripting Architecture (OSA) for Python.
This library contains the basic functionality for the Python AppleScript client. Removed in Python 3.x.
Aepack—Conversion between Python variables and AppleEvent data containers
This library defines functions for converting Python variables to AppleEvent and back. Removed in Python 3.x.
SGI IRIX Specific Services
Libries providing features unique to SGI’s IRIX operating system versions 4 and 5.
gl—Graphics library interface
Provides access to the Silicon Graphics Graphics library. It is only available on SGI machines and has been removed in Python 3.x.
al—Audio functions on the SGI
Provides access to the audio facilities of the SGI Indy and Indigo workstations. Has been removed in Python 3.x.
SunOS Specific Services
Provides libraries that are specific to SunOS 5 (aka Solaris version 2).
sunaudiodev—Access to Sun audio hardware
Provides access to the Sun audio interface. Has been removed in Python 3.x.