Python site: site-specific configuration hook
Answer: The site module is imported automatically during interpreter startup.
What it changes
Import of this module usually appends site-specific paths to the module search path.
It also adds callables, including help, to the built-in namespace.
The interpreter S option blocks that automatic import.
Call main to trigger the usual site-specific additions after a suppressed start.
How paths are built
Heads come from sys prefix and sys exec prefix, and empty heads are skipped.
Name pth files contain additional items, one per line, to be appended to sys path.
It builds up to four directories by pairing each head with a tail part.
The colon and callable portion of a start-file entry point are mandatory.
See also
Claims
- id: C1 claim: The site module is imported automatically during interpreter startup. source: S1 evidence: "This module is automatically imported during initialization"
- id: C2 claim: The interpreter S option can suppress that automatic import. source: S1 evidence: "import can be suppressed using the interpreter"
- id: C3 claim: It builds directories by pairing each head with a tail part. source: S1 evidence: "constructing up to four directories from a head"
- id: C4 claim: The colon and callable portion of a start-file entry point are mandatory. source: S2 evidence: "The colon and callable portion are mandatory"
Sources
- [S1] site — Site-specific configuration hook. Python Software Foundation. https://docs.python.org/3/library/site.html . License: PSF License Version 2. Accessed 2026-11-24.
- [S2] site documentation (source). CPython. https://raw.githubusercontent.com/python/cpython/main/Doc/library/site.rst . License: PSF License Version 2. Accessed 2026-11-24.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Python Software Foundation, site — Site-specific configuration hook; CPython, site documentation (source). PSF-2.0 (https://docs.python.org/3/license.html). Copyright Python Software Foundation. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Python Software Foundation, site — Site-specific configuration hook; CPython, site documentation (source). PSF-2.0 (https://docs.python.org/3/license.html). Copyright Python Software Foundation.
Cite this
iinventedlight. 2026. "Python site: site-specific configuration hook." iinventedlight Library, iil:note:yxxnn3nz, version of 2026-11-24. https://iinventedlight.com/library/notes/python-site/. License: CC-BY-4.0.
@misc{iil_note_yxxnn3nz,
author = {{iinventedlight}},
title = {{Python site: site-specific configuration hook}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-24},
url = {https://iinventedlight.com/library/notes/python-site/},
note = {Permanent ID iil:note:yxxnn3nz. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
Extra files beside this note
These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.
- python-site.schema.json (schema; CC-BY-4.0)
- python-site.table.json (table; CC-BY-4.0)
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/python-site.md.