{"id":459,"library":"xmltodict","title":"xmltodict","description":"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.","status":"active","version":"1.0.4","language":"python","source_language":"en","source_url":"https://github.com/martinblech/xmltodict","tags":["XML","JSON","parser","data conversion"],"install":[{"cmd":"pip install xmltodict","lang":"bash","label":"Install xmltodict"}],"dependencies":[],"imports":[{"note":"Ensure to use the full module import.","symbol":"xmltodict","correct":"import xmltodict"}],"quickstart":{"code":"import xmltodict\n\nxml_str = '<foo><bar value=\"1\">test</bar></foo>'\ndict_obj = xmltodict.parse(xml_str)\nprint(dict_obj)","lang":"python","description":"Quickly parse XML to a Python dictionary."},"warnings":[{"fix":"Upgrade to Python 3.9+ and use version 1.0.0 or higher.","message":"Version 1.0.0 dropped legacy compatibility paths for Python 2.x.","severity":"breaking","affected_versions":"<1.0.0"},{"fix":"Use 'import xmltodict' instead of legacy import patterns.","message":"Avoid using outdated patterns to import the library.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-05-12T13:57:16.201Z","next_check":"2026-06-26T00:00:00.000Z","problems":[{"fix":"pip install xmltodict","cause":"The xmltodict library is not installed in the Python environment where the script is being run.","error":"ModuleNotFoundError: No module named 'xmltodict'"},{"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.","cause":"The input XML string is not well-formed, contains syntax errors, or invalid characters, preventing xmltodict from parsing it correctly.","error":"xml.parsers.expat.ExpatError: syntax error: line X, column Y"},{"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'.","cause":"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 '@').","error":"KeyError: 'some_element_name'"},{"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.","cause":"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.","error":"ValueError: Document must have exactly one root."},{"fix":"Validate the XML input for well-formedness and correct any syntax errors, mismatched tags, or invalid characters before passing it to `xmltodict.parse()`.","cause":"The input provided to `xmltodict.parse()` is not valid XML or contains malformed characters, preventing proper parsing.","error":"xmltodict.expat.ExpatError: not well-formed (invalid token): line 1, column 0"}],"ecosystem":"pypi","meta_description":null,"install_score":100,"install_tag":"verified","quickstart_score":80,"quickstart_tag":"verified","pypi_latest":null,"install_checks":{"last_tested":"2026-05-12","tag":"verified","tag_description":"installs cleanly on critical runtimes, fast import, recently tested","results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.12,"mem_mb":4.1,"disk_size":"17.8M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.08,"mem_mb":4.1,"disk_size":"18M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.17,"mem_mb":4.8,"disk_size":"19.7M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.14,"mem_mb":4.8,"disk_size":"20M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.16,"mem_mb":4.6,"disk_size":"11.6M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.15,"mem_mb":4.6,"disk_size":"12M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.14,"mem_mb":4.7,"disk_size":"11.2M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.14,"mem_mb":4.7,"disk_size":"12M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.12,"mem_mb":4.2,"disk_size":"17.3M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.1,"mem_mb":4.2,"disk_size":"18M"}]},"quickstart_checks":{"last_tested":"2026-04-23","tag":"verified","tag_description":"quickstart runs on critical runtimes, recently tested","results":[{"runtime":"python:3.10-alpine","exit_code":0},{"runtime":"python:3.10-slim","exit_code":0},{"runtime":"python:3.11-alpine","exit_code":0},{"runtime":"python:3.11-slim","exit_code":0},{"runtime":"python:3.12-alpine","exit_code":0},{"runtime":"python:3.12-slim","exit_code":0},{"runtime":"python:3.13-alpine","exit_code":0},{"runtime":"python:3.13-slim","exit_code":0},{"runtime":"python:3.9-alpine","exit_code":0},{"runtime":"python:3.9-slim","exit_code":0}]}}