Install & Compatibility
Where this runs
tested against v26.2 · 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
muslpy 3.10–3.910 runs
installs and imports cleanly · install 0.0s · import 0.253s · 38.2MB
glibcpy 3.10–3.910 runs
installs and imports cleanly · install 3.0s · import 0.230s · 39MB
37MB installed
● package 37MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
XmlParser
✓ from xsdata.formats.dataclass.parsers import XmlParser
XmlSerializer
✓ from xsdata.formats.dataclass.serializers import XmlSerializer
generated_model_classes
✓ from {your_package_name} import {ClassName}
Classes are generated into a Python package specified by the `--package` CLI option.
This quickstart demonstrates creating a simple dataclass structure, then serializing a Python object to XML and deserializing XML back into Python objects. For complex schemas, `xsdata`'s CLI tool is typically used to generate dataclasses from XSD, DTD, or WSDL files.
from dataclasses import dataclass, field
from datetime import date
from xsdata.formats.dataclass.parsers import XmlParser
from xsdata.formats.dataclass.serializers import XmlSerializer
from xsdata.formats.dataclass.serializers.config import SerializerConfig
@dataclass
class Person:
first_name: str = field(metadata=dict(name='FirstName'))
last_name: str = field(metadata=dict(name='LastName'))
birth_date: date = field(metadata=dict(name='BirthDate', type='Attribute', format='%Y-%m-%d'))
@dataclass
class Family:
person: list[Person] = field(default_factory=list, metadata=dict(name='Person'))
# Create an instance
family_obj = Family(person=[
Person(first_name='John', last_name='Doe', birth_date=date(1980, 5, 15)),
Person(first_name='Jane', last_name='Doe', birth_date=date(1982, 11, 22))
])
# Serialize to XML
config = SerializerConfig(pretty_print=True, xml_declaration=True, encoding='UTF-8')
serializer = XmlSerializer(config=config)
xml_output = serializer.render(family_obj)
print(xml_output)
# Deserialize from XML
xml_input = """
<?xml version="1.0" encoding="UTF-8"?>
<Family>
<Person BirthDate="1980-05-15">
<FirstName>John</FirstName>
<LastName>Doe</LastName>
</Person>
<Person BirthDate="1982-11-22">
<FirstName>Jane</FirstName>
<LastName>Doe</LastName>
</Person>
</Family>
"""
parser = XmlParser()
deserialized_family = parser.from_string(xml_input, Family)
print(deserialized_family.person[0].first_name)
xsdata --version
Errors
Common errors & fixes
command not found: xsdata
The `xsdata` command-line tool's executable is not in your system's PATH, or it was installed in an environment where the global command isn't directly exposed.
fixpython -m xsdata generate --input <schema_file> --output <output_dir>
ModuleNotFoundError: No module named 'xsdata.formats.dataclasses.parsers.xml'
The `xsdata-formats` package, which provides the XML (and other format) parsers and serializers, has not been installed alongside the core `xsdata` library.
fixpip install xsdata-formats
lxml.etree.XMLSyntaxError: Start tag expected, '<' not found, line 1, column 1
The input string provided to an `from_xml` or similar parsing method is not valid XML, is empty, or contains leading/trailing whitespace/characters that prevent proper parsing.
fixEnsure the XML string is valid, well-formed, and contains only the XML content, e.g., by checking the source or using `strip()` on the string before parsing.
xsdata.exceptions.ParserError: Failed to locate schema: myfile.xsd
The specified path to the XML Schema Definition (XSD) file is incorrect, the file does not exist at the given location, or the program lacks the necessary permissions to read it.
fixVerify the absolute or relative path to the XSD file and ensure it is correct and accessible from where the `xsdata generate` command is being executed.
Upgrade
Version history
26.2latest on PyPI · released Feb 15, 2026
Audit
Dependencies
pythonrequiredMinimum Python version required.
lxmloptionalHighly optimized XML parsing backend, included with `[lxml]` extra.
requestsoptionalDefault transport for SOAP webservice clients, included with `[soap]` extra.
clickoptionalCLI entry point, included with `[cli]` extra.