Depending on what you're doing with the output, one option is to use JSON for the display.

import json
x = {'planet' : {'has': {'plants': 'yes', 'animals': 'yes', 'cryptonite': 'no'}, 'name': 'Earth'}}

print json.dumps(x, indent=2)

Output:

{
  "planet": {
    "has": {
      "plants": "yes", 
      "animals": "yes", 
      "cryptonite": "no"
    }, 
    "name": "Earth"
  }
}

The caveat to this approach is that some things are not serializable by JSON. Some extra code would be required if the dict contained non-serializable items like classes or functions.

Answer from David Narayan on Stack Overflow
🌐
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
🌐
Formatter.org
formatter.org › python-formatter
Python Formatter Online – Beautify and Format Python Code
Beautify and format Python code online to improve readability, fix indentation, and keep formatting consistent.
🌐
TutorialsPoint
tutorialspoint.com › online_python_formatter.htm
Online Python Formatter | Tutorialspoint
Online Python Formatter and Beautifier - Try online Python Code formatter and beautifier and Editor to beautify and format Python code using jQuery Plug-in
🌐
CleanCSS
cleancss.com › python-beautify
Python Viewer, Formatter, Editor
Enter your messy, minified, or obfuscated Python into the field above to have it cleaned up and made pretty. The editor above also contains helpful line numbers and syntax highlighting. There are many option to tailor the beautifier to your personal formatting tastes.
🌐
Minifier
minifier.org › python-beautifier
Python Beautifier - Format & Beautify Python Code Online
Turn messy Python code into a well-structured format in seconds. Proper formatting minimizes errors, which is easy to read and maintain. Makes complex dictionaries and nested Python objects visually clear and structured.
🌐
Sublime Forum
forum.sublimetext.com › t › how-to-beautify-python-dictionaries-in-sublimetext-plugin › 46549
How to beautify python dictionaries in SublimeText plugin? - Technical Support - Sublime Forum
September 19, 2019 - Could anyone please suggest me a package that can beautify python dictionaries? Ie: input: (python dict) => output (python dict) I’m not interested on using pprint.pformat as the output is really ugly and I’d like to get the same output than prettyprinter… unfortunately I can’t use prettyprinter on SublimeText as it won’t install with the old python 3.3.5 (ie: i’ll get "colorama requires Python '>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*' but the running Python is 3.3.5" error) I was looking fo...
🌐
Pyrfecter
pyrfecter.com › format-python-code
Format Python code online · Pyrfecter
June 26, 2025 - If you have Python code you want to format online, look no further. Pyrfecter is an easy and secure way to format, lint, and improve your Python code all from inside your browser. Even if your code is well written Pyrfecter can help.
Find elsewhere
🌐
datagy
datagy.io › home › python posts › python: pretty print a dict (dictionary) – 4 ways
Python: Pretty Print a Dict (Dictionary) - 4 Ways • datagy
December 19, 2022 - In this tutoria, you’ll learn how to use Python to pretty print a dict (dictionary). You’ll learn how to use the pprint library as well as the json library to do this. You’ll also learn how to pretty print nested dictionaries in Python.
🌐
Python
docs.python.org › 3 › library › pprint.html
pprint — Data pretty printer
Return the formatted representation of object as a string. indent, width, depth, compact, sort_dicts and underscore_numbers are passed to the PrettyPrinter constructor as formatting parameters and their meanings are as described in the documentation ...
🌐
ExtendsClass
extendsclass.com › python-formatter.html
Python formatter online
This tool uses Black: the uncompromising Python code formatter (MIT License). Black is a PEP 8 compliant opinionated formatter. Note: This beautifier are few options.
🌐
Code Beautify
codebeautify.org › python-formatter-beautifier › y24bec644
Python dict crap...
Python Formatter helps to format unformatted or ugly Python data and helps to save and share Python.
🌐
Encode64
encode64.com › home › formatters › python formatter
Free Online Python Formatter – Black & PEP 8 Style Code Beautifier | Encode64
from fastapi import FastAPI app = FastAPI() @app.get("/items/{item_id}") async def read_item(item_id: int, q: str | None = None) -> dict: return {"item_id": item_id, "q": q} Turn exploratory Jupyter cells into clean Python scripts ready for version control.
🌐
GitHub
github.com › google › yapf
GitHub - google/yapf: A formatter for Python files · GitHub
To control the style, run YAPF with the --style argument. It accepts one of the predefined styles (e.g., pep8 or google), a path to a configuration file that specifies the desired style, or a dictionary of key/value pairs.
Starred by 14K users
Forked by 900 users
Languages   Python
🌐
JSON Formatter
jsonformatter.org › 66628e
Full Dictionary Data
Use Auto switch to turn auto update on or off for beautification.
🌐
Appspot
pythoniter.appspot.com
Pythoniter - Pretty Python Online Formatter
Welcome. Use this text box to input your dirty-formatted python code, and get a nice, well ordered file · If you have made syntax mistakes, It will complain and don't give you the cookie ;)
🌐
Real Python
realpython.com › python-pretty-print
Prettify Your Data Structures With Pretty Print in Python – Real Python
October 4, 2022 - The keys of the dictionaries are even visually indented! This output makes it so much more straightforward to scan and visually analyze data structures. Note: The output you’ll see will be longer if you run the code yourself. This code block truncates the output for readability. If you’re a fan of typing as little as possible, then you’ll be pleased to know that pprint() has an alias, pp(): ... Note: Python has included this alias since version 3.8.0 alpha 2.
🌐
Astral
docs.astral.sh › ruff › formatter
The Ruff Formatter | Ruff
The Ruff formatter is an extremely fast Python code formatter designed as a drop-in replacement for Black, available as part of the ruff CLI via ruff format.