# Python Modules and Packages - An Introduction

DevFeed: [Python Modules and Packages - An Introduction](<https://devfeed.tech/articles/python-modules-and-packages-an-introduction-99151.md>)

Original publisher: [Read original article](<https://realpython.com/python-modules-packages/>)

Author: John Sturtz

Published: 2026-10-25T14:00:00Z

Content type: article

Language: en

Sources: [Real Python](<https://devfeed.tech/sources/real-python.md>)

Topics: [modules](<https://devfeed.tech/topics/modules.md>), [Python](<https://devfeed.tech/topics/python.md>), [import](<https://devfeed.tech/topics/import.md>), [Code Modularity](<https://devfeed.tech/topics/code-modularity.md>)

Tags: [explore](<https://devfeed.tech/tags/explore.md>), [introduction](<https://devfeed.tech/tags/introduction.md>), [modular](<https://devfeed.tech/tags/modular.md>), [modules](<https://devfeed.tech/tags/modules.md>), [packages](<https://devfeed.tech/tags/packages.md>), [programming](<https://devfeed.tech/tags/programming.md>), [python](<https://devfeed.tech/tags/python.md>)

## AI overview

Python modules let you split code into smaller units with separate namespaces; packages organize modules hierarchically using dot notation. A Python module can be a `.py` file, a dynamically loaded C module, or a built-in, and imports search the current directory, `PYTHONPATH`, and installation-specific locations listed in `sys.path`. `import mod` keeps names under the module namespace, while `from mod import name` adds them directly to the caller and can overwrite existing names; `import *` can create collisions, with `__all__` controlling what is imported. Code guarded by `if __name__ == '__main__'` runs when the file is executed as a script, not when imported. Modules load once per interpreter session unless reloaded. Packages can use `__init__.py` for initialization or automatic imports, though it has not been required since Python 3.3; package `__all__` controls star imports, which otherwise import no modules by default. Nested packages support absolute and relative imports.

## Source excerpt

Explore Python modules and packages, the two mechanisms that make modular programming possible, and learn how imports find your code.