PEP 842: Module Exports
This PEP introduces a formal 'export' statement to Python modules to explicitly define public API surfaces. It provides a native mechanism to control variable visibility and module interface exposure.
Verified State Diff
Impact & Verification Analysis
Python library maintainers, core developers, and software architects.
It improves encapsulation, reduces accidental exposure of internal implementation details, and enables better tooling support for static analysis and tree-shaking.
Full Fact Overview
Currently, Python relies on the 'all' list convention or underscore-prefix naming conventions to signal private versus public module members, which are not strictly enforced by the interpreter. PEP 842 proposes a language-level 'export' statement that allows developers to explicitly declare which names are intended for external consumption. This shift moves Python closer to the module systems found in languages like JavaScript (ESM) or Rust, potentially allowing static analysis tools and IDEs to provide better autocompletion and dependency tracking by strictly defining module boundaries.