Registry / serialization / xsdata

xsdata

JSON →
library26.2pypypi✓ verified 24d ago

xsData is a complete data binding library for Python (current version 26.2) that allows developers to access and use XML and JSON documents as simple objects rather than using DOM. It features a code generator for XML schemas, DTD, WSDL definitions, XML & JSON documents, producing simple dataclasses with type hints. It is actively maintained with frequent releases, typically monthly or bi-monthly.

pip install xsdata
INSTALL
IMPORT
SIG · XSDATA
X
xsdata
serializationpythonv26.2
Install
3.0s avg
Import
241ms
Disk
37MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
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
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 0.253s · 38.2MB
glibc
py 3.103.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
Debug
Known issues
breakingSupport for Python 3.9 was dropped in version 26.1. Users on Python 3.9 must upgrade their Python interpreter to >=3.10 to use newer xsData versions.
fix
Upgrade Python to 3.10 or newer.
affects: >=26.1
gotchaComplex XML schemas can lead to circular import issues in the generated Python models, especially with the default `filenames` structure style. Consider using alternative structure styles like `namespaces`, `clusters`, or `single-package` to mitigate this.
fix
Use CLI options such as `--structure-style namespaces` or `--structure-style single-package` during code generation.
affects: all
gotchaThe parser's default behavior for type conversion is lenient, converting problematic values to `str` and emitting a `ConverterWarning` rather than raising an exception. This can mask data quality issues.
fix
Set `ParserConfig.fail_on_converter_warnings = True` to treat conversion warnings as exceptions and enforce strict type validation during parsing.
affects: all
breakingRecent versions (e.g., v26.2) have fixed issues where elements in the same choice but different branches were incorrectly merged as lists. This correction might alter the structure of generated dataclasses or the parsing behavior for existing XML documents if previous versions relied on the 'incorrect' merging logic.
fix
Review generated models and parsing logic, especially for schemas with complex choices, after upgrading. Regenerate models and test parsing against your expected XML inputs.
affects: >=26.2
deprecatedThe `--ns-struct` CLI option has been deprecated. Its functionality is now provided by `--structure-style namespaces`.
fix
Replace `--ns-struct` with `--structure-style namespaces` when generating code from the command line.
affects: >=21.6
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.
fix
python -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.
fix
pip 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.
fix
Ensure 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.
fix
Verify 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.
Agent activity
44 hits · last 30 days
node
38
OpenAI (training)
1
Resources
xsdata — pip install xsdata · libregistry