🌐
Python
docs.python.org › 3 › library › pprint.html
pprint — Data pretty printer
The pprint module provides a capability to “pretty-print” arbitrary Python data structures in a form which can be used as input to the interpreter. If the formatted structures include objects which are not fundamental Python types, the representation may not be loadable.
🌐
Code Beautify
codebeautify.org › python-formatter-beautifier
Python Formatter and Beautifier
Best Python Formatter will help to format, beautify, minify, compact Python code, string, text. Format, Save, Share
Discussions

Why Pretty Print?
It is a bit convoluted for something that you'd normally only use during software development, and you can't really give a simple user-case of the form that you'd normally see in a beginner's book. It's useful when you're debugging, and need to look at a huge data structure, a large complicated list or json file, or whatever, and just printing it normally gives an impenetrable wall of text. More on reddit.com
🌐 r/learnpython
4
1
October 7, 2020
How can I make my class pretty printable in Python? - Stack Overflow
Python has a pretty printer (pprint(...)). I would like to make my classes pretty printable. Will pretty print print my instances in a better way, if I provide a certain interface? The Python More on stackoverflow.com
🌐 stackoverflow.com
python - How to pretty print nested dictionaries? - Stack Overflow
Using yaml is very interesting ... back in python. 2014-10-06T04:49:00.007Z+00:00 ... yaml doesn't like Numpy's version of scalar types... I wasn't surprised that is doesn't support numpy arrays, but I would have expected the same output for a float and a numpy.float64 2017-03-02T17:12:07.917Z+00:00 ... is it possible to get the string representation of the pretty printed ... More on stackoverflow.com
🌐 stackoverflow.com
How to print a list in Python "nicely" - Stack Overflow
In PHP, I can do this: echo ' ' print_r($array); echo ' ' In Python, I currently just do this: print the_list However, this will cause a big jumble of data. Is there any way to More on stackoverflow.com
🌐 stackoverflow.com
People also ask

What is the advantage of pretty printing a Python dictionary?
Pretty printing enhances the readability of your dictionary, especially when it is large and complex. It ensures the output is more human-friendly and easier to comprehend at a glance.
🌐
docs.kanaries.net
docs.kanaries.net › topics › Python › pretty-print-dictionary-python
How to Use Pretty Print for Python Dictionaries – Kanaries
What is the pformat function in Python's pprint module?
The pformat function pretty prints your Python dictionary and returns it as a string. This is useful when you want a pretty-printed representation for further processing and not just for printing to the console.
🌐
docs.kanaries.net
docs.kanaries.net › topics › Python › pretty-print-dictionary-python
How to Use Pretty Print for Python Dictionaries – Kanaries
How to control the indentation in a pretty printed dictionary?
You can control the indentation using the indent parameter in the pprint function. The value provided to indent will be the number of spaces used for indentation for each level.
🌐
docs.kanaries.net
docs.kanaries.net › topics › Python › pretty-print-dictionary-python
How to Use Pretty Print for Python Dictionaries – Kanaries
🌐
Real Python
realpython.com › python-pretty-print
Prettify Your Data Structures With Pretty Print in Python – Real Python
October 4, 2022 - The pprint module, Python's data pretty printer, is a useful part of the standard library. You can work with it for debugging data structures and increasing the readability of your output.
🌐
Rich
rich.readthedocs.io › en › latest › pretty.html
Pretty Printing — Rich 14.1.0 documentation
Run the following command to see an example of pretty printed output: python -m rich.pretty · Note how the output will change to fit within the terminal width. The pprint() method offers a few more arguments you can use to tweak how objects are pretty printed.
🌐
Python
peps.python.org › pep-0813
PEP 813 – The Pretty Print Protocol | peps.python.org
1 month ago - This PEP describes the “pretty print protocol”, a collection of changes proposed to make pretty printing more customizable and convenient.
🌐
seenode blog
seenode.com › blog › how-to-use-python-pretty-print-pprint
How to Use Python Pretty Print (pprint) for Cleaner Python Output | seenode blog
May 19, 2025 - It refers to “Pretty Print,” the native Python library that allows developers to customize their output experience with its different parameters and flags for a single class print (). This class effectively uses six parameters.
🌐
GeeksforGeeks
geeksforgeeks.org › python › pprint-data-pretty-printer-python
pprint : Data pretty printer in Python - GeeksforGeeks
DSA Python · Data Science · NumPy ... (pretty print) is a built-in utility that formats complex data structures like dictionaries, lists, or JSON in a readable way with proper indentation and line breaks....
Published   January 9, 2026
Find elsewhere
🌐
Python Module of the Week
pymotw.com › 2 › pprint
pprint – Pretty-print data structures - Python Module of the Week
... pprint contains a “pretty printer” for producing aesthetically pleasing representations of your data structures. The formatter produces representations of data structures that can be parsed correctly by the interpreter, and are also easy for a human to read.
🌐
FavTutor
favtutor.com › blogs › pretty-print-dictionary-python
Pretty Print Dictionary in Python: pprint & json (with examples)
February 13, 2023 - The Python pprint (pretty-print) module provides a function to display complex data structures like dictionaries in a more readable format.
🌐
Kanaries
docs.kanaries.net › topics › Python › pretty-print-dictionary-python
How to Use Pretty Print for Python Dictionaries – Kanaries
June 7, 2023 - Yet, their representation, particularly ... module slithers in to save the day. The pprint module, standing for "pretty print", aims to provide more readable and aesthetically pleasing representations of complex data structures, like dictionaries....
🌐
Textual
textual.textualize.io › widgets › pretty
Textual - Pretty
May 29, 2023 - The example below shows a pretty-formatted dict, but Pretty can display any Python object.
🌐
TutorialsPoint
tutorialspoint.com › python_text_processing › python_pretty_prints.htm
Python Text Processing - Pretty Printing
The python module pprint is used for giving proper printing formats to various data objects in python. Those data objects can represent a dictionary data type or even a data object containing the JSON data.
🌐
Reddit
reddit.com › r/learnpython › why pretty print?
r/learnpython on Reddit: Why Pretty Print?
October 7, 2020 -

