Python pstats: read and display profiler statistics
Answer: The pstats module provides tools for reading, manipulating, and displaying profiling statistics.
The Stats class
Those statistics are generated by Python profilers.
The Stats class is the primary interface for working with profile data.
You can load statistics from a file and print a basic report.
It can read statistics directly from a Profile object as well.
Methods on Stats can sort and filter the data.
Cleaning and saving
The strip dirs method removes directory paths from filenames.
That makes the output more compact.
dump stats saves the current statistics to a file.
The file is created if it does not already exist.
The module reads output from both profiling.tracing and profiling.sampling.
See also
Claims
- id: C1 claim: The module provides tools for reading and displaying profiling statistics. source: S1 evidence: "provides tools for reading, manipulating, and displaying profiling statistics"
- id: C2 claim: Stats is the primary interface for working with profile data. source: S1 evidence: "The Stats class is the primary interface for working with profile"
- id: C3 claim: dump stats saves the current statistics to a file. source: S1 evidence: "Save the current statistics to a file"
- id: C4 claim: The strip dirs method removes directory paths from filenames. source: S2 evidence: "method removes directory paths from filenames"
Sources
- [S1] pstats — Statistics for profilers. Python Software Foundation. https://docs.python.org/3/library/pstats.html . License: PSF License Version 2. Accessed 2026-11-24.
- [S2] pstats documentation (source). CPython. https://raw.githubusercontent.com/python/cpython/main/Doc/library/pstats.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, pstats — Statistics for profilers; CPython, pstats 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, pstats — Statistics for profilers; CPython, pstats documentation (source). PSF-2.0 (https://docs.python.org/3/license.html). Copyright Python Software Foundation.
Cite this
iinventedlight. 2026. "Python pstats: read and display profiler statistics." iinventedlight Library, iil:note:117xx83t, version of 2026-11-24. https://iinventedlight.com/library/notes/python-pstats/. License: CC-BY-4.0.
@misc{iil_note_117xx83t,
author = {{iinventedlight}},
title = {{Python pstats: read and display profiler statistics}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-24},
url = {https://iinventedlight.com/library/notes/python-pstats/},
note = {Permanent ID iil:note:117xx83t. 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-pstats.schema.json (schema; CC-BY-4.0)
- python-pstats.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-pstats.md.