pyxsd.schemaless

Schemaless XML and native JSON documents with explicit XML projection.

Optional JSON Schema and OpenAPI guidance loads only when requested, so the native XML, native JSON, and explicit mapping paths have no optional import.

Attributes

Exceptions

JsonLimitError

Native JSON input exceeded one of its structural or byte budgets.

JsonParseError

Malformed, ambiguous, or non-native JSON input or output.

JsonSchemaError

JSON Schema could not be compiled or evaluated for this document.

ScalarTypeError

The lexical value at an explicitly pinned location was rejected.

SchemalessParseError

Malformed XML with a report, exact location, and open expanded names.

XmlMappingError

A native JSON value cannot be projected with the supplied mapping.

Classes

SchemalessDocument

One XML parse with no schema binding.

JsonDocument

One native JSON value with an optional JSON Schema validation report.

JsonLimits

Optional budgets for one native JSON input.

MappingRule

One explicit override for an occurrence addressed by JSON Pointer.

XmlMapping

A root name plus per-pointer projection rules.

NodeMapping

Register Python mixins for XML element occurrences.

DocumentProfile

One immutable profile snapshot of a document's current revision.

PathProfile

Bounded evidence for one structural XML path or exact JSON pointer.

ProfileLimits

Optional budgets for one profile walk.

TypeCandidate

One ranked scalar type evaluated against every value at a path.

SchemalessElement

An editable XML element with no schema binding.

SchemalessRevision

One authoritative lexical revision with a replaceable immutable policy.

ScalarAdapter

Convert lexical strings to Python values and back.

TypePolicy

An immutable scalar mode and ordered set of explicit path or pointer pins.

Functions

from_data(value, *[, limits, types, json_schema, ...])

Copy host data into a new native JSON document.

from_json(source, *[, limits, types, json_schema, ...])

Decode JSON text, bytes, or a stream into a new native JSON document.

attribute(name, *[, type])

Declare one expanded-name attribute field.

child(name)

Declare one child element field by expanded name.

children(name)

Declare all child elements with one expanded name as a tuple.

text(*[, type, default])

Declare the element's leading character data as a scalar field.

parse_xml(source, *[, xml_policy, xml_limits, types, ...])

Read XML from a path, bytes, stream, or caller-built element.

Package Contents

class pyxsd.schemaless.SchemalessDocument(root, source, report, *, source_index=None, capture_source=None, report_current=True, xml_policy=None, xml_limits=None, _xdm_baseline=None, _node_mapping=None)

One XML parse with no schema binding.

root is the editable lexical tree, report is the parse’s report (never a validation verdict), source is the recorded source name, and source_index is the byte index for that source (None for a caller-built tree). report_current is true only while the report still describes the tree: a lexical edit or a transform wrapper makes it stale.

Parameters:
root: pyxsd.schemaless.tree.SchemalessElement
source_index = None
property report_current: bool

Whether the report still describes the current lexical revision.

A successful edit dirties the revision, and a transform wrapper deliberately keeps the old report snapshot, so both report stale until the document is parsed again.

Return type:

bool

test_type(path, type_ref)

Report every matching occurrence that rejects the proposed type.

Parameters:
  • path (str)

  • type_ref (pyxsd.schemaless.types.TypeRef)

Return type:

pyxsd.validation.ValidationReport

pin_type(path, type_ref)

Install a pin even when some matching values reject the type.

Invalid selectors and unknown types or paths are reported but not installed. Successful installation changes neither lexical data nor XDM.

Parameters:
  • path (str)

  • type_ref (pyxsd.schemaless.types.TypeRef)

Return type:

pyxsd.validation.ValidationReport

to_xdm()

Return the cached, untyped XDM view of this unedited revision.

A parsed XML source retains its comments, processing instructions and spans. A caller-built tree instead supplies its XML lexical projection. After an edit, use revalidate() to obtain a fresh document.

Return type:

pyxsd.xdm.nodes.XdmDocument

revalidate()

Refresh the current lexical XML in a new document, without a schema.

