Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Python · Const

from

from is part of Python’s import statement: it selects names from a module and binds them in the current namespace, optionally under aliases. Leading dots enable package-relative imports.

How it works

The from form imports a named attribute from a module and binds it in the current namespace. A dotted module path and relative leading dots are supported, and as can provide a different local name.

Syntax

from relative_module import identifier [as identifier]
from relative_module import (identifier [as identifier], ...)
from relative_module import *

Parameters

NameTypeDescription
relative_modulemodule pathModule or relative module containing the names to import.
identifieridentifierOne or more attributes or submodules to bind locally.

Returns

The statement binds imported values in the current namespace; it does not have a function return value.

Key points

  • A from import loads or initializes its source module before resolving each requested name.
  • After resolution, the selected value is stored in the importing scope.
  • An alias controls the local name created by the import.
  • Wildcard imports are restricted to module scope.
  • Two leading dots in a relative import refer to the parent package.

Common mistakes

  • Wildcard imports cannot be used inside a class or function; doing so raises SyntaxError.
  • A leading dot makes the import relative to the current package; additional dots move upward through package levels.

Example: Import a name from a module

from pathlib import Path

config_path = Path("config.json")
print(config_path.name)

This imports Path directly from pathlib, so the local name Path refers to that class.

When to use it

Direct name imports

Use a class or function without qualifying every reference with its module name.

Aliased imports

Avoid a local naming conflict or clarify a dependency’s role.

Package-relative imports

Share code between modules within the same package.

Interview questions

QHow does a from import work?

The from form first finds and initializes the module named in the from clause. For each requested identifier, Python checks for an attribute, may try a submodule, and raises ImportError if the name is not found.

Follow-up: What name is bound when as is present? The alias is used; otherwise the imported attribute name is bound locally.

QWhat does from package import name bind?

from package import name binds the selected name in the current namespace, rather than binding only the package name. An as clause changes the local binding name.

Follow-up: How would you import a sibling module? Use a relative form such as from . import sibling within a package.

QWhich forms can a from import statement take?

The grammar permits one or more identifiers, optionally aliased, and also permits parenthesized multiline imports. It additionally permits wildcard imports, but only at module scope.

Follow-up: What does from . import mod mean? It imports mod from the package containing the importing module.

  • import statement
  • relative imports
  • importlib.import_module()
  • __import__()

Source: 7. Simple statements. Checked 2026-10-16.