Registry / serialization / xmltodict

xmltodict

JSON →
library1.0.4pypypi✓ verified 25d ago

xmltodict makes working with XML feel like you are working with JSON. The current version is 1.0.4, with regular updates and bug fixes.

pip install xmltodict
INSTALL
IMPORT
SIG · XMLTODICT
X
xmltodict
serializationpythonv1.0.4
Install
1.6s avg
Import
126ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.0.4 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.134s · 17.8MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.6s · import 0.118s · 18MB
16MB installed
● package 16MB
Code
Verified usage

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

xmltodict
import xmltodict
Ensure to use the full module import.

Quickly parse XML to a Python dictionary.

import xmltodict xml_str = '<foo><bar value="1">test</bar></foo>' dict_obj = xmltodict.parse(xml_str) print(dict_obj)
Debug
Known issues
breakingVersion 1.0.0 dropped legacy compatibility paths for Python 2.x.
fix
Upgrade to Python 3.9+ and use version 1.0.0 or higher.
affects: <1.0.0
gotchaAvoid using outdated patterns to import the library.
fix
Use 'import xmltodict' instead of legacy import patterns.
affects: all
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'xmltodict'
The xmltodict library is not installed in the Python environment where the script is being run.
fix
pip install xmltodict
xml.parsers.expat.ExpatError: syntax error: line X, column Y
The input XML string is not well-formed, contains syntax errors, or invalid characters, preventing xmltodict from parsing it correctly.
fix
Ensure the XML string is syntactically correct and well-formed according to XML standards, or handle potential parsing errors with a try-except block.
KeyError: 'some_element_name'
An attempt was made to access an XML element or attribute using a dictionary key that does not exist in the parsed output, often due to incorrect case, wrong path, or the element being an attribute (which are prefixed with '@').
fix
Inspect the structure of the parsed dictionary output (e.g., by printing it) to identify the correct key, paying attention to case sensitivity and attribute prefixes like '@attribute_name'.
ValueError: Document must have exactly one root.
The dictionary provided to `xmltodict.unparse` does not represent a valid XML structure because it lacks a single top-level key that would serve as the XML root element, or it has multiple top-level keys.
fix
Ensure the input dictionary for unparsing has exactly one top-level key that will act as the root element of the generated XML document.
xmltodict.expat.ExpatError: not well-formed (invalid token): line 1, column 0
The input provided to `xmltodict.parse()` is not valid XML or contains malformed characters, preventing proper parsing.
fix
Validate the XML input for well-formedness and correct any syntax errors, mismatched tags, or invalid characters before passing it to `xmltodict.parse()`.
Upgrade
Version history
1.0.4latest on PyPI · released Feb 22, 2026
Audit
Dependencies

No dependency data recorded yet.

Agent activity
56 hits · last 30 days
node
48
OpenAI (training)
1
Resources
xmltodict — pip install xmltodict · libregistry