parse-xml1
A source-preserving XML 1.0 parser for Python 3.14+, with no runtime
dependencies.
python -m pip install parse-xml1
from parse_xml1 import Element, Text, parse
document = parse('<?xml version="1.0"?><greeting lang="en">Hello, XML!</greeting>')
greeting = document.root
assert isinstance(greeting, Element)
assert greeting.name == "greeting"
assert greeting.attributes[0].value == "en"
assert isinstance(greeting.children[0], Text)
assert greeting.to_xml() == '<greeting lang="en">Hello, XML!</greeting>'
The immutable document tree retains the exact original source, including
declarations, comments, processing instructions, CDATA sections, whitespace,
and entity references. Parsed text and attribute values expose their expanded
XML 1.0 values. Internal general entities are supported; external entities and
external DTD subsets are never fetched. Parsing has configurable character,
node, nesting, and entity-expansion limits.
See the API contract for node types, source spans, limits, and
entity handling.
Development
uv sync --locked
uv run --frozen python -m pytest
uv run --frozen python scripts/check_distribution.py --output-dir /tmp/parse-xml1-candidate
The distribution check builds both wheel and source archive and verifies that
the installed wheel imports the typed parse_xml1 package.
See release instructions for PyPI Trusted Publishing setup.