Python stat: interpret results from os.stat
Answer: The stat module defines constants and functions for interpreting os.stat results.
What the module is for
Those helpers interpret results of os.stat, os.fstat, and os.lstat.
The calls in view are os.stat, os.fstat, and os.lstat, when they exist.
For full system-call detail, consult the documentation for your system.
Since 3.4, a C implementation backs the module.
Tests for file types
S_ISDIR is non-zero when the mode comes from a directory.
S_ISREG is non-zero when the mode comes from a regular file.
S_ISLNK is non-zero when the mode comes from a symbolic link.
S_ISFIFO is non-zero when the mode comes from a named pipe.
S_ISSOCK is non-zero when the mode comes from a socket.
See also
Claims
- id: C1 claim: The module interprets results from os.stat and related calls. source: S1 evidence: "constants and functions for interpreting the results of os.stat()"
- id: C2 claim: Since 3.4 the module is backed by a C implementation. source: S1 evidence: "backed by a C implementation"
- id: C3 claim: S_ISDIR is true when the mode comes from a directory. source: S2 evidence: "if the mode is from a directory"
- id: C4 claim: S_ISREG is true when the mode comes from a regular file. source: S2 evidence: "if the mode is from a regular file"
Sources
- [S1] stat — Interpreting stat() results. Python Software Foundation. https://docs.python.org/3/library/stat.html . License: PSF License Version 2. Accessed 2026-11-23.
- [S2] stat documentation (source). CPython. https://raw.githubusercontent.com/python/cpython/main/Doc/library/stat.rst . License: PSF License Version 2. Accessed 2026-11-23.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Python Software Foundation, stat — Interpreting stat() results; CPython, stat 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, stat — Interpreting stat() results; CPython, stat documentation (source). PSF-2.0 (https://docs.python.org/3/license.html). Copyright Python Software Foundation.
Cite this
iinventedlight. 2026. "Python stat: interpret results from os.stat." iinventedlight Library, iil:note:46ac7qb4, version of 2026-11-23. https://iinventedlight.com/library/notes/python-stat/. License: CC-BY-4.0.
@misc{iil_note_46ac7qb4,
author = {{iinventedlight}},
title = {{Python stat: interpret results from os.stat}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-23},
url = {https://iinventedlight.com/library/notes/python-stat/},
note = {Permanent ID iil:note:46ac7qb4. 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-stat.schema.json (schema; CC-BY-4.0)
- python-stat.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-stat.md.