• Any Python file is a module, its name being the file's base name without the .py extension.
  • A package is a collection of Python modules: while a module is a single Python file, a package is a directory of Python modules containing an additional __init__.py file, to distinguish a package from a directory that just happens to contain a bunch of Python scripts. Packages can be nested to any depth, provided that the corresponding directories contain their own __init__.py file.

The distinction between module and package seems to hold just at the file system level. When you import a module or a package, the corresponding object created by Python is always of type module. Note, however, when you import a package, only variables/functions/classes in the __init__.py file of that package are directly visible, not sub-packages or modules.


Example

As an example, consider the xml package in the Python standard library: its xml directory contains an __init__.py file and four sub-directories; the sub-directory etree contains an __init__.py file and, among others, an ElementTree.py file.

See what happens when you try to interactively import package/modules:

>>> import xml
>>> type(xml)
<type 'module'>
>>> xml.etree.ElementTree
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'etree'
>>>
>>>
>>> import xml.etree
>>> type(xml.etree)
<type 'module'>
>>> xml.etree.ElementTree
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'ElementTree'
>>>
>>>
>>> import xml.etree.ElementTree
>>> type(xml.etree.ElementTree)
<type 'module'>
>>> xml.etree.ElementTree.parse
<function parse at 0x00B135B0>

NOTE

In Python there also are built-in modules, such as sys, that are written in C, but I don't think you meant to consider those in your question.

Answer from Giulio Piancastelli on Stack Overflow
Top answer
1 of 10
807
  • Any Python file is a module, its name being the file's base name without the .py extension.
  • A package is a collection of Python modules: while a module is a single Python file, a package is a directory of Python modules containing an additional __init__.py file, to distinguish a package from a directory that just happens to contain a bunch of Python scripts. Packages can be nested to any depth, provided that the corresponding directories contain their own __init__.py file.

The distinction between module and package seems to hold just at the file system level. When you import a module or a package, the corresponding object created by Python is always of type module. Note, however, when you import a package, only variables/functions/classes in the __init__.py file of that package are directly visible, not sub-packages or modules.


Example

As an example, consider the xml package in the Python standard library: its xml directory contains an __init__.py file and four sub-directories; the sub-directory etree contains an __init__.py file and, among others, an ElementTree.py file.

See what happens when you try to interactively import package/modules:

>>> import xml
>>> type(xml)
<type 'module'>
>>> xml.etree.ElementTree
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'etree'
>>>
>>>
>>> import xml.etree
>>> type(xml.etree)
<type 'module'>
>>> xml.etree.ElementTree
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'ElementTree'
>>>
>>>
>>> import xml.etree.ElementTree
>>> type(xml.etree.ElementTree)
<type 'module'>
>>> xml.etree.ElementTree.parse
<function parse at 0x00B135B0>

NOTE

In Python there also are built-in modules, such as sys, that are written in C, but I don't think you meant to consider those in your question.

2 of 10
458

A module is a single file (or files) that are imported under one import and used. e.g.

import my_module

A package is a collection of modules in directories that give a package hierarchy.

from my_package.timing.danger.internets import function_of_love

Documentation for modules

Introduction to packages

๐ŸŒ
Learn Python
learnpython.org โ€บ en โ€บ Modules_and_Packages
Modules and Packages - Learn Python - Free Interactive Python Tutorial
For example, when building a ping ... consists of a different file, which may be edited separately. Modules in Python are just Python files with a .py extension....
Discussions