The new parse has its own report, source index, lexical revision and XDM view. Comments and processing instructions omitted by the editable tree do not survive this round trip. Mixin selectors use the paths and lexical values of the new tree.

Return type:

SchemalessDocument

to_dict(*, typed=True, always_list=False)

Returns the lexical tree as a plain dict.

typed=True applies the scalar policy to leaves and attributes. typed=False exports the lexical strings.

Parameters:
Return type:

dict

to_data(*, format='pyxsd', fidelity='best-effort', typed=True, always_list=False)

Returns the lexical tree under the native pyxsd data contract.

The schema-directed formats need a compiled schema to choose a layout, so a schemaless document rejects them explicitly. typed, always_list, and fidelity keep their native meanings.

Parameters:
  • format (pyxsd.data_conversion.contracts.FormatName)

  • fidelity (pyxsd.data_conversion.contracts.Fidelity)

  • typed (bool)

  • always_list (bool)

Return type:

pyxsd.data_conversion.contracts.JsonValue

profile(limits=None)

Walk the current lexical revision into an immutable profile.

XML rows group occurrences by expanded-name path without same-name occurrence indexes and report attributes separately. Candidate evaluation is evidence only: it never installs a pin, edits lexical data, or adds XDM annotations, and a failing pin still profiles without raising. revision_id and revision_dirty record the source revision at snapshot time.

Parameters:

limits (pyxsd.schemaless.profile.ProfileLimits | None)

Return type:

pyxsd.schemaless.profile.DocumentProfile

write(dest)

Writes the lexical tree to dest (a path or a file object).

Parameters:

dest (str | pathlib.Path | os.PathLike[str] | IO[str])

Return type:

None

to_string()

Returns the lexical tree serialized as compact XML text.

Return type:

str

exception pyxsd.schemaless.JsonLimitError

Native JSON input exceeded one of its structural or byte budgets.

exception pyxsd.schemaless.JsonParseError(message, *, line=None, column=None, position=None)

Malformed, ambiguous, or non-native JSON input or output.

line, column, and position carry the decoder’s one-based text position and zero-based character offset when the failure came from JSON text; value-model failures (duplicate keys, non-finite numbers, unsupported host objects) leave them None.

Parameters:
  • message (str)

  • line (int | None)

  • column (int | None)

  • position (int | None)

line = None
column = None
position = None
exception pyxsd.schemaless.JsonSchemaError

JSON Schema could not be compiled or evaluated for this document.

exception pyxsd.schemaless.ScalarTypeError(message, *, location)

The lexical value at an explicitly pinned location was rejected.

Parameters:
location
exception pyxsd.schemaless.SchemalessParseError(message, *, location, open_elements)

Malformed XML with a report, exact location, and open expanded names.

Parameters:
location
open_elements
report
exception pyxsd.schemaless.XmlMappingError(report)

A native JSON value cannot be projected with the supplied mapping.

report carries the structured diagnostics: each issue names the JSON Pointer, the projected XML path, and any other evidence needed to repair the mapping. Projection stops at the first fatal issue, so a failed projection never returns a partial document.

Parameters:

report (pyxsd.validation.ValidationReport)

report
class pyxsd.schemaless.JsonDocument(value, *, source='<memory>', types=None)

One native JSON value with an optional JSON Schema validation report.

source is the recorded input name ("<memory>" for anonymous text, bytes, streams, and host data), report is the document’s report, and is_valid is false once that report records an error. A schema-invalid instance still supports native reads and XDM conversion. types is the immutable scalar policy; the default is native(), and pin_type() replaces it for this document only.

Parameters:
source: str
property report: pyxsd.validation.ValidationReport

The document’s report, empty when built without JSON Schema guidance.

Return type:

pyxsd.validation.ValidationReport

property is_valid: bool

Whether the report holds no error-severity issues.

Return type:

bool

property types: pyxsd.schemaless.types.TypePolicy

The document’s immutable scalar policy.

Return type:

pyxsd.schemaless.types.TypePolicy

require_valid()

Raise pyxsd.ValidationError if the report has errors.

Return type:

None

