pprint wraps nested collections according to the available width. pformat() returns a string, which helps compare a representation in tests or include it in a local tool.
Practical example
from pprint import pformat
event = {"user": {"id": 42, "roles": ["editor", "reviewer"]}, "active": True}
rendered = pformat(event, width=50, sort_dicts=True)
print(rendered)
Control the representation
Tune width, depth, and sort_dicts for the purpose. Custom objects still control their repr, so an expensive or unsafe representation remains a problem.
Do not dump production data
Readable output does not replace structured logging events. Remove passwords, tokens, and personal data before printing or recording structures, and limit depth and volume.
Keep learning
Continue with Python Debugging: Complete Guide to pdb and breakpoint and Python Logging: Complete Guide to Efficient Logging. A official Python documentation, accessed July 22, 2026, documents the API and behavior across versions.