Modern XML & JSON Data Binding for Python 3.12+¶
pyxsdata is a modern, high-performance data binding and code generation library for Python 3.12+. It allows developers to seamlessly convert XML and JSON documents into native Python objects (Standard Dataclasses or Pydantic v2 models) rather than dealing directly with the DOM.
A Modern Successor to xsdata
pyxsdata is an actively maintained, modernized fork of xsdata designed exclusively for Python 3.12+. It consolidates ecosystem extensions like xsdata-pydantic directly into the unified core, introduces native Rust PolyXML zero-copy acceleration, ultra-fast C++ pugixml pull-parsing support, leverages modern PEP 695 generics, and is built with modern tooling (uv, ty, and ruff).
Looking for Next-Generation Multi-Language Tooling? Check out PolyXML
For greenfield projects, microsecond-latency telemetry, or polyglot architectures (Python, Rust, C++, Java, TypeScript, Go, C#), we recommend PolyXML—a unified safe-Rust compiler (protoc for XML) and streaming runtime executing 10x–24x faster with zero intermediate DOM allocations and architectural immunity to XXE vulnerabilities.
⚡ Quick Start¶
Installation Extras
cli: Command-line interface and code generatorpydantic: Native Pydantic v2 bindings and code generationcore: Native RustPolyXMLengine for ultra-fast throughput (~300k objs/s)pugixml: C++ streaming pull parser for low latencylxml: High-performance C-based XML parsing with DTD/XInclude supportsoap: SOAP client webservice transport
Generate Python dataclasses or Pydantic models from any schema:
Parse and serialize XML with standard Python dataclasses:
from pyxsdata.formats.dataclass.parsers import XmlParser
from pyxsdata.formats.dataclass.serializers import XmlSerializer
from pyxsdata.formats.dataclass.serializers.config import SerializerConfig
from myapp.models import PurchaseOrder
# Parsing
parser = XmlParser()
order = parser.parse("order.xml", PurchaseOrder)
print(order.bill_to.name) # "Robert Smith"
# Serializing
config = SerializerConfig(pretty_print=True)
serializer = XmlSerializer(config=config)
xml_output = serializer.render(order)
Drop-in XML parsing and serialization using Pydantic models:
from pyxsdata.pydantic.bindings import XmlParser, XmlSerializer
from myapp.models import PurchaseOrder
parser = XmlParser()
order = parser.from_string(xml_text, PurchaseOrder)
# Full Pydantic v2 features:
data_dict = order.model_dump()
json_schema = order.model_json_schema()
serializer = XmlSerializer()
xml_output = serializer.render(order)
🌟 Key Features¶
- Unified Schema Support: Generate models from W3C XML Schema (XSD 1.0 & 1.1), WSDL 1.1, DTD definitions, and raw XML or JSON documents.
- Native Pydantic v2: Built-in first-class Pydantic v2 code generator and binding
layer (
pyxsdata.pydantic). No external plugins required. - Blazing Fast Performance: Up to 15x faster XML deserialization (~300k
objs/sec) with native Rust PolyXML, plus direct scalar and proxy converter fast
paths, MRO caching, cached child metadata lookups, short-circuited attribute checks,
and native support for
xml.etree,lxml, and C++pugixml. - Modern Python 3.12+: Strictly built for Python 3.12+. Fully type-annotated, PEP
695 generics, and verified with Astral
tywith zero diagnostics.
💡 The Philosophy¶
!!! note "Why naive?" The W3C XML Schema specification is notoriously complex because it was designed to accommodate every conceivable document layout. When consuming schemas in application code, developers simply need clean, intuitive data structures.
`pyxsdata` simplifies XML binding through an elegant core assumption:
> **All schema definitions are classes; everything else is class properties.**
📚 Explore the Documentation¶
- 5-Minute Quickstart - Get up and running in minutes with a complete step-by-step tutorial.
- Installation Guide - Learn about optional dependencies,
uv, and verification. - Migrating from xsdata - Seamlessly migrate existing codebases to pyxsdata and native Pydantic v2.
- Code Generator Guide - Explore CLI options, configurations, and docstring styles.
- Data Binding Guide - Learn XML/JSON parsing, serialization, and tree manipulation.
- Parser Backends - Compare performance between standard
library,
lxml,pugixml, and RustPolyXML. - Pydantic v2 Integration - Deep dive into native Pydantic v2 models and JSON schema support.
- Frequently Asked Questions - Solutions to common questions, large file streaming, and web framework tips.
- Sample Projects - Real-world schemas and models in action.
- Changelog - Release notes and version history.