Dan's solution is just wrong, and Ismail's in incomplete.

  1. __str__() is not called, __repr__() is called.
  2. __repr__() should return a string, as pformat does.
  3. print normally indents only 1 character and tries to save lines. If you are trying to figure out structure, set the width low and indent high.

Here is an example

class S:
    def __repr__(self):
        from pprint import pformat
        return pformat(vars(self), indent=4, width=1)

a = S()
a.b = 'bee'
a.c = {'cats': ['blacky', 'tiger'], 'dogs': ['rex', 'king'] }
a.d = S()
a.d.more_c = a.c

print(a)

This prints

{   'b': 'bee',
    'c': {   'cats': [   'blacky',
                         'tiger'],
             'dogs': [   'rex',
                         'king']},
    'd': {   'more_c': {   'cats': [   'blacky',
                               'tiger'],
                  'dogs': [   'rex',
                              'king']}}}

Which is not perfect, but passable.

Answer from Charles Merriam on Stack Overflow
🌐
Python
docs.python.org › 3 › library › pprint.html
pprint — Data pretty printer
Source code: Lib/pprint.py 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 struc...
Discussions

Pretty print JSON from URL
I've not done a lot in this space but something I have tried in the past with JSON's is to convert to a pandas DataFrame. I'm not sure if this is exactly what you are after, but the following stackoverflow post may help: https://stackoverflow.com/questions/21104592/json-to-pandas-dataframe More on reddit.com
🌐 r/learnpython
13
2
August 27, 2021
New Protocol for Pretty Printing
Looks pretty cool to me. dataclasses have this kind of repr thing built in, but it would be nice to have this tool if i were doing something else, to build them on my own. that said, your code above requires putting in the defaults twice. i bet you could automate the work inside __rich_repr__ by using inspect.signature, something like this: from inspect import signature from rich.repr import rich_repr @rich_repr class Bird: def __init__(self, name, eats=None, fly=True, extinct=False): self.name = name self.eats = list(eats) if eats else [] self.fly = fly self.extinct = extinct def __rich_repr__(self): for name, param in signature(Bird).parameters.items(): if param.default == param.empty: yield name, getattr(self, name) else: yield name, getattr(self, name), param.default if __name__ == "__main__": print(Bird("gull", eats=["fish", "chips", "ice cream", "sausage rolls"])) print(Bird("penguin", eats=["fish"], fly=False)) print(Bird("dodo", eats=["fruit"], fly=False, extinct=True)) More on reddit.com
🌐 r/Python
2
66
May 8, 2021
Format specifier for pretty printing - Ideas - Discussions on Python.org
Since python has format specifiers, I was wondering whether these could be use to add pretty printing functionality to any object. The pprint module could then make use of this, by delegating the formatting to the objects themselves with a fallback to the current implementation (eg the ... More on discuss.python.org
🌐 discuss.python.org
0
February 4, 2025
Printing a class object?
I'm not familiar with that package, but a quick look at the documentation would suggest that as long as the API is consistent it should be as simple as import pokebase as pb pokemon = pb.pokemon(1) print([move.name for move in pokemon.moves]) EDIT: And if that gives an error, check what attributes the move objects have: from pprint import pprint pprint(dir(pokemon.moves[0])) More on reddit.com
🌐 r/learnpython
8
2
January 22, 2023
🌐
Real Python
realpython.com › python-pretty-print
Prettify Your Data Structures With Pretty Print in Python – Real Python
October 4, 2022 - It’s possible to create an instance of PrettyPrinter that has defaults you’ve defined. Once you have this new instance of your custom PrettyPrinter object, you can use it by calling the .pprint() method on the PrettyPrinter instance: ... >>> from pprint import PrettyPrinter >>> custom_printer = PrettyPrinter( ...
🌐
Reddit
reddit.com › r/learnpython › pretty print json from url
r/learnpython on Reddit: Pretty print JSON from URL
August 27, 2021 -

Hello Everyone,

I've hit a frustrating wall and after much googling I took a deep breath and felt the best approach was to ask you all for advice.

I'm making a very simple script and need assistance with what tool I should use to move forward.

Step 1: Fetch the URL Step 2: Make the JSON pretty. Such as a top-down listing of Title and URL only.

import requests

#make the URL call
page = requests.get('http://gleamlist.com:5000/api')
#verify the page has content - just for testing.
print(page.content)

I've tried using the json module but confuse myself and I've thought maybe BS4 would help but also confuse myself. I believe JSON is basically a dictionary and I want to parse out the info. Could anyone assist me with some tips or a specific topic to research and implement please?

🌐
DigitalOcean
digitalocean.com › community › tutorials › python-pretty-print-json
How to Pretty Print JSON in Python | DigitalOcean
September 16, 2025 - Learn how to pretty print JSON in Python using built-in tools like json.dumps() and pprint to improve readability and debug structured data efficiently.
🌐
GeeksforGeeks
geeksforgeeks.org › python › pprint-data-pretty-printer-python
pprint : Data pretty printer in Python - GeeksforGeeks
The pprint module (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
docs.python.org › id › 3.5 › library › pprint.html
8.11. pprint --- Data pretty printer — dokumentasi Python 3.5.10
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.
🌐
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 Engineer
python-engineer.com › posts › pprint-python
How to use pprint in Python? - Python Engineer
May 17, 2022 - [{'application': ['Data Science', ... and above. Returns True if the object passed is readable by pprint, if an object is readable it can be pretty printed....
🌐
Reddit
reddit.com › r/python › new protocol for pretty printing
r/Python on Reddit: New Protocol for Pretty Printing
May 8, 2021 -

I've recently documented a protocol in Rich to add pretty printing to arbitrary objects.

The problem was that containers like dicts, lists, sets etc could be formatted over multiple lines, but custom classes are limited to a string that can be generated from __repr__. The new protocol in Rich adds a __rich_repr__ method which allows an object to declare how it should be pretty printed.

Looking for feedback. Here are the docs.

Here's an example of a __rich_repr__ method.

And here's what it looks like when you pretty print a Bird instance:

🌐
Python.org
discuss.python.org › ideas
Format specifier for pretty printing - Ideas - Discussions on Python.org
February 4, 2025 - Since python has format specifiers, I was wondering whether these could be use to add pretty printing functionality to any object. The pprint module could then make use of this, by delegating the formatting to the objects themselves with a fallback to the current implementation (eg the ...
🌐
Jython
jython.org › jython-old-sites › docs › library › pprint.html
8.18. pprint — Data pretty printer — Jython v2.5.2 documentation
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.
🌐
Reddit
reddit.com › r/learnpython › printing a class object?
r/learnpython on Reddit: Printing a class object?
January 22, 2023 -

I'm trying to use the pokebase wrapper just to explore and I'm really struggling with it.

I just want to print all the moves a pokemon has but they show up as locations in memory instead of the actual values. I'm not sure how to get the data out of this.

import pokebase as pb

pokemon = pb.pokemon(1)
print(pokemon.moves)

Example of results:

[<pokebase.interface.APIMetadata object at 0x000001E774593C70>, <pokebase.interface.APIMetadata object at 0x000001E774543940>, <pokebase.interface.APIMetadata object at 0x000001E774593B20>]
🌐
Analytics Vidhya
analyticsvidhya.com › home › how to use pprint in python? [explained with examples]
How to Use PPrint in Python? [Explained with Examples]
October 19, 2024 - A. Pprint (pretty print) is a Python module used for formatting complex data structures more readably and organized, especially when printing them to the console or writing to a file.
🌐
IPython
ipython.org › ipython-doc › 3 › api › generated › IPython.lib.pretty.html
Module: lib.pretty — IPython 3.2.1 documentation
All you have to do is to add a _repr_pretty_ method to your object and call the methods on the pretty printer passed: class MyObject(object): def _repr_pretty_(self, p, cycle): ... Depending on the python version you want to support you have two possibilities.
🌐
Python Module of the Week
pymotw.com › 2 › pprint
pprint – Pretty-print data structures - Python Module of the Week
It formats your object and writes it to the data stream passed as argument (or sys.stdout by default). from pprint import pprint from pprint_data import data print 'PRINT:' print data print print 'PPRINT:' pprint(data) $ python pprint_pprint.py PRINT: [(0, {'a': 'A', 'c': 'C', 'b': 'B', 'e': 'E', 'd': 'D', 'g': 'G', 'f': 'F', 'h': 'H'}), (1, {'a': 'A', 'c': 'C', 'b': 'B', 'e': 'E', 'd': 'D', 'g': 'G', 'f': 'F', 'h': 'H'}), (2, {'a': 'A', 'c': 'C', 'b': 'B', 'e': 'E', 'd': 'D', 'g': 'G', 'f': 'F', 'h': 'H'})] PPRINT: [(0, {'a': 'A', 'b': 'B', 'c': 'C', 'd': 'D', 'e': 'E', 'f': 'F', 'g': 'G', 'h': 'H'}), (1, {'a': 'A', 'b': 'B', 'c': 'C', 'd': 'D', 'e': 'E', 'f': 'F', 'g': 'G', 'h': 'H'}), (2, {'a': 'A', 'b': 'B', 'c': 'C', 'd': 'D', 'e': 'E', 'f': 'F', 'g': 'G', 'h': 'H'})]
🌐
Educative
educative.io › answers › what-is-the-pretty-print-module-in-python
What is the pretty-print module in Python?
The pprint module can be used to pretty-print the Python data structures in a readable format. The pprint is a native Python library. We can use the pprint() method or create our pprint object with PrettyPrinter().
🌐
Real Python
realpython.com › lessons › pretty-print
Pretty Print (Video) – Real Python
>>> from pprint import pprint >>> data = { ... 'squares':[x**2 for x in range(10)] ... } >>> pprint(data) {'squares': [0, 1, 4, 9, 16, 25, 36, 49, 64, 81]} >>> data['tens'] = [x**10 for x in range(10)] >>> print(data) {'squares': [0, 1, 4, 9, 16, 25, 36, 49, 64, 81], 'tens': [0, 1, 1024, 59049, 1048576, 9765625, 60466176, 282475249, 1073741824, 3486784401]} >>> pprint(data) {'squares': [0, 1, 4, 9, 16, 25, 36, 49, 64, 81], 'tens': [0, 1, 1024, 59049, 1048576, 9765625, 60466176, 282475249, 1073741824, 3486784401]} >>> pprint(data, width=20) {'squares': [0, 1, 4, 9, 16, 25, 36, 49, 64, 81], 'ten
Published   May 5, 2020