DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PC×
Skip to content
World desk3 min

Difference Between a Module, Package, and Library in Python

A Python module is an importable code unit; a package is a module that can contain other modules; and a library is a broader collection of reusable functionality.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

In Python, a module is an importable unit of code, a package is a module that can contain other modules, and a library is a broader collection of reusable functionality. These terms describe different scopes, not three mutually exclusive kinds of thing: every package is a module, and a library can be made up of packages and modules.

Module vs. package vs. library: the difference

Term What it means How it relates to the others
Module An importable organizational unit of Python code with its own namespace. A .py file is the common introductory example. Can stand alone or belong to a package.
Package A module that can organize submodules or subpackages. Technically, it has a __path__ attribute. A package is a special kind of module.
Library A collection of reusable functionality. May be composed of modules, packages, and extension modules.
Standard library Python’s bundled collection of packages, modules, and extension modules. Distributed with Python; its exact membership can vary by platform and other criteria.

Python’s tutorial introduces a module as “a file containing Python definitions and statements.” That is a useful starting point, but not a complete definition: modules need not all originate as ordinary files. The glossary describes a module more generally as an organizational unit of code with a namespace that is loaded through importing. Python tutorial: Modules · Python glossary: module

What is a Python module?

A module is one importable unit. It gives its contents a namespace, so code can refer to the definitions it provides. For example, when a program imports a module, it can use the module’s name to access its functions or other definitions.

Thinking “one module equals one .py file” works for many everyday projects, but it is an approximation rather than the rule for every importable module. Python’s import system can load code from other sources, too.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What is a Python package?

A package organizes importable units in a hierarchy. The Python glossary defines it technically as a module with a __path__ attribute; the import-system reference makes the relationship explicit: all packages are modules, but not all modules are packages. Python glossary: package · Python import system: packages

In a common filesystem-based layout, a package looks like a directory containing Python code. For ordinary packages, the tutorial describes __init__.py as the marker that tells Python to treat a directory as a package. Namespace packages are an exception: they can have no __init__.py, and may have no single physical directory representing the package. They can also let separately installable packages share a common parent name.

Is a package a module?

Yes. A package is a kind of module with the ability to contain other importable units. The reverse is not true: a module can be a standalone unit without being a package.

How dotted imports show the hierarchy

The Python tutorial uses a sound-processing example. In sound.effects.echo, sound and sound.effects are packages, while echo is a submodule inside sound.effects. The import form affects which name is directly available in your code:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • import sound.effects.echo imports the submodule using its full dotted name.
  • from sound.effects import echo makes the submodule available as echo.
  • from sound.effects.echo import echofilter imports the named function from that submodule.

This example describes the import-name hierarchy; it does not mean that every package must map neatly to one directory on disk. Python tutorial: Packages

What does “Python library” mean?

“Library” describes a collection of functionality, rather than a particular file type or import syntax. A library may be distributed as a package, but the terms answer different questions: a module or package describes an import-system unit and its place in a hierarchy; a library describes the broader reusable functionality someone is using.

Context matters when someone says “Python library.” They may mean reusable Python code in general, or the Python standard library specifically. Python’s documentation defines the standard library as the packages, modules, and extension modules distributed as part of the official interpreter package. Its membership can vary with platform and other criteria. The standard-library reference distinguishes it from components available through the Python Package Index. Python standard library reference

Is the Python standard library one package?

No. The standard library is the broader bundled collection, not a single package. It contains many packages and modules distributed with Python.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

A practical way to remember the terms

  • Module: one importable code unit.
  • Package: a module that can contain other importable units.
  • Library: a reusable collection that may include modules and packages.

The file-and-folder analogy can help you picture a typical project—modules often resemble files and packages often resemble directories—but treat it as a guide, not a definition. Python’s import system allows package structures that do not correspond to one simple filesystem layout.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.