Skip to content

Modern XML & JSON Data Binding for Python 3.12+

CI Docs Coverage: 100% Ruff Astral ty uv License: MIT

PyPI Python 3.12+ Pydantic v2 Rust PolyXML PRs Welcome


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

$ pip install "pyxsdata[cli,pydantic,core]"

Installation Extras

  • cli: Command-line interface and code generator
  • pydantic: Native Pydantic v2 bindings and code generation
  • core: Native Rust PolyXML engine for ultra-fast throughput (~300k objs/s)
  • pugixml: C++ streaming pull parser for low latency
  • lxml: High-performance C-based XML parsing with DTD/XInclude support
  • 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 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 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