0Pricing
Python Academy · Lesson

Packages and __init__.py

Organize modules into packages with proper directory structure.

What Is a Package?

A package is a directory that contains an __init__.py file and one or more modules. Python treats any such directory as a package you can import from.

mypackage/
    __init__.py
    utils.py
    math_helpers.py

The __init__.py File

__init__.py runs when the package is imported. It can be empty or expose selected names to callers.

# mypackage/__init__.py
from .utils import helper
from .math_helpers import add

All lessons in this course

  1. Creating and Importing Modules
  2. The Python Standard Library
  3. Packages and __init__.py
  4. Installing Packages with pip
← Back to Python Academy