value_at(pointer: str, typed: Literal[False] = False) → pyxsd.schemaless.json_values.NativeJsonValue
value_at(pointer: str, typed: bool) → Any

Return the value addressed by an RFC 6901 JSON Pointer.

The empty pointer addresses the root. Scalars from the native model are immutable and returned directly; objects and arrays are deep-copied so the caller cannot mutate authoritative storage.

typed=True returns an independent view whose scalar leaves follow the document’s policy. Objects stay mappings, arrays stay lists, null stays None, and map keys are never interpreted. A scalar that the policy cannot parse raises ScalarTypeError with the failing pointer; the native value itself remains unchanged.

to_data()

Return a deep copy of the native value.

Parsed integral numbers remain int, other parsed numbers remain Decimal, and a float remains a float only when host data supplied one. No number passes through float merely to be copied. The type policy affects only value_at() and to_xdm().

Return type:

pyxsd.schemaless.json_values.NativeJsonValue

to_json(indent=None)

Serialize the native value as JSON text.

None emits compact containers. An integer supplies spaces and a string supplies JSON whitespace for one level of indentation. A non-whitespace indent raises JsonParseError. A type policy never changes the exact native scalar spellings.

Parameters:

indent (int | str | None)

Return type:

str

to_xml(mapping, *, node_mapping=None)

Project this native value into a fresh XML document.

mapping names the root element and may rename occurrences by RFC 6901 JSON Pointer. Element-first projection turns object properties and array members into elements, strings into escaped character data, numbers and booleans into JSON-compatible lexical text, and null into xsi:nil="true". The source value is never changed and edits to the derived XML do not write back.

The result has no source bytes or source index. Its report is current and holds non-fatal warnings for information the XML shape cannot retain. Invalid names, unusable expanded namespace names, and string characters XML 1.0 cannot represent raise XmlMappingError instead of being repaired, escaped around, or dropped. Object member keys are always validated as local names; only explicit mapping names may be expanded. JSON Pointer pins stay on this document: the projected tree starts from a lexical policy.

A schema-backed mapping requires a valid instance for its own schema. If validation fails, XmlMappingError.report contains the JSON Schema diagnostics. Other mappings do not require schema validation.

Pass node_mapping to add Python mixins to matching projected occurrences; descriptor type= entries become occurrence pins on the derived document’s policy, just as they do for parse_xml().

Parameters:
Return type:

pyxsd.schemaless.document.SchemalessDocument

to_xdm()

Return this document’s native value as an XDM 3.1 sequence.

Objects become maps with xs:string keys, arrays become arrays whose members keep their nesting, and null becomes the empty sequence. A scalar uses an explicit pointer pin, unambiguous schema guidance, conservative string inference, or its exact native atomic kind, in that order. An invalid instance uses only pins and native kinds. A pin that rejects its value raises ScalarTypeError with the pointer. Nothing is wrapped in an XML document.

Return type:

pyxsd.xdm.values.XdmSequence

profile(limits=None)

Return a bounded, immutable profile of the current native value.

Rows use exact RFC 6901 pointers: one "value" row for every address and one additional "array-items" row at each array’s pointer for aggregate member evidence. Scalar candidates are evaluated as evidence only: the profile never changes the native value, the scalar policy, or any later XDM interpretation. A native document has no revision counter, so the snapshot records revision_id=None and revision_dirty=False.

Parameters:

limits (pyxsd.schemaless.profile.ProfileLimits | None)

Return type:

pyxsd.schemaless.profile.DocumentProfile

test_type(pointer, type_ref)

Report whether the JSON scalar at pointer accepts a proposed type.

Testing never installs a pin. A malformed or absent pointer, a non-scalar value, and an unknown type each report one error and leave the policy unchanged. A scalar that rejects the type also leaves the policy unchanged.

Parameters:
  • pointer (str)

  • type_ref (pyxsd.schemaless.types.TypeRef)

Return type:

pyxsd.validation.ValidationReport

pin_type(pointer, type_ref)

Install a pointer pin even when the current value rejects the type.

