pyxsd
XML schema processing in Python: XSD and RELAX NG bindings, Schematron validation, and schema-aware XSLT.
pyxsd compiles and inspects XSD and RELAX NG schemas, validates XML, and binds
documents to Python objects without generated source files. XSD compilation
builds runtime classes from the schema's type hierarchy. The same XSD type
model connects validation and binding to XPath, xsl:import-schema, and
schema-aware XSLT 2.0/3.0. Schematron adds rule-based validation with native
reports and SVRL; XSLT 1.0/2.0/3.0 and Python callables transform documents.
Compile once, then query, edit, revalidate, or export many documents.
The document APIs also import and export five XML/JSON conventions, load XML without a schema, and retain native JSON numbers without precision loss. Optional Pydantic and Arrow/Parquet adapters project the schema model into application models and analytical records.
Install
Requires Python 3.11 or newer:
pip install pyxsd
For the MCP server, pip install 'pyxsd[mcp]' provides the pyxsd-mcp
command, or configure your client to launch the server with uvx. Install
pyxsd[mcp-all] instead for Pydantic, Arrow, and JSON Schema integrations.
Native XML/JSON processing needs no integration extra. Trusted-local Python
transformation execution remains disabled by default; clean XSLT previews still run.
{
"mcpServers": {
"pyxsd": {
"command": "uvx",
"args": ["--from", "pyxsd[mcp]", "pyxsd-mcp"]
}
}
}
For the bundled agent skills:
npx skills add knorby/pyxsd
See MCP setup for storage and trust options and agent skills for other clients. MCP Python transformation execution is disabled by default; clean XSLT previews still run.
Quickstart
This example runs without any files or downloads:
from io import StringIO
from pyxsd import Schema
schema = Schema.compile(
StringIO("""
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="quantity" type="xs:positiveInteger"/>
</xs:schema>
""")
)
schema.require_valid()
document = schema.parse(StringIO("<quantity>42</quantity>"))
document.require_valid()
print(document.to_dict()["$"]) # 42
Compilation generates Python classes at runtime; no separate code-generation
step is needed. Parsing records recoverable validation errors rather than
raising them automatically. require_valid() raises ValidationError when
the report contains errors.
The quickstart supplies a complete file-based example with queries, edits, and fresh validation. The same install also provides a CLI:
pyxsd -i inventory.xml -s inventory.xsd --namespaces strict --strict
Use that command with your own files or the quickstart's fixtures. --strict
makes validation errors fail the command; a bare run does not write XML.
Work with your data
- Validate and diagnose XML: inspect issue codes, phases, and exact source occurrences.
- Validate RELAX NG schemas: compile XML or compact-syntax grammars and reuse the validation and export workflows.
- Validate Schematron rules: compile
standalone ISO/IEC 19757-3:2025 schemas with
pyxsd.schematronorpyxsd schematron, or validate captured inputs withpyxsd_schematron_validateandpyxsd_schematron_validate_documents. Completed validations produce native reports, SVRL, or JSON. - Run schema-aware XSLT: compile XSLT
1.0/2.0/3.0 stylesheets, use XSD types and
xsl:import-schema, validate XSD/RELAX NG sources and targets, and usepyxsd.xslt,pyxsd xslt, orpyxsd_preview_transformwithkind: xsltin clean MCP workers. - Query and edit documents: use XPath or ElementTree paths, export dictionaries/JSON, and revalidate edits.
- Convert JSON data: import and
export Parker, BadgerFish, JsonML, native
pyxsd, andpyxsd-jsonformats, and generate JSON Schema.pyxsd-jsonuses the schema for value types and tags ambiguous alternatives. - Work without an XML schema: edit lexical XML trees, work with native JSON, and project JSON into XML using explicit mappings or JSON Schema/OpenAPI guidance.
- Write transforms: apply Python functions or reusable transform classes to the bound tree.
- Process multiple documents: reuse a compiled schema sequentially and choose whether to stop or report failures.
- Connect Pydantic and Arrow: generate access models or schema-derived tables and Parquet with optional extras.
- Use MCP tools: explore schemas and inspect XML diagnostics through a local stdio server. Trusted-local Python transform execution is disabled by default; clean XSLT previews still run, and trusted-local previews require explicit opt-in.
For runnable applications, browse the examples: GPX statistics, document and diagram rendering, healthcare conversion and diagnosis, and analytical workflows. Each family documents its inputs and setup.
Scope and limits
pyxsd supports XSD 1.1 with an optional XSD 1.0 mode, native RELAX NG 1.0,
standalone ISO/IEC 19757-3:2025 Schematron for the XSLT query bindings, and
Python-native XSLT 1.0/2.0/3.0 with schema-aware XSLT 2.0 and 3.0 profiles.
The XSLT capability matrix identifies the measured profiles and selected-case
results; streaming is outside the declared profiles. Schematron support is
standalone and evidence-backed for the documented XSLT query-binding profiles;
it does not claim ISO certification or add a format to generic MCP validation.
Namespace-aware binding is the default (ParseModes.NAMESPACED and CLI
--namespaces strict). Pass ParseModes.STRICT, ParseModes.LAX, or
--namespaces legacy explicitly when a document needs the historical
local-name matching. See
binding modes,
supported features and gaps, and
W3C test-suite results before choosing
it for a particular schema.
Parsing materializes the XML tree. Validation does not repair invalid input, and the Python object tree is not a lossless source representation. Read the data model for access and export limits. For untrusted input, configure parser protections and resource limits as described in XML security.
Documentation and contributing
Full documentation · Python API · CLI reference · Contributing · Changelog
The documentation site follows develop and may describe unreleased behavior.
For release-specific sources, select the matching tag in this repository.
pyxsd began at Oak Ridge National Laboratory in 2006 and was revived for Python 3 in 2026. See the project history.
License
BSD 3-Clause. LICENSE includes the original ORNL provenance note.
Metadata
Release files for pyxsd 1.5.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pyxsd-1.5.0.tar.gz | 5.1 MB | With provenance | Details for pyxsd-1.5.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pyxsd-1.5.0-py3-none-any.whl | Python 3 | none | any | Details for pyxsd-1.5.0-py3-none-any.whl |
Total release size: 7.0 MB
Release files / pyxsd-1.5.0.tar.gz
| Download URL | pyxsd-1.5.0.tar.gz |
|---|---|
| Size | 5.1 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
594c33ceb287ec36dac8f7bfde8b5ff88970ca7dc4ef561041e409fa6402a862
|
|
BLAKE2b-256 checksum How to use checksums |
0a60466443c2e2ceb6f08141e84e7dabd604392a3613c2a055ece9790c22199b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 5, 2026.
Transparency logRelease files / pyxsd-1.5.0-py3-none-any.whl
| Download URL | pyxsd-1.5.0-py3-none-any.whl |
|---|---|
| Size | 1.9 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d90ef51b1d47c4df73f25af8fdfc8ed578f5352a5b76bd64dd69fc42bf0e7e51
|
|
BLAKE2b-256 checksum How to use checksums |
03e51af51c65184f94de286a900e1e959387add13f0b1bbe4038246a7a05c639
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 5, 2026.
Transparency logSecurity for pyxsd 1.5.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for pyxsd-1.5.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 5, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.