What is the best way (or are the various ways) to pretty print XML in Python?
As of Python 3.9 (still a release candidate as of 12 Aug 2020), there is a new xml.etree.ElementTree.indent()
function for pretty-printing XML trees.
Sample usage:
import xml.etree.ElementTree as ET
element = ET.XML("text")
ET.indent(element)
The upside is that it does not require any additional libraries. For more information check https://bugs.python.org/issue14465 and https://github.com/python/cpython/pull/15200