liveBook · Manning

Standard library

As explained in The Quick Python Book, Fourth Edition

A standard library is the collection of libraries and modules distributed with a programming language implementation to provide commonly needed functionality.

Python’s standard library is the collection of built-in types, constants, functions, exceptions, and modules distributed with Python. Its “batteries included” approach supplies common functionality without requiring additional installations. section 1.2.4 section 19.1

Use the standard library for common programming tasks, including:

  • Manipulating strings, bytes, Unicode text, dates, times, collections, and other data types. section 19.1.1
  • Performing mathematical, statistical, decimal, fractional, random, and iterator-based operations. section 19.1.1
  • Working with files, filesystems, operating-system services, databases, email, web pages, and internet protocols. section 1.2.4 section 19.6
  • Developing, debugging, scheduling, formatting, copying, annotating, and coordinating Python programs. section 19.1 section 19.1.1

A web server without extra installation

Import the built-in HTTP server and serve the current directory with two lines: import http.server http.server.test(HandlerClass=http.server.SimpleHTTPRequestHandler) The required networking and HTTP support is already available in Python. section 1.2.4

Table 19.1 String services modules (view table figure)

Module

Description and possible uses

string

Compare with string constants, such as digits or whitespace; format strings (see chapter 6)

re

Search and replace text using regular expressions (see chapter 16)

struct

Interpret bytes as packed binary data and read and write structured data to/from files

difflib

Use helpers for computing deltas, find differences between strings or sequences, and create patches and diff files

textwrap

Wrap and fill text and format text by breaking lines or adding spaces

Browse representative string-service modules such as re, struct, difflib, and textwrap, with their typical uses. section 19.1.1

Check the standard library before searching for external packages. When required functionality is absent, use external-module tooling such as pip and isolate project dependencies with venv. section 19.1 section 19.6

How The Quick Python Book, Fourth Edition covers it

How deep it goes
Surveys built-in components and major module categories, but defers detailed API study to the library reference.
Examples
Uses a two-line HTTP server and module tables covering string services, data types, and numeric operations.
What it assumes
Assumes general Python familiarity while treating the standard library’s scope and common module categories at a high level.
What you can do after
Apply it by selecting built-in modules before installing external packages, then manage unavoidable dependencies with pip and venv.
How it connects
Connects built-in types and functions with modules, external libraries, pip, PyPI, and virtual environments.

Also explained in

Compare how 7 books explain standard library →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of The Quick Python Book, Fourth Edition. The section links point to the parts of the book it draws on.