wildcard import

A wildcard import uses the from module import * syntax to import all public names in a module’s namespace into your current namespace at once.

If __all__ isn’t defined in the target module, then Python imports every name in the module’s namespace that doesn’t start with an underscore (_). Otherwise, it imports the names listed in __all__. If you intentionally want a curated public API for a module or package, define __all__ to control exactly what a wildcard import will import.

Wildcard imports are convenient for quick interactive use, but they’re discouraged in real code because they obscure where names come from, can silently overwrite existing names, and make static analysis and tooling less effective.

Example

Here’s a quick example of a wildcard import:

Python
>>> from math import *
>>> sqrt(25)
5

Loading unneeded names is a direct consequence of this kind of import. Here, you only use the sqrt() function but all the functions in math are also imported.

Name collisions are another risk:

Python
>>> pi = 3

>>> from math import *
>>> pi  # Overwrote your binding
3.141592653589793

Controlling what a star import exposes with the __all__ attribute:

Python calculations.py
__all__ = ["add", "sub"]  # Exports add() and sub()

def add(a, b):
    return a + b

def sub(a, b):
    return a - b

def _helper():
    return "hidden"

Tutorial

Python's __all__: Packages, Modules, and Wildcard Imports

In this tutorial, you'll learn about wildcard imports and the __all__ variable in Python. With __all__, you can prepare your packages and modules for wildcard imports, which are a quick way to import everything.

intermediate python

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


By Leodanis Pozo Ramos • Updated Jan. 9, 2026