Skip to main content
MahiDev — Learn. Build. Become AI-ready.

Lesson 07

Python Packages Overview — Function, Module & Package

Understand the reuse ladder from functions to modules to packages — and when to use each level in real Python projects.

Intermediate35 min
Python packages overview hero Module 14 Lesson 7 from functions to packages

From functions to packages: Understand how Python organizes reusable code — Function → Module → Package.

Use the playground and quiz to climb the reuse ladder.

What you will learn

  • Differentiate function, module, and package
  • Understand the reuse ladder
  • See how packages organize multiple modules
  • Know when to use each level in real projects

The reuse ladder

A package solves a bigger problem than a module, and a module solves a bigger problem than a function.

Function module package reuse ladder one file same folder across projects

Summary table

Level What is it? Reuse scope
Function A reusable block of code Same file
Module One .py file Same folder
Package Folder containing modules Across projects

Level 1: Function

A function is useful when everything lives in one Python file.

python
def sumop(a, b):
    return a + b

print(sumop(10, 20))

Best for: small programs and reusable logic within a single script.

You cannot automatically use sumop from another .py file unless you copy it or move it into a module.


Level 2: Module

A module is simply a Python file.

Module import same folder main.py arithops.py project folder

arithops.py

python
def sumop(a, b):
    return a + b

def mulop(a, b):
    return a * b

main.py

python
import arithops

print(arithops.sumop(10, 20))
print(arithops.mulop(4, 5))

The important rule: both files are in the same folder. Move main.py to another directory and the import breaks.


Level 3: Package

A package is a folder that contains multiple modules.

bankkit package folder init bankinfo arithops greetmod import syntax

Package structure

text
bankkit/
│
├── __init__.py
├── bankinfo.py
├── arithops.py
└── greetmod.py

Once Python knows where bankkit/ lives, any project can use:

python
import bankkit.bankinfo

print(bankkit.bankinfo.BNAME)

The package name becomes the top-level namespace — that is the jump from "same folder only" to cross-project reuse.


How they compare

Feature Function Module Package
Physical unit Function .py file Folder
Contains Code Variables, functions, classes Multiple modules
Import needed No Yes Yes
Reuse One file Same project folder Multiple projects

Real-world example

Imagine you are building a banking application.

bankkit real world bankinfo transactions interest module split
Module Responsibility
bankinfo.py Customer and bank details
transactions.py Deposit and withdraw
interest.py Interest calculations

The bankkit package groups related modules into one reusable library — the same pattern professional teams use for APIs, data pipelines, and ML toolkits.


Interview memory card

Question Answer
What is a function? Reusable code inside one file
What is a module? A Python .py file
What is a package? A folder containing multiple modules
Why use packages? Organize and reuse code across projects

Key takeaways

  • Function = reuse within one file
  • Module = reuse across files in the same folder
  • Package = organize multiple modules into a reusable library
  • Packages are the foundation of professional Python project structure
  • Next: Creating Python Packages — build bankkit/ step by step

Loading playground…

Check your understanding

Packages overview quiz

A Python package is best defined as:

1 / 10