„Batteries included“

In Python, a library can consist of several components, including built-in data types and constants that can be used without an import statement, such as Numbers and Lists, as well as some built-in Functions and Exceptions. The largest part of the library is an extensive collection of Modules. If you have Python installed, there are also several libraries available for you to use.

Managing data types

The standard library naturally contains support for the types built into Python. In addition, there are three categories in the standard library that deal with different data types: Modules for strings, datatypes and numbers.

String modules

:

Module

Description

string

compares with constants such as string.digits or string.whitespace

re

searches and replaces text with regular expressions

struct

interprets bytes as packed binary data

difflib

helps to calculate deltas, find differences between strings or sequences and create patches and diff files

textwrap

wraps and fills text, formats text with line breaks or spaces

Modules for data types

Module

Description

datetime, calendar

Time and calendar operations

collections

Container data types

enum

allows the creation of enumeration classes that bind symbolic names to constant values

array

Efficient arrays of numeric values

sched

Event scheduler

queue

Synchronised queue class

copy

Shallow and deep copy operations

pprint

prints Python data structures „pretty“.

typing

supports commenting code with hints about the types of objects, especially function parameters and return values

Modules for numbers

:

Module

Description

numbers

for numeric abstract base classes

math, cmath

for mathematical functions for real and complex numbers

decimal

for decimal fixed-point and floating-point arithmetic

statistics

for functions for calculating mathematical statistics

fractions

for rational numbers

random

for generating pseudo-random numbers and selections and for shuffling sequences

itertools

for functions that create iterators for efficient loops

functools

for higher-order functions and operations on callable objects

operator

for standard operators as functions

Changing files

:

Module

Description

os.path

performs common pathname manipulations

pathlib

manipulates pathnames

fileinput

iterates over multiple input files

filecmp

compares files and directories

tempfile

creates temporary files and directories

glob, fnmatch

use UNIX-like path and file name patterns

linecache

randomly accesses lines of text

shutil

performs higher level file operations

mimetypes

Assignment of file names to MIME types

pickle, shelve

enable Python object serialisation and persistence, see also The pickle module

csv

reads and writes CSV files

json

JSON encoder and decoder

sqlite3

provides a DB-API 2.0 interface for SQLite databases, see also The sqlite module

xml, xml.parsers.expat, xml.dom, xml.sax, xml.etree.ElementTree

reads and writes XML files, see also R:doc:../save-data/xml

html.parser, html.entities

Parsing HTML and XHTML

configparser

reads and writes Windows-like configuration files (.ini)

base64, binhex, binascii, quopri, uu

encodes/decodes files or streams

struct

reads and writes structured data to and from files

zlib, gzip, bz2, zipfile, tarfile

for working with archive files and compressions

See also

Interacting with the operating system

Module

Description

os

Various operating system interfaces

platform

Access to the identification data of the underlying platform

time

Time access and conversions

io

Tools for working with data streams

select

Waiting for I/O completion

optparse

Parser for command line options

curses

Terminal handling for character cell displays

getpass

Portable password entry

ctypes

provides C-compatible data types

threading

high-level threading interface

multiprocessing

Process-based threading interface

subprocess

Management of subprocesses

Use of Internet protocols

Module

descriptiong

socket, ssl

Low-level network interface and SSL wrapper for socket objects

email

Email and MIME processing package

mailbox

Manipulation of mailboxes in various formats

cgi, cgitb

Common Gateway Interface support

wsgiref

WSGI utilities and reference implementation

urllib.request, urllib.parse

Open and parse URLs

ftplib, poplib, imaplib, nntplib, smtplib, telnetlib

Clients for various Internet protocols

socketserver

Framework for network servers

http.server

HTTP server

xmlrpc.client, xmlrpc.server

XML-RPC client and server

Developing and debugging

Module

Description

pydoc

Documentation generator and online help system

doctest

Test examples from Python docstrings

unittest

Framework for unittests, see also Unittest

test.support

Utility functions for tests

trace

traces the execution of Python statements

pdb

Python debugger

logging

logging function for Python

timeit

measures the execution time of small code snippets

profile, cProfile

Python profiler

sys

System-specific parameters and functions

gc

Functions of the Python garbage collector

inspect

inspects objects live

atexit

exit handler

__future__

Future statement definitions

imp

allows access to the import internals

zipimport

imports modules from zip archives

modulefinder

finds modules used by a script