Difference between modules, packages and libraries in Python
One thing worth noting: both module and package have technical meanings in the Python ecosystem while 'library' does not. More on reddit.com
๐ŸŒ r/Python
32
313
June 6, 2022
Difference between modules, packages and libraries in Python
๐ŸŒ r/Python
How are python packages and modules organized?
I think you are confused about the distinction between builtins and the stdlib. Builtins - as listed by __builtins__ - are just the names that are automatically available within the interpreter without importing. And sys.builtin_module_names - as the documentation states - lists "all modules that are compiled into this Python interpreter". This is not at all the same thing as "modules that are in the standard library associated with this Python version". For that, you could potentially use sys.stdlib_module_names, which would be exactly what you want except that it was only introduced in Python 3.10. Do you definitely need to use 3.9? More on reddit.com
๐ŸŒ r/learnpython
4
1
January 17, 2025
Guide to how Python's module system actually works?
I can't figure out what exactly you are doing from your description but for you to be that frustrated and using comments like "Python belongs in the stone age" I can't help but feel you are just doing it wrong. Symlinks?! I'm working on a large project right now that has a large amount of code reuse amongst it's bits. The server and the client share code. The GUI client and the CLI client share code. Other tools share all of this code. It's laid out somewhat like this: PYTHONPATH=*path to my project* Examples imports from each component: Client: from projectname.client.library import Connector, SomethingElse... from projectname.core.session import Session Server: from projectname.server.library import Listen from projectname.core.session import Session core/session.py: from projectname.core.globalvars import globalVarICareAbout from projectname.core.helpers import helperFunctionIPlanToUse (Names changed to protect the innocent) Basically, we have a top level directory (which is superfluous, to be honest) and then each component. If there is code that is only used by clients it will live in the client package. If there is code that is only used in the server it will live in the server package. If there is code that is shared amongst them it will live in the core package. By specifying the PYTHONPATH to be the toplevel of the project, all code imports are very clear. All code imports are done the same way so if a hunk of code has to be moved from the client libraries to the core libraries, it can be done without changing anything except the places that import THAT code. I'm not sure this is addressing your specific concern but I do feel as though you must be doing something wrong right now... More on reddit.com
๐ŸŒ r/Python
24
15
October 10, 2010
People also ask

