Skip to content

Package

In one line

A package is a folder of Python modules with an __init__.py file, letting you import them as a group.

In simple words

A Python package is a folder that contains multiple module files plus a special __init__.py file. The __init__.py tells Python "this folder is a package," and it can hold initialization code or be empty. Packages let you organize related modules into a hierarchy.

For example, a myproject package might contain myproject/database.py, myproject/models.py, and myproject/__init__.py. You import submodules with from myproject.database import connect. The dot notation reflects the folder structure.

Packages are how the Python ecosystem distributes code. When you pip install numpy, you install a package. Packages can contain sub-packages, creating a tree of modules. Modern Python (3.3+) also supports namespace packages without __init__.py, but the classic structure remains common.

Example

python
# myproject/__init__.py (can be empty)
# myproject/database.py
def connect():
    return "Connected"

# myproject/models.py
class User:
    pass

# main.py
from myproject.database import connect
from myproject.models import User

print(connect())  # "Connected"

myproject is a package (a folder with __init__.py). You import its modules with dot notation.

Common confusions

  • Confused with: module

    The difference: A module is a single .py file; a package is a folder of modules with an __init__.py. Packages group related modules; a module is one file of code within or outside a package.

Related terms

Related Resources

Related Lessons

  • Functions

    Packages organize modules of functions

Learn the fundamentals

Deepen your understanding with structured lessons on this topic.

View lessons

Decode error messages

Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.

View errors

← Back to glossary