← All notes

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

Sources

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

Permanent ID: iil:note:117xx83t

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.},
}

Markdown

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.

All artifact files (JSON index)

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.