liveBook · Manning

Package

As explained in Python Workout, Second Edition

A package is a Python namespace that organizes related modules and subpackages, typically represented by a directory.

A package groups related Python modules in a directory, giving a larger project a single distributable structure. If that directory is on sys.path, its modules can be imported individually or through the package name. section 9.9

A package layout

Place first.py, second.py, and third.py inside mypackage. Code can then import first and use first.x, or import mypackage.first and use mypackage.first.x. section 9.9

How Python Workout, Second Edition covers it

How deep it goes
Defines directory-based packages and demonstrates alternative module import paths without descending into package internals.
Examples
Uses mypackage with first.py, second.py, and third.py, plus a menu.py packaging exercise.
What it assumes
Assumes familiarity with modules and import statements.
What you can do after
Build packages from related modules and import those modules with short or qualified names.
How it connects
Connects packages with modules, import statements, sys.path, the standard library, and PyPI.

Also explained in

Compare how 7 books explain package →

Related concepts

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