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.
#1 Best Overall
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.
Rank #2
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:
Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchPC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11import sound.effects.echoimports the submodule using its full dotted name.from sound.effects import echomakes the submodule available asecho.from sound.effects.echo import echofilterimports 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.
Best Value
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.
Quick Recap
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.