A malformed or absent pointer, a non-scalar value, and an unknown type report an error without changing the policy. A scalar that rejects the type still receives the pin, so later typed reads and XDM conversion raise ScalarTypeError. Installing a pin changes neither native storage nor the JSON spelling.

Parameters:
  • pointer (str)

  • type_ref (pyxsd.schemaless.types.TypeRef)

Return type:

pyxsd.validation.ValidationReport

pyxsd.schemaless.from_data(value, *, limits=None, types=None, json_schema=None, base_uri=None, reference_registry=None, resource_policy=None, format_assertion=False, format_typing=False)

Copy host data into a new native JSON document.

Mappings with string keys, lists, tuples, strings, booleans, integers, finite floats and Decimal values, and None are accepted. Tuples become lists, and the input is copied so later changes to value cannot affect the document. Values outside the native model raise JsonParseError; structural budgets raise JsonLimitError.

types is the document’s scalar policy for typed reads and XDM conversion; the default is native(), which preserves every native scalar kind. For the optional schema arguments, see from_json().

Parameters:
Return type:

JsonDocument

pyxsd.schemaless.from_json(source, *, limits=None, types=None, json_schema=None, base_uri=None, reference_registry=None, resource_policy=None, format_assertion=False, format_typing=False)

Decode JSON text, bytes, or a stream into a new native JSON document.

Integral number tokens become int and other number tokens become Decimal; no number passes through float. Malformed text, duplicate object keys, non-standard numeric constants, and non-UTF-8 bytes raise JsonParseError named for the source: a named stream keeps its name and every anonymous source is "<memory>". An exceeded structural budget raises JsonLimitError.

types is the document’s scalar policy for typed reads and XDM conversion; the default is native(), which preserves every native scalar kind. Parsed JSON text never changes because of it.

json_schema accepts a Draft 2020-12 boolean, mapping, or strict JSON text. Relative references use the schema’s base_uri, not the instance source. External resources must be registered in reference_registry or authorized and read by resource_policy. Format is an annotation unless format_assertion is true. Assertion uses deterministic checks for date, date-time, and time plus uuid, ipv4, ipv6, json-pointer, regex, int32, int64, float, double, and byte; regex follows Python re syntax, and unlisted formats depend on the installed jsonschema environment. Invalid schemas or unresolved references raise JsonSchemaError; instance failures are recorded in the document’s report.

format_typing independently enables supported format and content encoding annotations for typed reads and XDM conversion of valid instances. uuid, ipv4, and ipv6 return standard-library values with canonical xs:string XDM; int32, int64, float, double, and byte or contentEncoding: base64 reuse their XSD SimpleTypes. It never changes validation, native storage, or JSON output, and unsupported or rejected values keep their native interpretation.

Parameters:
Return type:

JsonDocument

class pyxsd.schemaless.JsonLimits

Optional budgets for one native JSON input.

Every structural bound is inclusive and positive: max_bytes counts the input bytes as supplied (UTF-8 bytes for text, including a leading BOM), max_depth counts nesting with the root at depth one, and max_values counts every value (containers and scalars) but not object member names. max_diagnostics is a non-negative retention budget for diagnostics that later JSON Schema evaluation may attach to the document. None leaves that budget unset.

max_bytes: int | None = None
max_depth: int | None = None
max_values: int | None = None
max_diagnostics: int | None = None
type pyxsd.schemaless.NativeJsonValue = bool | int | float | Decimal | str | list['NativeJsonValue'] | dict[str, 'NativeJsonValue'] | None
class pyxsd.schemaless.MappingRule

One explicit override for an occurrence addressed by JSON Pointer.

kind overrides the default node kind. none inlines container children and drops scalar values with a warning. name and item_name are local or Clark names; keys used as names must be local. namespace qualifies a local name; prefix supplies a lexical binding.

Arrays wrap by default. Unwrapped arrays repeat the occurrence name unless item_name supplies a separate name. order lists object keys to emit first. By default null emits xsi:nil for elements and is omitted with a warning for attributes and text. type formats a scalar’s lexical value without annotating the XML or changing the JSON.

