Runtime Data Attributes
module.__package__
Legacy package context for relative imports. Prefer __spec__.parent; Python 3.13 deprecates reliance on this field by the import system. Bare modules may have None.
Formal Syntax & Structure
python syntaxpython
module.__package__Return Value
str | None
Value exposed by this attribute; availability and mutability depend on the owner as described.
Working Example
Example Snippetpython
from types import ModuleTypefrom importlib.machinery import ModuleSpecfrom importlib.util import module_from_specm = module_from_spec(ModuleSpec('demo',None,is_package=True))print((m.__package__,m.__spec__.parent))