Metadata-Version: 2.5
Name: pyxsd
Version: 1.3.1
Summary: Schema-guided XML-to-Python object mapping with a transform pipeline
Project-URL: Homepage, https://github.com/knorby/pyxsd
Project-URL: Repository, https://github.com/knorby/pyxsd
Project-URL: Documentation, https://pyxsd.knorby.com/
Project-URL: Issues, https://github.com/knorby/pyxsd/issues
Project-URL: Changelog, https://github.com/knorby/pyxsd/blob/develop/CHANGELOG.md
Author-email: Kali Norby <kali.norby@gmail.com>
Maintainer-email: Kali Norby <kali.norby@gmail.com>
License-Expression: BSD-3-Clause
License-File: LICENSE
Keywords: parser,schema,transform,validation,xml,xsd
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Programming Language :: Python :: 3.15
Classifier: Topic :: Text Processing :: Markup :: XML
Requires-Python: >=3.11
Requires-Dist: defusedxml<1,>=0.7.1
Requires-Dist: elementpath<6,>=4.7
Provides-Extra: arrow
Requires-Dist: pyarrow>=22; extra == 'arrow'
Provides-Extra: mcp
Requires-Dist: anyio<5,>=4.10; extra == 'mcp'
Requires-Dist: mcp<3,>=2.3; extra == 'mcp'
Requires-Dist: pydantic<3,>=2.12.5; extra == 'mcp'
Provides-Extra: mcp-all
Requires-Dist: anyio<5,>=4.10; extra == 'mcp-all'
Requires-Dist: mcp<3,>=2.3; extra == 'mcp-all'
Requires-Dist: pyarrow>=22; extra == 'mcp-all'
Requires-Dist: pydantic<3,>=2.12.5; extra == 'mcp-all'
Provides-Extra: pydantic
Requires-Dist: pydantic<3,>=2.12.5; extra == 'pydantic'
Description-Content-Type: text/markdown

# pyxsd

<!-- mcp-name: io.github.knorby/pyxsd -->

[![CI](https://github.com/knorby/pyxsd/actions/workflows/ci.yml/badge.svg)](https://github.com/knorby/pyxsd/actions/workflows/ci.yml)
[![codecov](https://codecov.io/gh/knorby/pyxsd/branch/develop/graph/badge.svg)](https://codecov.io/gh/knorby/pyxsd)
[![PyPI](https://img.shields.io/pypi/v/pyxsd)](https://pypi.org/project/pyxsd/)
[![Docs](https://img.shields.io/badge/docs-pyxsd.knorby.com-blue)](https://pyxsd.knorby.com/)
[![License](https://img.shields.io/badge/license-BSD--3--Clause-blue)](LICENSE)

pyxsd compiles XML Schema (XSD) into Python classes, then validates and binds
XML documents into typed object trees. It combines structured validation
reports, XPath and ElementTree queries, user-defined transforms, and XML
serialization, with optional Pydantic and Arrow/Parquet integrations. Use it
when you need schema-driven validation and XML processing, not just an XML
parser: compile a schema once, then inspect, transform, or export many documents.

## Install

Requires Python 3.11 or newer:

```sh
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 when the server should also project records through
Arrow; transformation execution remains disabled by default.

```json
{
  "mcpServers": {
    "pyxsd": {
      "command": "uvx",
      "args": ["--from", "pyxsd[mcp]", "pyxsd-mcp"]
    }
  }
}
```

For the bundled agent skills:

```sh
npx skills add knorby/pyxsd
```

See [MCP setup](https://pyxsd.knorby.com/mcp.html) for storage and trust
options and [agent skills](https://pyxsd.knorby.com/skills.html) for other
clients. MCP transformation execution is disabled by default.

## Quickstart

This example runs without any files or downloads:

```python
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](https://pyxsd.knorby.com/quickstart.html) supplies a complete
file-based example with queries, edits, and fresh validation. The same install
also provides a CLI:

```sh
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](https://pyxsd.knorby.com/validation.html): inspect
  issue codes, phases, and exact source occurrences.
- [Query and edit documents](https://pyxsd.knorby.com/quickstart.html#query-the-document):
  use XPath or ElementTree paths, export dictionaries/JSON, and revalidate edits.
- [Write transforms](https://pyxsd.knorby.com/transforms/writing.html): apply
  Python functions or reusable transform classes to the bound tree.
- [Process multiple documents](https://pyxsd.knorby.com/batch.html): reuse a
  compiled schema sequentially and choose whether to stop or report failures.
- [Connect Pydantic and Arrow](https://pyxsd.knorby.com/integrations.html):
  generate access models or schema-derived tables and Parquet with optional extras.
- [Use MCP tools](https://pyxsd.knorby.com/mcp.html): explore schemas and inspect
  XML diagnostics through a local stdio server. Transform execution is disabled
  by default; trusted-local previews require explicit opt-in.

For runnable applications, browse the [examples](examples/README.md): 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. Namespace-aware binding
is opt-in (`ParseModes.NAMESPACED` or `--namespaces strict`); the default matches
local names for compatibility. See [binding modes](https://pyxsd.knorby.com/binding.html),
[supported features and gaps](https://pyxsd.knorby.com/supported.html), and
[W3C test-suite results](https://pyxsd.knorby.com/xsts.html) 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](https://pyxsd.knorby.com/data-model.html) for access and export limits.
For untrusted input, configure parser protections and resource limits as
described in [XML security](https://pyxsd.knorby.com/xml-security.html).

## Documentation and contributing

[Full documentation](https://pyxsd.knorby.com/) ·
[Python API](https://pyxsd.knorby.com/api.html) ·
[CLI reference](https://pyxsd.knorby.com/cli.html) ·
[Contributing](https://pyxsd.knorby.com/contributing.html) ·
[Changelog](CHANGELOG.md)

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](https://pyxsd.knorby.com/history/origins.html).

## License

BSD 3-Clause. [LICENSE](LICENSE) includes the original ORNL provenance note.
