pyxsd compared with xmlschema¶
Choose pyxsd when you want a schema-defined Python object tree that you can
query, extend, transform, and export. Choose
xmlschema when lazy processing
or WSDL support is central to your application. Both validate XSD 1.0 and 1.1,
offer runtime bindings, and support common JSON formats for encoding and
decoding. pyxsd makes runtime class generation its primary model: the current
schema supplies extensible classes directly, with no generated binding module
to regenerate or drift out of sync.
This is an API and design comparison, not a performance benchmark. For validity-verdict evidence, XSTS methodology and results records the shared corpus, each engine’s checked denominator, and reviewed baselines. For pyxsd’s broader case, read Why pyxsd.
At a glance¶
pyxsd |
xmlschema |
|
|---|---|---|
XSD support |
1.1 default; explicit 1.0 mode ( |
1.0 and 1.1 ( |
Runtime dependency |
|
|
XML parser |
stdlib |
stdlib |
Primary model |
validate, bind to a schema-defined Python object tree, query, export, transform |
decode/encode XML↔Python/JSON, validate, inspect schema components |
Instance → Python |
|
Converters to nested |
Python/JSON → XML |
|
|
JSON Schema |
|
Converter-based Python/JSON contracts; consult its API for supported exports |
Binding source files |
None required; classes come directly from the compiled XSD; optional |
Runtime data bindings available; optional static generation with Jinja2 templates |
Application extensions |
Compile-time mixins with methods and validation hooks |
Custom converters and data-binding classes |
Pydantic / Arrow |
Optional schema-derived Pydantic models and Arrow/Parquet record projections |
Python/JSON conversion; no equivalent built-in adapters documented |
XPath/lookup |
|
XPath-based schema component API; |
Transform workflow |
Native XSLT 1.0/2.0/3.0, schema-aware 2.0/3.0, and Python callables; CLI and MCP entry points |
Custom converters and ordinary Python processing of decoded data |
Validation output |
|
Exception hierarchy, |
Lazy / incremental |
no |
|
Resource hardening |
opt-in parser profiles ( |
entity-forbidding parser, |
Remote schema download |
opt-in |
yes, with an offline cache |
WSDL |
no |
yes (WSDL 1.1) |
Where pyxsd helps¶
A schema-driven application model¶
pyxsd’s normal compile/parse path produces typed Python objects. XSD type derivation becomes class inheritance, simple values use XSD datatype classes, and mixins add application methods and validation hooks at compile time. Queries return the original bound nodes, so selection and application logic work on the same objects. See Mixin extensions and Data model.
This is an advantage of the runtime model, not a reduction in what the application objects can do. Generated binding source adds an artifact that can drift from its XSD until someone regenerates it. pyxsd instead compiles the current schema into classes, while mixins keep application methods and validation hooks separate from the schema-derived structure. There are no generated class bodies to edit or preserve across regeneration.
Compile the XSD once and reuse the resulting schema across documents. When the schema changes, recompile it instead of regenerating and distributing binding modules. Optional Type stubs for generated binding classes describe those runtime classes for editors and type checkers without becoming a separate runtime implementation.
xmlschema also supports runtime-generated bindings through
DataBindingConverter, in addition to DataElementConverter and static
Jinja2 generation. The choice is therefore between binding APIs and
workflows, not between having Python objects and doing without them. Its
data bindings documentation describes that model.
Inspection and repair with explicit validation¶
pyxsd keeps recoverable findings on ValidationReport and lets the caller
choose where require_valid() should stop a pipeline. Stable issue codes,
phase tags, and optional indexed source locations support automated triage;
Document.locate() can connect a finding to its occurrence. Lax binding
retention keeps more data available for repair without suppressing findings
under the same validation settings. See Validation and Parse modes and binding policies.
xmlschema also collects errors through iter_errors() and lax validation.
pyxsd’s benefit is the report attached to the bound document and the
separation between data retention and error policy, not an exclusive ability
to report multiple errors. In both libraries, fatal input failures can
prevent a usable result.
A direct route to application output¶
Use to_dict() / to_data() / to_json() for structured extraction, or apply a Python
callable through Document.transform(). The CLI can invoke the same
transform classes. After changing a tree, revalidate() produces a fresh
document and report before writing. See Using transforms.
The optional Optional Pydantic and Arrow integrations derive Pydantic models and Arrow record schemas from XSD before any instance XML exists. This suits applications that need a declared data contract or typed Parquet output rather than a sample-inferred mapping. The projections have their own supported-shape limits and do not replace full XML validation.
Document data contracts¶
Both libraries encode and decode Parker, BadgerFish,
and JsonML. pyxsd also supports native pyxsd and schema-driven
pyxsd-json, and generates Draft 2020-12 JSON Schema for all five formats.
Shared format names do not guarantee identical JSON; see Data conversion
for examples, interoperability differences, and validation limits.
Where xmlschema is a better fit¶
Lazy and incremental processing.
XMLResourcewithlazy/thin_lazysupports large documents and streaming, which pyxsd does not.Resource controls and hardening.
xmlschemaexposes a broader resource-policy layer (allow/defuse), timeouts, processing limits, and remote download with an offline cache. pyxsd has opt-in parser profiles,XmlLimits, and budgeted HTTPS schema retrieval, but no persistent cache, lxml parser injection, or general per-parse timeout. Its default parser is the stdlib parser; local-only loading does not confine filesystem access. See XML security and untrusted input before processing untrusted inputs.Generated source as a deliverable. Jinja2 generation suits projects that specifically need source modules to inspect or distribute. pyxsd instead builds its implementation classes at runtime and optionally emits typing stubs; it does not need static source to provide bindings.
WSDL 1.1 processing. pyxsd does not provide a WSDL API.
XPath over schema components.
xmlschemahas an XPath-based component API and global maps. pyxsd has declaration introspection, dependency traversal, and filtered stubs, but no public schema-component XPath API. See API reference for the available introspection surface.
Limitations of pyxsd¶
Namespace-correct documents are the default expectation. The default
ParseModes.NAMESPACEDpolicy rejects documents that only matched by local name;ParseModes.STRICT,ParseModes.LAX, and--namespaces legacyare the explicit compatibility choices.Grouped exports lose mixed-content positions. Interleaved text is kept verbatim in the bound tree (leading text in
_value_, child tails in_tail_) and survives serialization and XPath queries, but the dict export can only concatenate the character data under$. Usepyxsd-jsonor JsonML for ordered mixed export; the Arrow/Pydantic integrations reject mixed content.DTD-dependent checks have limited evidence.
ENTITY/ENTITIESchecks depend on available unparsed-entity declarations; external subsets are not fetched. See DTD evidence and input limitations. Parser profiles are separate and do not provide DTD validation; see XML security and untrusted input.One parse at a time per
Schema. The compiled schema holds per-parse indexes on a shared host, so concurrent parses against the sameSchemaare not supported.XML 1.1 documents are not fully supported (an expat limitation), though schema version mode 1.0/1.1 is.
Using them together¶
pyxsd uses xmlschema for conversion fixtures as described above, and in two distinct validation test roles:
Manifest differential oracle.
tests/test_oracle.py, enabled byPYXSD_RUN_ORACLE=1, compares the engines’ schema and available instance verdicts over the curated manifest. It selectsXMLSchema11only for cases markedxsd11; other cases use the XSD 1.0 class. Documented case-specific divergences are skipped, while unexpected exceptions are harness failures, not agreement.Full-XSTS comparison engine.
tests/report_xsts.py --engine bothscores each engine independently against the pinned main-suite expectations and selected profile, retaining its adapter gaps and other non-verdict outcomes. The XSD 1.1 baseline records both engines; the XSD 1.0 baseline currently records pyxsd only.PYXSD_RUN_ORACLEdoes not select this runner’s engines.
Neither role makes xmlschema normative truth. A disagreement prompts specification-based adjudication; it does not prove that either engine or the corpus is wrong. The required XSTS PR gate checks the recorded baseline, not pairwise agreement. See Two distinct xmlschema roles for the populations, skips, scoring rules, and reproduction commands.
See also¶
Supported features — pyxsd’s feature inventory and known gaps.
XSTS methodology and results — verdict-agreement methodology, provenance, and results.
XML and XSD validation — XML/XSD versions and validation terminology.
pyxsd compared with libxml2 — C-engine scope and preliminary XSD 1.0 evidence.
pyxsd compared with lxml — general XML/HTML tree APIs and objectify bindings.
Data model — the bound tree,
to_dict/to_json, and the projection used byxpath/find.xmlschema documentation — the authoritative description of the features attributed to it above.