Standard Library Modules

Standard library modules are always available but must be imported to be used in client modules. To access them, use one of these formats:

  • import module, and fetch attribute names (module.name)

  • from module import name, and use module names unqualified (name)

  • from module import *, and use module names unqualified (name)

For instance, to use name argv in the sys module, either use import sys and name sys.argv, or use from sys import argv and name argv.

There are many standard library modules; the following sections are not necessarily exhaustive, and aim to document only commonly used names in commonly used modules. See Python’s Library Reference for a more complete reference to standard library modules.

In all of the following module sections:

  • Listed export names followed by parentheses are functions that must be called; others are simple attributes (i.e., variable names in modules).

  • Module contents document the modules’ state Python 3.0; see Python manuals for information on attributes unique to version 2 or 3.

Get Python Pocket Reference, 4th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.