pyxsd.integrations.pydantic

Generate standalone Pydantic models and typed snapshots of bound XML.

Install pyxsd[pydantic]. Models validate the projected data contract; whole-document XML validation remains Document.revalidate().

Classes

ModelSet

A compiled-schema-scoped registry of generated Pydantic models.

Functions

clean_field_schema(schema)

Remove the internal None placeholder from one field schema.

models(…)

Create a model registry without requiring instance XML.

Module Contents

pyxsd.integrations.pydantic.clean_field_schema(schema)

Remove the internal None placeholder from one field schema.

A missing optional non-nillable field has an internal None default in the model, but that is not a nullable input/default in the JSON Schema contract. XSD and RELAX NG schema hooks share this exact cleanup.

Parameters:

schema (dict[str, Any])

Return type:

None

class pyxsd.integrations.pydantic.ModelSet(schema)

A compiled-schema-scoped registry of generated Pydantic models.

Parameters:

schema (pyxsd.schema.Schema)

schema
model_for(*, element, path=())

Resolve a global declaration or an unambiguous local declaration path.

Parameters:
Return type:

type[pydantic.BaseModel]

from_document(document, *, revalidate=False)

Snapshot a bound document; request fresh XML validation explicitly.

Parameters:
Return type:

pydantic.BaseModel

from_node(node, *, element, path=())

Snapshot an occurrence matching the selected compiled declaration.

Parameters:
Return type:

pydantic.BaseModel

pyxsd.integrations.pydantic.models(schema: pyxsd.schema.Schema) → ModelSet
pyxsd.integrations.pydantic.models(schema: pyxsd.relaxng.schema.RelaxNGSchema) → pyxsd.relaxng.pydantic_adapter.RelaxNGModelSet

Create a model registry without requiring instance XML.

A compiled XSD schema still returns the existing ModelSet. A compiled RELAX NG schema returns its route registry; the RELAX NG adapter is imported lazily so XSD-only use never imports RELAX NG projection code.