Registry / devops / xmlformatter

xmlformatter

JSON →
library0.2.9pypypi✓ verified 81d ago

A Python library to format (pretty-print) and compress XML documents. Supports both files and strings, with options for indentation, encoding, and XML declaration handling. Current version: 0.2.9. Release cadence: infrequent.

pip install xmlformatter
INSTALL
IMPORT
SIG · XMLFORMATTER
X
xmlformatter
devopspythonv0.2.9
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Formatter
from xmlformatter import Formatter
from xmlformatter import XmlFormatter

Initialize a formatter, format an XML string, and print the pretty-printed result.

from xmlformatter import XmlFormatter formatter = XmlFormatter(indent=' ', encoding_output='UTF-8', preserve_declaration=True) xml_string = '<root><child>text</child></root>' pretty = formatter.format_string(xml_string) print(pretty) # Output: # <?xml version="1.0" encoding="UTF-8"?> # <root> # <child>text</child> # </root>
Debug
Known issues
gotchaThe 'preserve_declaration' parameter only preserves an existing XML declaration; it does not add one if missing. To force a declaration, set 'xml_declaration' parameter instead.
fix
Use formatter = XmlFormatter(xml_declaration=True) to always output declaration.
affects: all
gotchaThe 'indent' parameter defaults to 4 spaces. If you set indent to something else, ensure it's a string of spaces or a single tab. Numeric values may cause unexpected behavior or errors.
fix
Use indent='  ' or indent='\t' explicitly as a string.
affects: all
deprecatedThe parameter 'preserve_whitespace' is no longer supported in version 0.2.9. Use 'preserve' instead.
fix
Replace preserve_whitespace=True with preserve=True in XmlFormatter constructor.
affects: >=0.2.9
Upgrade
Version history
0.2.9latest on PyPI · released May 6, 2026
Audit
Dependencies

No dependency data recorded yet.

Agent activity
10 hits · last 30 days
node
8
Amazon
1
Resources

No resource links recorded.

xmlformatter — pip install xmlformatter · libregistry