name: str | None = None
kind: str | None = None
namespace: str | None = None
prefix: str | None = None
array: str | None = None
item_name: str | None = None
null: str | None = None
type: pyxsd.schemaless.types.TypeRef | None = None
order: collections.abc.Sequence[str] | None = None
class pyxsd.schemaless.XmlMapping(root_name, *, default='elements', rules=None)

A root name plus per-pointer projection rules.

rules maps RFC 6901 JSON Pointers to MappingRule values. A pointer that does not occur in a particular document is simply policy for a possible occurrence; it is not an error, so mapping factories can describe optional schema properties. Use compact() to opt into scalar attributes. Rules are checked when their occurrences are projected, because only then are their XML paths known.

Parameters:
property root_name: str | None

The static root name, or None when OpenAPI selects it per instance.

Return type:

str | None

property default: str

"elements" or "compact".

Type:

The projection policy

Return type:

str

property rules: collections.abc.Mapping[str, MappingRule]

An immutable view of the JSON Pointer to rule policy.

Return type:

collections.abc.Mapping[str, MappingRule]

classmethod elements(root_name, *, rules=None)

Return the conservative element-first mapping for root_name.

Parameters:
Return type:

XmlMapping

classmethod compact(root_name, *, rules=None)

Map scalar object properties to attributes unless overridden.

Parameters:
Return type:

XmlMapping

classmethod from_json_schema(schema, *, root_name, rules=None, base_uri=None, reference_registry=None, resource_policy=None, format_assertion=False, format_typing=False)

Compile Draft 2020-12 guidance for an element-first projection.

The schema must validate the instance at projection time. format_assertion checks recognized formats during validation; format_typing independently formats compatible values through the mapped XSD SimpleTypes or canonical UUID and IP text. Explicit rules take precedence, rejected values keep the native spelling, and schema defaults are not applied.

Parameters:
Return type:

XmlMapping

classmethod from_openapi(schema_object, *, root_name=None, rules=None, base_uri=None, reference_registry=None, resource_policy=None, dialect=None, format_assertion=False, format_typing=False)

Compile an element-first mapping from an OpenAPI Schema Object.

XML Objects on applicable schemas supply node kinds, names, namespaces, and array wrapping. root_name overrides the annotation’s local name. If only an applicator supplies the root name, it is selected at projection time. Explicit rules override individual metadata fields. format_assertion checks recognized formats during validation; format_typing independently formats compatible values through the mapped XSD SimpleTypes unless an explicit rule provides a type, and rejected values keep the native spelling.

Parameters:
Return type:

XmlMapping

class pyxsd.schemaless.NodeMapping

Register Python mixins for XML element occurrences.

Each parse uses the current rules as a snapshot; later registrations do not change existing documents. Later matching rules take precedence, and a mixin matched more than once appears only at its highest priority. Descriptor type= entries compile into occurrence pins on the same document policy; a later pin_type() at that path replaces them for descriptor and ordinary reads alike.

register(mixin: None = None, *, path: str | None = None, predicate: _Predicate | None = None) → collections.abc.Callable[[_Mixin], _Mixin]
register(mixin: type, *, path: str | None = None, predicate: _Predicate | None = None) → None

Register a mixin directly or return a decorator for its class.

Supply exactly one selector. Paths start at the document root, use Clark names for namespaces, and can specify one-based same-name indexes. If any step is indexed, omitted indexes default to one. A predicate sees the unprojected lexical node and must not edit it. A descriptor type= requires a path selector because its pin has to name the occurrences it applies to.

pyxsd.schemaless.attribute(name, *, type=None)

Declare one expanded-name attribute field.

Reads call SchemalessElement.attribute_value and therefore follow the document’s effective scalar policy; a missing attribute reads as None. Writes format the value through that same adapter and replace only that attribute. name is an expanded (Clark) name, not a serialization prefix.

Parameters:
  • name (str)

  • type (pyxsd.schemaless.types.TypeRef | None)

Return type:

Any

pyxsd.schemaless.child(name)

Declare one child element field by expanded name.

