liveBook · Manning

Standard library

As explained in Python Workout: 50 ten-minute exercises

A standard library is a collection of reusable modules, types, functions, APIs, and other facilities distributed with a programming language implementation or platform.

The Python standard library is the built-in collection of modules and packages that supplies commonly needed functionality. Importing these modules helps programs reuse tested capabilities instead of repeating code. section 8.0 section 8.11

Common ways to work with the standard library include:

  • Import a complete module, such as os. section 8.0
  • Import selected names, such as sep from os. section 8.0
  • Use standard-library types such as Decimal when their specialized behavior fits the problem. section 8.0
  • Look beyond the standard library to PyPI when additional community packages are needed. section 8.0

Importing standard-library functionality

import os from os import sep from decimal import Decimal These forms make a module, a selected name, and a standard-library class available to the program. Choosing between them controls which names enter the local namespace. section 8.0

Table 8.1 What you need to know (view table figure)

Concept

What is it?

Example

To learn more

import

Statement for importing modules

import os

http://mng.bz/xWme

from X import Y

Imports module X, but only defines Y as a global variable

from os import sep

http://mng.bz/xWme

importlib.reload

Re-imports an already loaded module, typically to update definitions during development

importlib.reload(mymod)

http://mng.bz/Z2PO

pip

Command-line program for installing packages from PyPI

pip install packagename

https://pypi.org/

Decimal

Class that accurately handles floating-point numbers

from decimal import Decimal

http://mng.bz/RAX0

Use the reference table to compare import statements, module reloading, PyPI installation, and Decimal. section 8.0

How Python Workout: 50 ten-minute exercises covers it

How deep it goes
Frames imports, modules, namespaces, and packages, but stops short of detailed individual module APIs.
Examples
Uses import os, from os import sep, and from decimal import Decimal as concrete import examples.
What you can do after
Apply it via Python imports to reuse functionality and make programs shorter and more maintainable.
How it connects
Connects modules, packages, namespaces, import statements, and PyPI packages.

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 Python Workout: 50 ten-minute exercises. The section links point to the parts of the book it draws on.