Photo by Godfrey Nyangechi / Unsplash

TIL - In Python __all__ Controls What Imports * Exposes

Today I Learned Apr 25, 2026

Defining __all__ in a module explicitly declares its public API. Without it, from module import * imports everything not starting with _. With it, only the listed names are exported.

# utils.py

__all__ = ["format_date", "parse_date"]

def format_date(d): ...
def parse_date(d): ...
def _internal_helper(): ... # not exported

Even if you never use import *, __all__ serves as documentation - it tells readers and IDEs what the public surface area is.

๐Ÿ
Note: __all__ does not block direct imports - from utils import _internal_helper still works.

Tags