The field reads None when no child has name. More than one matching child is ambiguous and raises ValueError, unless the generated mapped class keeps a children() view for that name declared by the same class as this singular field: the list view then makes the repetition explicit, and the singular field addresses its first element. An inherited pair from one declaring class stays lenient; a list view from another mixin, or one shadowed or replaced in the generated MRO, does not suppress the ambiguity. Navigation fields are read-only.

Parameters:

name (str)

Return type:

Any

pyxsd.schemaless.children(name)

Declare all child elements with one expanded name as a tuple.

Every read builds a new tuple from the current authoritative child sequence, so the result follows document order after any edit.

Parameters:

name (str)

Return type:

Any

pyxsd.schemaless.text(*, type=None, default=None)

Declare the element’s leading character data as a scalar field.

Reads call SchemalessElement.scalar_value for present leading text and return default when there is none. Mixed content stays mixed content: child tails are never concatenated into this value. Writes replace only the leading text.

Parameters:
  • type (pyxsd.schemaless.types.TypeRef | None)

  • default (Any)

Return type:

Any

pyxsd.schemaless.parse_xml(source, *, xml_policy=None, xml_limits=None, types=None, node_mapping=None)

Read XML from a path, bytes, stream, or caller-built element.

Parsed sources retain the same bytes for the source index and XDM capture. A caller-built tree has no original byte spans. Malformed XML raises SchemalessParseError; policy and budget errors propagate unchanged. By default scalar reads are lexical; pass types to change interpretation. Pass node_mapping to add Python mixins to matching lexical occurrences; descriptor type= entries merge beneath types into the document’s effective scalar policy as occurrence pins.

Parameters:
Return type:

pyxsd.schemaless.document.SchemalessDocument

class pyxsd.schemaless.DocumentProfile

One immutable profile snapshot of a document’s current revision.

revision_id is the XML revision identifier and revision_dirty its edited state at snapshot time; a native JSON document has no revision counter, so it records None and False. rows follows document order, and complete is false whenever a limit truncated evidence.

revision_id: int | None
revision_dirty: bool
complete: bool
rows: tuple[PathProfile, ...]
at(path, kind=None)

Return the row for path, preferring its own row over an aggregate.

kind selects one row when a path owns more than one, as a JSON array does with "value" and "array-items". Without kind the first row at the path wins, which is the exact address’s own row because an aggregate row always follows the row it aggregates.

Parameters:
  • path (str)

  • kind (str | None)

Return type:

PathProfile

class pyxsd.schemaless.PathProfile

Bounded evidence for one structural XML path or exact JSON pointer.

kind is "element" or "attribute" for XML, "value" for one exact JSON address, and "array-items" for the aggregate member evidence of a JSON array at that same pointer. An XML path spells expanded names without same-name occurrence indexes, exactly as a path-wide pin does. occurrences counts every value at the path; parents counts the containing occurrences (one document context for a root row) and min_occurs/max_occurs describe how many occurrences each parent holds; missing counts parents holding none. empties counts empty elements, empty attributes, empty strings, and empty JSON containers; nulls counts JSON nulls; mixed counts XML occurrences that mix character data with element children.

distinct_values and samples hold bounded lexical text in document order (samples may repeat), native_kinds holds the observed native JSON kinds, and candidates holds the ranked built-in scalar types followed by any extra schema-suggested types, with their pass/fail evidence. A row without scalar evidence reports zero candidate counts: an XML occurrence with element children contributes character data only through mixed, and a JSON array aggregate evaluates its scalar members while nulls and containers contribute only kinds and counts. Candidate counts always evaluate the whole lexical value; only the stored value lists are bounded. interpretations lists the distinct sources of the current interpretation in first-seen order.

path: str
kind: str
occurrences: int
parents: int
min_occurs: int
max_occurs: int
missing: int = 0
nulls: int = 0
empties: int = 0
mixed: int = 0
native_kinds: tuple[str, ...] = ()
distinct_values: tuple[str, ...] = ()
samples: tuple[str, ...] = ()
candidates: tuple[TypeCandidate, ...] = ()
interpretations: tuple[str, ...] = ()
truncated: bool = False
property candidate_names: tuple[str, ...]

The ranked candidate names in evaluation order.

