What __init__.py does in Python packages

By Pradyumna Chippigiri

June 15, 2026


TIL: __init__.py is used to make a folder behave like a package and also helps expose cleaner imports.

Example

Folder structure

project/
└── mypackage/
    ├── __init__.py
    └── math_utils.py

math_utils.py

def add(a, b):
    return a + b

Without __init__.py re-export

Usage:

from mypackage.math_utils import add
 
print(add(2, 3))

Output:

5

Import path is longer because we directly access the module file.

With __init__.py re-export

__init__.py

from .math_utils import add

The . means: current package.

Usage:

from mypackage import add
 
print(add(2, 3))

Output:

5

Now the import is cleaner because __init__.py re-exported add.

Another example

__init__.py

print("Initializing package...")

Usage:

import mypackage

Output:

Initializing package...

This happens because Python executes __init__.py when importing the package.

Mental model

__init__.py = package entrypoint/export file.