Interpreter Customization Hooks

sitecustomize

Optional site-wide startup module that an administrator or distribution can provide. The site module attempts to import it after processing site paths. A missing hook is normally ignored; an existing hook may execute arbitrary Python during startup. The example is a proposed synthetic source-inspection fixture, not an actual hook import.

Formal Syntax & Structure

python syntaxpython
import sitecustomize

Return Value

module

Optional installation-defined module; importing may execute its contents.

Working Example

Example Snippetpython
from pathlib import Pathfrom tempfile import TemporaryDirectoryimport astwith TemporaryDirectory() as folder:    path = Path(folder) / "sitecustomize.py"    path.write_text("label = \"demo\"\n", encoding="utf-8")    print(ast.parse(path.read_text(encoding="utf-8")).body[0].targets[0].id)
Python Reference