Return type:

tuple[str, …]

candidate(name)

Return the candidate named name, or raise KeyError.

Parameters:

name (str)

Return type:

TypeCandidate

property interpretation: str

The source of the current interpretation, or "mixed".

A row whose occurrences are interpreted by different sources reports "mixed". An aggregate row with no scalar members has no source of its own and reports "native".

Return type:

str

class pyxsd.schemaless.ProfileLimits

Optional budgets for one profile walk.

Every bound is inclusive and positive. max_paths bounds the number of reported path rows, max_distinct the distinct-value list of each row, max_samples the sample list of each row, and max_value_bytes the UTF-8 length of each stored value. None leaves that budget unset, which profiles the whole source; supply a bound whenever the source is not trusted. Exceeding a budget during a walk marks the profile incomplete.

max_paths: int | None = None
max_distinct: int | None = None
max_samples: int | None = None
max_value_bytes: int | None = None
class pyxsd.schemaless.TypeCandidate

One ranked scalar type evaluated against every value at a path.

first_failure is the first rejecting occurrence in document order, in the same location family the document uses for diagnostics: an XML IssueLocation or a JSON DataLocation. from_schema_annotation is true when at least one applied JSON Schema annotation suggested the type.

name: str
passed: int
failed: int
first_failure: pyxsd.locations.IssueLocation | None = None
from_schema_annotation: bool = False
class pyxsd.schemaless.SchemalessElement

An editable XML element with no schema binding.

property revision: SchemalessRevision

The lexical revision and scalar policy that own this element.

Return type:

SchemalessRevision

class pyxsd.schemaless.SchemalessRevision

One authoritative lexical revision with a replaceable immutable policy.

property types: pyxsd.schemaless.types.TypePolicy

The current immutable scalar policy.

Return type:

pyxsd.schemaless.types.TypePolicy

scalar_value(node)
Parameters:

node (SchemalessElement)

Return type:

Any

attribute_value(node, expanded_name)
Parameters:
Return type:

Any

class pyxsd.schemaless.ScalarAdapter

Convert lexical strings to Python values and back.

The parse callback rejects invalid input with a ValueError, TypeError, or ArithmeticError. format takes a typed value and returns its lexical representation. An optional xdm callback can convert the value to an atomic item; otherwise its formatted string is used.

parse: collections.abc.Callable[[str], Any]
format: collections.abc.Callable[[Any], str]
xdm: collections.abc.Callable[[Any], pyxsd.xdm.values.XdmAtomic] | None = None
test(lexical)

Return whether this adapter accepts a lexical value.

Parameters:

lexical (str)

Return type:

bool

to_xdm(value)

Convert a typed value to an XDM atomic item.

Parameters:

value (Any)

Return type:

pyxsd.xdm.values.XdmAtomic

class pyxsd.schemaless.TypePolicy

An immutable scalar mode and ordered set of explicit path or pointer pins.

mode: Literal['lexical', 'native', 'infer']
pins: collections.abc.Mapping[str, ScalarAdapter]
classmethod lexical()

Keep XML scalars lexical unless they are pinned.

Return type:

TypePolicy

classmethod native()

Keep native scalar kinds unless they are pinned.

Return type:

TypePolicy

classmethod infer()

Conservatively interpret lexical scalars unless they are pinned.

Return type:

TypePolicy

static resolve(type_ref)

Resolve an XSD scalar name or a caller-supplied adapter.

Parameters:

type_ref (TypeRef)

Return type:

ScalarAdapter

with_pin(path, type_ref)

Return a new policy with the adapter pinned at path.

Parameters:
  • path (str)

  • type_ref (TypeRef)

Return type:

TypePolicy

json_adapter(pointer, value, *, asserted=None)

Resolve the adapter for one native JSON scalar at pointer.

Precedence is an explicit pointer pin, schema guidance from an evaluated schema, conservative inference of a string leaf, and then the native kind (no adapter). asserted is the document layer’s extension point for a schema that proves this occurrence’s type; inference never reinterprets a non-string native value.

Parameters:
Return type:

ScalarAdapter | None