Hi all

I'm trying to understand the usefulness of Pretty Print.

In automate the boring stuff it was used a few times earlier in the book to make things look 'prettier', it didn't really look much better to me but I assumed this was down to taste.

Now I just saw an actual use-case for it later in the book and it seems like a very convoluted method.

After importing pretty print, the format function can be used to convert a list to a string which makes it easier to write to a text doc and subsequently reimport (apparently). But you can just put 'str' in front of the list to achieve the same thing, so I fail to see the point.

Any ideas?

:\

🌐
PyPI
pypi.org › project › prettyprinter
prettyprinter · PyPI
Syntax-highlighting, declarative and composable pretty printer for Python 3.5+
      » pip install prettyprinter
    
Published   Jun 22, 2019
Version   0.18.0
Top answer
1 of 4
16

pprint does not look for any hooks. The pprint.PrettyPrinter uses a dispatch pattern instead; a series of methods on the class that are keyed on class.__repr__ references.

You can subclass pprint.PrettyPrinter to teach it about your class:

class YourPrettyPrinter(pprint.PrettyPrinter):
    _dispatch = pprint.PrettyPrinter._dispatch.copy()

    def _pprint_yourtype(self, object, stream, indent, allowance, context, level):
        stream.write('YourType(')
        self._format(object.foo, stream, indent, allowance + 1,
                     context, level)
        self._format(object.bar, stream, indent, allowance + 1,
                     context, level)
        stream.write(')')

    _dispatch[YourType.__repr__] = _pprint_yourtype

then use the class directly to pretty print data containing YourType instances. Note that this is contingent on the type having their own custom __repr__ method!

You can also plug functions directly into the PrettyPrinter._dispatch dictionary; self is passed in explicitly. This is probably the better option for a 3rd-party library:

from pprint import PrettyPrinter

if isinstance(getattr(PrettyPrinter, '_dispatch'), dict):
     # assume the dispatch table method still works
     def pprint_ExtendedConfigParser(printer, object, stream, indent, allowance, context, level):
         # pretty print it!
     PrettyPrinter._dispactch[ExtendedConfigParser.__repr__] = pprint_ExtendedConfigParser

See the pprint module source code for how the other dispatch methods are written.

As always, single-underscore names like _dispatch are internal implementation details that can be altered in a future version. However, it is the best option you have here. The dispatch table was added in Python 3.5 and is present in at least Python 3.5 - 3.9 alpha.

You may want to look at rich, a third-party library that has some great pretty-printing capabilities, and supports hooks (__rich_repr__); see the documentation on customising pretty-printing.

2 of 4
4

It is not really a solution, but I usually just make objects serializable and pretty print them like this:

pprint(obj.dict())
🌐
freeCodeCamp
freecodecamp.org › news › how-to-pretty-print-json-in-python
How to Pretty Print JSON in Python
April 14, 2023 - This module provides a dumps() function that can serialize Python objects into a JSON formatted string. By default, this function produces a JSON string without any formatting, but we can use the indent parameter to specify the number of spaces to use for indentation. Here's an example of how to pretty print JSON in Python:
🌐
CodeGym
codegym.cc › java blog › learning python › pretty-print (pprint) in python
Pretty-Print (pprint) in Python
July 31, 2024 - Welcome, fellow Python enthusiasts! Today, we’re diving into a handy tool that will make your coding life easier: pprint, short for "pretty-print". By the end of this article, you'll be a pprint pro, knowing when and how to use it to make your data more readable and manageable.