relative import

A relative import lets you import modules from the same package or parent packages using leading dots instead of the full package path. Relative imports use the from ... import ... form where one leading dot refers to the current package, two dots to the parent, and so on.

Relative imports only work in modules that are part of a package and are resolved based on the importing module’s package context. In particular, modules intended to be executed as the main script should use absolute imports.

Use relative imports when you want to keep package-internal references short and resilient to refactors. Avoid them in files you execute directly, and keep in mind that you can’t import beyond the top-level package.

Example

Imagine you have the following project layout:

project/
└── pkg/
    ├── __init__.py
    ├── util.py
    ├── api.py
    └── models/
        ├── __init__.py
        ├── helpers.py
        └── user.py

In pkg/models/user.py, you can use relative imports to reach sibling and parent modules:

Python pkg/models/user.py
# From the parent package (pkg)
from .. import util
from ..api import get_client

# From the current package (pkg.models)
from . import helpers
from .helpers import parse_response

Relative imports can’t go beyond the top-level package. Attempting to do so raises an ImportError.

Tutorial

Absolute vs Relative Imports in Python

If you’ve worked on a Python project that has more than one file, chances are you’ve had to use an import statement before. In this tutorial, you’ll not only cover the pros and cons of absolute and relative imports but also learn about the best practices for writing import statements.

intermediate best-practices python

For additional information on related topics, take a look at the following resources:


By Leodanis Pozo Ramos • Updated Jan. 9, 2026