packages and sub-packages in Python

Python Packages are formed of various python modules and sub-packages. As per regular packages in Python, packages are directories containing .py files and supplemented by __init__.py. The namespace packages in Python are formed by portions from various sources including multiple directories and network locations.

Physical Design Updated 18 Sep 2019 1 min read

Overview

  • Any Python library of significant complexity and a simple design tends to grow into multiple .py files.
  • While each .py file corresponds to a Python module, multiple python modules are grouped as Python packages and sub-packages.
  • A package can have several sub-packages and modules inside.
  • Roughly packages are directories and modules are files. This simple organization of packages is called regular packages in Python.
  • From Python3.3, the packages can be formed of portions from many directories and network locations. They are called namespace packages. Also, only one or few files of a directory can contribute to a Python namespace package.
  • Namespace packages do not have __init__.py and they also do not rely on the __path__ attribute.