Python
absolute_import
from __future__
Python imports
future module

What does from __future__ import absolute_import actually do?

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

Introduction

from __future__ import absolute_import was a Python 2 feature that changed how plain import statements were resolved. Its purpose was to make Python 2 behave more like Python 3 by treating ordinary imports as absolute by default instead of sometimes preferring modules from the current package. This mattered because local module names could accidentally shadow standard library or third-party modules.

The Problem It Solved in Python 2

In older Python 2 code, an import such as:

python
import string

could unexpectedly import a local module named string.py from the current package instead of the standard library string module. That made package behavior fragile and confusing.

With absolute_import, Python 2 changes the default so that plain imports resolve as absolute imports unless you explicitly ask for relative import syntax.

Example Without absolute_import

Imagine this package layout:

text
1project/
2    main.py
3    pkg/
4        __init__.py
5        string.py
6        worker.py

Inside worker.py, a plain import string in Python 2 could import pkg/string.py rather than the standard library module. That is often not what the author intended.

Example With absolute_import

In Python 2:

python
from __future__ import absolute_import

import string

Now import string means the top-level standard library module unless you explicitly request relative import behavior.

If you actually want the sibling module, use explicit relative syntax:

python
from . import string

That makes intent visible and removes ambiguity.

Why This Became the Python 3 Default

Python 3 adopted absolute-import behavior by default because it is easier to reason about and more robust in larger projects. So the future import was mainly a migration tool for Python 2 code bases preparing for Python 3 compatibility.

In modern Python 3 code, you do not need this future import because the behavior is already standard.

Clear Example of Intent

Consider a package with a local helper module named email.py. Without absolute-import behavior, importing email might accidentally resolve to the local file instead of the standard library package.

The safer pattern is:

python
from . import email_helpers
import email

One line is explicitly local. The other is explicitly top-level by Python 3 rules.

How It Affected Package Design

This feature encouraged cleaner package structure:

  • fewer ambiguous module names
  • clearer use of explicit relative imports
  • easier migration from Python 2 to Python 3

It also pushed developers to think more carefully about whether an import was meant to reference a sibling module or a top-level dependency.

What It Does Not Do

It does not:

  • change how explicit relative imports work
  • automatically fix circular imports
  • matter in normal Python 3 code
  • affect runtime behavior outside import resolution

Its scope is narrow and specific to import semantics.

Python 3 Context

In Python 3, this line is usually unnecessary noise:

python
from __future__ import absolute_import

It does not hurt much, but it adds no value in most modern code. If you see it, the code may have historical Python 2 compatibility roots.

Practical Guidance Today

For current projects:

  • use Python 3 import semantics
  • use explicit relative imports only when importing within the same package
  • avoid local module names that shadow popular standard library modules

These habits make import behavior predictable without any future import.

Common Pitfalls

  • Thinking absolute_import is still required in Python 3 projects.
  • Confusing absolute import behavior with package search path configuration.
  • Assuming it fixes circular import problems.
  • Keeping ambiguous local module names such as string.py or email.py.
  • Mixing implicit and explicit relative import styles without clear intent.

Summary

  • 'from __future__ import absolute_import was mainly a Python 2 compatibility feature.'
  • It made plain imports resolve as absolute by default, like Python 3.
  • Its main value was preventing accidental import of sibling modules with conflicting names.
  • In Python 3, the behavior is already the default, so the import is usually unnecessary.
  • The long-term lesson is to keep imports explicit and package structure unambiguous.

Related reading
Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

All Rights Reserved.