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.
pip install types-xmltodict xmltodictVerified import paths — ran on the pinned version, not inferred.
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.
Upgrade `xmltodict` to version 1.0.0 or higher. If encountering type checking errors, align your `types-xmltodict` version with the major/minor version of `xmltodict` (e.g., `types-xmltodict~=1.0.x` for `xmltodict~=1.0.x`).
Always install `xmltodict` alongside `types-xmltodict` using `pip install xmltodict types-xmltodict`.
Ensure the major and minor versions of `types-xmltodict` align with your `xmltodict` installation. For example, `pip install xmltodict~=1.0 types-xmltodict~=1.0`.
Be aware of these limitations when parsing and unparsing. If these nuances are critical, evaluate alternative XML parsing libraries.
Keep `xmltodict` updated to the latest version. Do not disable `disable_entities=True` (the default) unless you fully understand the implications. Carefully validate and sanitize untrusted XML inputs before parsing.
Ensure the dictionary passed to `xmltodict.unparse()` always has a single top-level key representing the XML root element. Wrap multi-root data in a single dictionary if necessary.
Always use the `force_list` parameter when parsing XML where an element might appear zero, one, or many times to ensure consistent list-based access in the resulting dictionary.