Typing stubs for xmltodict

1.0.1.20260408 · active · verified Sat Apr 11

This package provides static type annotations for the `xmltodict` library, enabling type checkers like MyPy, Pyright, or PyCharm to validate code that uses `xmltodict`. It is part of the `typeshed` project, a community-maintained repository for Python library stubs, and is automatically released to PyPI. The current version is 1.0.1.20260408, with `typeshed` typically releasing updates daily.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates the core functionality of `xmltodict`: parsing an XML string into a Python dictionary and then unparsing a dictionary back into an XML string. With `types-xmltodict` installed, a type checker would ensure that the dictionary keys, values, and function arguments/returns conform to the expected types.

import xmltodict

# Example XML string
xml_string = """
<person>
    <name>John Doe</name>
    <age>30</age>
    <city>New York</city>
</person>
"""

# Parse XML to a Python dictionary (type-checked by types-xmltodict)
data_dict = xmltodict.parse(xml_string)
print(f"Parsed Dictionary: {data_dict}")

# Access data (type-checked)
name = data_dict['person']['name']
print(f"Name: {name}")

# Modify data
data_dict['person']['age'] = 31

# Unparse dictionary back to XML (type-checked)
modified_xml = xmltodict.unparse(data_dict, pretty=True, indent='  ')
print(f"\nModified XML:\n{modified_xml}")

view raw JSON →