XML to Python Converter
Paste XML and generate Python models in dataclass, pydantic, TypedDict, or attrs style.
Last updated: May 28, 2026
Find this tool useful? Support the project to keep it free!
Buy me a coffeeWhat is XML to Python Converter?
XML data often needs to be represented as Python classes before it can be validated, transformed, or passed through an application. This converter normalizes an XML sample into a JSON-like object shape, then generates Python types from that structure.
Attributes can be preserved, repeated sibling elements become lists, nested elements become nested classes, and simple text values can be inferred as int, float, bool, or str. Choose the Python model style that matches your project: @dataclass for lightweight value objects, pydantic for runtime validation, TypedDict for dict-based typing, or attrs for attrs-based models.
How to Use XML to Python Converter
Paste XML into the input panel.
Choose a Python output style.
Set a root class name or leave it blank to use the XML root element.
Choose Python 3.10+ or Python 3.9 type syntax.
Toggle XML attributes, scalar inference, and optional fields.
Copy the generated Python code.
Common Use Cases
- Creating pydantic models from XML API samples.
- Bootstrapping dataclasses for XML feed processing.
- Adding TypedDict hints to code that handles XML-derived dictionaries.
- Migrating XML fixtures into typed Python test data.
- Documenting XML response shapes with Python classes.
Example Input and Output
An XML order with repeated item elements becomes Python classes with list fields.
<order id="A100"><item><quantity>2</quantity></item></order>from dataclasses import dataclass
@dataclass
class Item:
quantity: int
@dataclass
class Order:
id_: str
item: list[Item]Privacy
All conversion happens in your browser. XML input is not sent to a server.
XML namespaces
Namespace prefixes are preserved in parsed XML names by the browser parser. Review generated field names when your XML uses namespaces.

