Python – Module and Package In Python

Hi again! In previous tutorials I described How to Setup Visual Studio Code to debug Python and also PYTHONPATH. In this tutorial I will talk about Modules and Packages. We all know that, one cannot put all his/her python files in one big directory. It will be impractical in terms of book keeping ass well as will make searching a lot difficult. Also, there will not be any logical segregation of functionalities, classes etc. So, we all need to divide our code base into logical chunks. This gives rise to Multi-directory project.


Before we get to the project level let’s briefly understand the meanings of Modules and Package. Module is practically any python file. It can contain class definitions, functions, some data or a runnable code. So in short any python file can be called a Module. A Module and/or a method in a module can be directly referenced in another Module.

Example of Module


While Package documentation according to official is way of structuring Python’s module namespace by using “dotted module names”. In simple words packages are bundles of Python modules which can be called by their directory names. A Package MUST have module. Just like a directory can have a sub-directory packages can have sub-packages A typical Package is structured as following..

ParentName/                            <Parent Package>
                  <Initialize Package> 
                   <Modules within the Package>
                   <Modules within the Package>
                   <Modules within the Package>
           Sub-PackageName/               <Sub-Package> 
                     <Initialize Sub-package>
                   <Modules within Sub-Package>

Example of Package

Please do let me know if you have any questions. You can post them in the comments section.

2 Replies to “Python – Module and Package In Python”

Leave a Reply