Skip to content

Modern XML & JSON Data Binding for Python 3.12+

CI Tests Documentation Coverage PyPI version Python versions


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 ultra-fast C++ pugixml pull-parsing support, leverages modern PEP 695 generics, and is built with modern tooling (uv, ty, and ruff).


⚡ Quick Start

$ pip install "pyxsdata[cli,lxml,soap,pydantic]"

Installation Extras

  • cli: Command-line interface and code generator
  • pydantic: Native Pydantic v2 bindings and code generation
  • lxml: High-performance C-based XML parsing
  • soap: SOAP client webservice transport

Generate Python dataclasses or Pydantic models from any schema:

# Generate standard dataclasses
$ pyxsdata generate schema.xsd --package myapp.models

# Or generate native Pydantic v2 models
$ pyxsdata generate schema.xsd --output pydantic --package myapp.models

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 54% faster XML deserialization (over 2x throughput) than legacy xsdata through 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 ty with 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