Open In App
Related Articles

What is the difference between Python’s Module, Package and Library?

Like Article
Save Article
Report issue

In this article, we will see the difference between Python’s Module, Package, and Library. We will also see some examples of each to things more clear.

What is Module in Python?

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. 

Examples of modules:

  1. Datetime
  2. Regex
  3. Random etc.

Example: Save the code in a file called 


def myModule(name):
    print("This is My Module : "+ name)


Import module named demo_module and call the myModule function inside it. 


import demo_module



This is My Module : Math

What is Package in Python?

The package is a simple directory having collections of modules. This directory contains Python modules and also having file by which the interpreter interprets it as a Package. The package is simply a namespace. The package also contains sub-packages inside it. 

Examples of Packages: 

  1. Numpy 
  2. Pandas


| (Constructor)
| (Module)
| (Module)
| (Module)

What is Library in Python

The library is having a collection of related functionality of codes that allows you to perform many tasks without writing your code. It is a reusable chunk of code that we can use by importing it into our program, we can just use it by importing that library and calling the method of that library with a period(.). However, it is often assumed that while a package is a collection of modules, a library is a collection of packages.

Examples of Libraries: 

  1. Matplotlib
  2. Pytorch
  3. Pygame
  4. Seaborn etc.


Importing pandas library and call read_csv method using an alias of pandas i.e. pd. 


import pandas as pd
df = pd.read_csv("file_name.csv")


Last Updated : 30 Sep, 2022
Like Article
Save Article
Share your thoughts in the comments
Similar Reads