xmlformatter
Format and compress XML documents
Decision gist · record as of 2026-08-14
Yes. xmlformatter is a lightweight, actively maintained tool with no external dependencies, a permissive MIT license, and no known vulnerabilities. Install it if you need to format, normalize, or compress XML documents—either programmatically or from the command line. The distinct handling of element vs. mixed content makes it useful for documents that blend structured data and natural language text.AI-flagged interpretation of the facts on this page — verify before relying
Before you install
- Low install friction with no runtime dependencies.
- Active maintenance status with a recent release.
License · maintenance · safety
MIT (permissive) — MIT license permits use, modification, and distribution with minimal restrictions, making it suitable for both open-source and proprietary projects.
last release 2026-05-06 (100 days)
0 known vulnerabilities (OSV.dev, 2026-08-14) · 92,197 downloads/mo, #13,469 on PyPI
Alternatives
Verify before relying
import xmlformatter
formatter = xmlformatter.Formatter(indent="2", indent_char=" ")
formatter.format_file("/path/to/doc.xml")- Whether the package handles large XML files efficiently or has memory constraints
- Performance characteristics when formatting deeply nested XML structures
- Compatibility with XML schemas or DOCTYPE declarations
What it is and what it does
xmlformatter is a Python 3 XML formatting library that normalizes whitespace in XML documents according to a set of explicit rules. It distinguishes between element content (treated as structured data) and mixed content (treated as text), applying different formatting strategies to each. For element content, it removes leading and trailing whitespace and collapses whitespace sequences; for mixed content, it preserves text flow while normalizing spacing around inline elements. The package provides both a programmatic API via the Formatter class and a command-line tool (xmlformat) for standalone use.
The library supports customization through options like indentation width and character, output encoding, element preservation (to skip formatting subtrees), and compression modes. It can read from files, strings, or stdin, and write to files or stdout. The package is a Python 3 replacement for the older Python 2 XmlFormatter package and includes migration guidance for existing users.
Use it for
- Pretty-print XML configuration files for readability and version control diffs
- Minify XML documents to reduce file size for transmission or storage
- Normalize whitespace in mixed-content XML (like XHTML or DocBook) while preserving text semantics
- Automate XML formatting in build pipelines or pre-commit hooks via the command-line tool
- Preserve specific XML subtrees (e.g. code blocks or literal content) while formatting the rest of a document
Worth the install?
AI-flagged interpretation of the facts on this page. Verify before relying on it.
Yes.
xmlformatter is a lightweight, actively maintained tool with no external dependencies, a permissive MIT license, and no known vulnerabilities. Install it if you need to format, normalize, or compress XML documents—either programmatically or from the command line. The distinct handling of element vs. mixed content makes it useful for documents that blend structured data and natural language text.
Install
xmlformatter on PyPI
Before you install
Low install friction with no runtime dependencies. Active maintenance status with a recent release.
License in practice
MIT license permits use, modification, and distribution with minimal restrictions, making it suitable for both open-source and proprietary projects.
Quickstart
import xmlformatter
formatter = xmlformatter.Formatter(indent="2", indent_char=" ")
formatter.format_file("/path/to/doc.xml")
Verify before relying
- Whether the package handles large XML files efficiently or has memory constraints
- Performance characteristics when formatting deeply nested XML structures
- Compatibility with XML schemas or DOCTYPE declarations
Package facts
| License | MIT permissive |
| Python support | Supports the current Python release >=3.2 |
| Install friction | Low. Pure-Python wheel |
| Runtime dependencies | None |
| Maintenance | Actively maintained 100 days since the last release |
| First released | |
| Downloads | 92,197 / month, #13,469 on PyPI 30-day window, as of 2026-08-14 |
| Known vulnerabilities | None known OSV.dev, checked 2026-08-14 |
| Classifiers | Programming Language :: Python :: 3Topic :: Text Processing :: Markup :: XML |
Evidence: xmlformatter-0.2.9-py3-none-any.whl
Tags
Let your AI agent find packages like this
Example. Real query, live index.
You found this page by searching. An agent finds it by wishing: SkillFed indexes 14,416 PyPI packages by what they can do, searchable in plain language.
wish › “xml formatting and indentation”
- xmlformatterFormats and compresses XML documents by applying distinct whitespace…
- prettierfierReformats HTML and XML strings with intelligent inline-tag handling,…
- reqifReqIF is a Python library for parsing, unparsing, formatting,…
Give your agent the search over MCP, or paste the wish link into any chat.
More XML packages
Beautiful Soup parses HTML and XML documents into a navigable tree, providing Pythonic methods to search, iterate, and modify the parsed content.
Install it if you need to parse or extract data from markup documents.
lxml provides Python bindings to libxml2 and libxslt, enabling parsing, validation, and transformation of XML and HTML documents through an ElementTree-compatible API with support for XPath, XSLT, and schema validation.
Install it if you need robust XML/HTML parsing, validation, or transformation; avoid it only if you must stay pure-Python and can accept slower performance.
Defusedxml hardens Python's standard XML libraries against XML bomb attacks and entity expansion exploits by providing drop-in replacements that disable dangerous parsing features by default.
Install it if your application parses any XML from untrusted sources.
Docutils converts plaintext documentation in reStructuredText format into multiple output formats including HTML, XML, and LaTeX using a modular processing system.
Converts XML to Python dictionaries and back, treating XML parsing and generation like working with JSON.
Sphinx generates professional documentation from reStructuredText source files, producing HTML, PDF, EPUB, and other formats with automatic cross-references, code highlighting, and hierarchical navigation.
See also paragraphs · prettierfier · dicttoxml · compact-json · dict2xml · htmlmin2 · meld3 · et-xmlfile · objprint