What are the key features of Python programming?
Simpleness, adaptability, readability, a robust standard library, and strong community support are some of Python's best qualities. It is the best option due to these characteristics for both novice and seasoned developers. Python has a wide range of features, some of which are covered below: Free and Open Source.Easy to code.Easy to Read.Object-Oriented Language.GUI Programming Support.High-Level Language.Large Community Support.Easy to Debug. Free and Open Source. Easy to code. Easy to Read. Object-Oriented Language. GUI Programming Support. High-Level Language. Large Community Support. Easy
๐ŸŒ
upgrad.com
upgrad.com โ€บ home โ€บ tutorials โ€บ software & tech โ€บ module and package in python
Exploring Modules and Packages in Python: A Comprehensive Guide
Can Python be used for web development?
Yes, a lot of people use Python to construct websites. Frameworks like Django and Flask provide a strong foundation for building dynamic and scalable online applications. Python's essential features make it a popular choice for web development. Python is accessible, open-source, and cost-free, to start. But more importantly, it is also very adaptable. Python makes it possible for web designers to use a range of different programming paradigms to create websites.
๐ŸŒ
upgrad.com
upgrad.com โ€บ home โ€บ tutorials โ€บ software & tech โ€บ module and package in python
Exploring Modules and Packages in Python: A Comprehensive Guide
What type of language is python?
Python is a high-level, dynamically-typed, general-purpose programming language known for its readability and versatility.
๐ŸŒ
upgrad.com
upgrad.com โ€บ home โ€บ tutorials โ€บ software & tech โ€บ module and package in python
Exploring Modules and Packages in Python: A Comprehensive Guide
๐ŸŒ
Upgrad
upgrad.com โ€บ home โ€บ tutorials โ€บ software & tech โ€บ module and package in python
Exploring Modules and Packages in Python: A Comprehensive Guide
September 9, 2025 - Both these functionalities are required in Python to structure and organize code. However, they serve different purposes. Where a module is a simple Python file, a package is a collection of multiple modules.
๐ŸŒ
Python documentation
docs.python.org โ€บ 3 โ€บ tutorial โ€บ modules.html
6. Modules โ€” Python 3.14.4 documentation
Packages are a way of structuring ... named B in a package named A. Just like the use of modules saves the authors of different modules from having to worry about each otherโ€™s global variable names, the use of dotted module names saves the authors of multi-module packages like NumPy or Pillow from having to worry about each otherโ€™s module names. Suppose you want to design a collection of modules (a โ€œpackageโ€) for the uniform handling of sound files and sound ...
๐ŸŒ
LearnPython.com
learnpython.com โ€บ blog โ€บ python-modules-packages-libraries-frameworks
Python Modules, Packages, Libraries, and Frameworks | LearnPython.com
July 15, 2021 - Python packages are basically a directory of a collection of modules. Packages allow the hierarchical structure of the module namespace. Just like we organize our files on a hard drive into folders and sub-folders, we can organize our modules ...
Find elsewhere
๐ŸŒ
Medium
medium.com โ€บ @sjalexandre โ€บ python-tutorial-unit-22-a55a7d07f023
Python Tutorial โ€” Modules, Packages and Libraries | Medium
August 13, 2023 - You can create a package by organizing related modules into a directory and including an __init__.py file. ... A library is a collection of modules and packages that provide functionalities for various tasks. Python has a rich set of libraries, including the Python Standard Library, which comes with Python, and external libraries that can be installed.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ what-is-the-difference-between-pythons-module-package-and-library
What is the difference between Python's Module, Package and Library? - GeeksforGeeks
July 15, 2025 - The module is a simple Python file that contains collections of functions and global variables and with having a .py extension file. It is an executable file and to organize all the modules we have the concept called Package in Python.
๐ŸŒ
Real Python
realpython.com โ€บ python-modules-packages
Python Modules and Packages โ€“ An Introduction โ€“ Real Python
March 21, 2024 - In this quiz, you'll test your understanding of Python modules and packages, which are mechanisms that facilitate modular programming. Modular programming involves breaking a large programming task into smaller, more manageable subtasks or modules.
๐ŸŒ
Real Python
realpython.com โ€บ videos โ€บ scripts-modules-packages-and-libraries
Scripts, Modules, Packages, and Libraries (Video) โ€“ Real Python
It often defines members like classes, functions, and variables intended to be used in other files that import it. A package is a collection of related modules that work together to provide certain functionality.
Published ย  May 26, 2020
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ python_modules.asp
Python Modules
Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Bootcamp Python Certificate Python Training ... Consider a module to be the same as a code library.
๐ŸŒ
LabEx
labex.io โ€บ tutorials โ€บ python-modules-and-packages-89
Mastering Python Modules and Packages | LabEx
Modules also make it easy to reuse code across multiple projects. A package is a collection of modules. Packages allow us to group related modules together and access them using a simple dot notation.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-packages
Python Packages - GeeksforGeeks
3 days ago - Module: A single Python file containing reusable code (e.g., math.py). Package: A directory containing modules and a special __init__.py file.
๐ŸŒ
TechVidvan
techvidvan.com โ€บ tutorials โ€บ modules-vs-packages-in-python
Modules vs Packages in Python - TechVidvan
May 8, 2021 - The python modules also store pre-defined functions from the library while the execution of code is going on. ... A package is the form of a collection of tools which helps in the initiation of the code.
๐ŸŒ
Python 101
python101.pythonlibrary.org โ€บ chapter36_creating_modules_and_packages.html
Chapter 36 - Creating Modules and Packages โ€” Python 101 1.0 documentation
Any time you save a new Python script, you have created a new module. You can import your module into other modules. A package is a collection of related modules. The things you import into your scripts from the standard library are modules or packages. In this chapter, we will learn how to ...
๐ŸŒ
Scaler
scaler.com โ€บ topics โ€บ module-and-package-in-python
What is the Difference between Module and Package in Python? - Scaler Topics
September 9, 2022 - A Python Module can be a simple python File (.py extension file), i.e., a combination of numerous Functions and Global variables. A Python Package is a collection of different Python modules with an __init__.py File.
๐ŸŒ
Real Python
realpython.com โ€บ learning-paths โ€บ modules-and-packages
Modules and Packages (Learning Path) โ€“ Real Python
Learning Path โ‹… Skills: Packages, Modules, Import System, pip, PyPI, uv, __init__.py, Namespace Packages ยท In this learning path, youโ€™ll explore how Pythonโ€™s import system works and how to structure your code using modules and packages. Youโ€™ll learn to manage project dependencies with pip and uv, evaluate third-party package quality, and publish your own packages to PyPI.
๐ŸŒ
Python
docs.python.org โ€บ 3 โ€บ library โ€บ index.html
The Python Standard Library โ€” Python 3.14.4 documentation
In addition to the standard library, there is an active collection of hundreds of thousands of components (from individual programs and modules to packages and entire application development frameworks), available from the Python Package Index.
๐ŸŒ
Tutorialspoint
tutorialspoint.com โ€บ python โ€บ python_modules.htm
Python - Modules
Any text file with .py extension and containing Python code is basically a module. It can contain definitions of one or more functions, variables, constants as well as classes. Any Python object from a module can be made available to interpreter session or another Python script by import statement.