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¶
Native JSON input exceeded one of its structural or byte budgets. |
|
Malformed, ambiguous, or non-native JSON input or output. |
|
JSON Schema could not be compiled or evaluated for this document. |
|
The lexical value at an explicitly pinned location was rejected. |
|
Malformed XML with a report, exact location, and open expanded names. |
|
A native JSON value cannot be projected with the supplied mapping. |
Classes¶
One XML parse with no schema binding. |
|
One native JSON value with an optional JSON Schema validation report. |
|
Optional budgets for one native JSON input. |
|
One explicit override for an occurrence addressed by JSON Pointer. |
|
A root name plus per-pointer projection rules. |
|
Register Python mixins for XML element occurrences. |
|
One immutable profile snapshot of a document's current revision. |
|
Bounded evidence for one structural XML path or exact JSON pointer. |
|
Optional budgets for one profile walk. |
|
One ranked scalar type evaluated against every value at a path. |
|
An editable XML element with no schema binding. |
|
One authoritative lexical revision with a replaceable immutable policy. |
|
Convert lexical strings to Python values and back. |
|
An immutable scalar mode and ordered set of explicit path or pointer pins. |
Functions¶
|
Copy host data into a new native JSON document. |
|
Decode JSON text, bytes, or a stream into a new native JSON document. |
|
Declare one expanded-name attribute field. |
|
Declare one child element field by expanded name. |
|
Declare all child elements with one expanded name as a tuple. |
|
Declare the element's leading character data as a scalar field. |
|
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.
rootis the editable lexical tree,reportis the parse’s report (never a validation verdict),sourceis the recorded source name, andsource_indexis the byte index for that source (Nonefor a caller-built tree).report_currentis true only while the report still describes the tree: a lexical edit or a transform wrapper makes it stale.- Parameters:
source (str | None)
report (pyxsd.validation.ValidationReport)
source_index (pyxsd.source_spans.SourceIndex | None)
capture_source (pyxsd.xdm.document.CaptureSource | None)
report_current (bool)
xml_policy (pyxsd.xml_policy.XmlParserPolicy | None)
xml_limits (pyxsd.xml_policy.XmlLimits | None)
_xdm_baseline (_BoundSnapshot | None)
_node_mapping (pyxsd.schemaless.nodes._CompiledNodeMapping | None)
- 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:
- 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:
- 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:
- 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:
- 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:
- to_dict(*, typed=True, always_list=False)¶
Returns the lexical tree as a plain dict.
typed=Trueapplies the scalar policy to leaves and attributes.typed=Falseexports the lexical strings.
- to_data(*, format='pyxsd', fidelity='best-effort', typed=True, always_list=False)¶
Returns the lexical tree under the native
pyxsddata contract.The schema-directed formats need a compiled schema to choose a layout, so a schemaless document rejects them explicitly.
typed,always_list, andfidelitykeep their native meanings.
- 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_idandrevision_dirtyrecord the source revision at snapshot time.- Parameters:
limits (pyxsd.schemaless.profile.ProfileLimits | None)
- Return type:
- 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
- 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, andpositioncarry 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 themNone.- 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:
message (str)
location (pyxsd.locations.IssueLocation)
- location¶
- exception pyxsd.schemaless.SchemalessParseError(message, *, location, open_elements)¶
Malformed XML with a report, exact location, and open expanded names.
- Parameters:
message (str)
location (pyxsd.locations.IssueLocation)
- location¶
- open_elements¶
- report¶
- exception pyxsd.schemaless.XmlMappingError(report)¶
A native JSON value cannot be projected with the supplied mapping.
reportcarries 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.
sourceis the recorded input name ("<memory>"for anonymous text, bytes, streams, and host data),reportis the document’s report, andis_validis false once that report records an error. A schema-invalid instance still supports native reads and XDM conversion.typesis the immutable scalar policy; the default isnative(), andpin_type()replaces it for this document only.- Parameters:
value (object)
source (str)
types (pyxsd.schemaless.types.TypePolicy | None)
- property report: pyxsd.validation.ValidationReport¶
The document’s report, empty when built without JSON Schema guidance.
- Return type:
- property types: pyxsd.schemaless.types.TypePolicy¶
The document’s immutable scalar policy.
- Return type:
- require_valid()¶
Raise
pyxsd.ValidationErrorif 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=Truereturns an independent view whose scalar leaves follow the document’s policy. Objects stay mappings, arrays stay lists, null staysNone, and map keys are never interpreted. A scalar that the policy cannot parse raisesScalarTypeErrorwith 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 remainDecimal, 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 onlyvalue_at()andto_xdm().- Return type:
- to_json(indent=None)¶
Serialize the native value as JSON text.
Noneemits compact containers. An integer supplies spaces and a string supplies JSON whitespace for one level of indentation. A non-whitespace indent raisesJsonParseError. A type policy never changes the exact native scalar spellings.
- 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
XmlMappingErrorinstead 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.reportcontains 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 forparse_xml().- Parameters:
mapping (pyxsd.schemaless.mapping.XmlMapping)
node_mapping (pyxsd.schemaless.nodes.NodeMapping | None)
- Return type:
- to_xdm()¶
Return this document’s native value as an XDM 3.1 sequence.
Objects become maps with
xs:stringkeys, 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 raisesScalarTypeErrorwith the pointer. Nothing is wrapped in an XML document.- Return type:
- 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 recordsrevision_id=Noneandrevision_dirty=False.- Parameters:
limits (pyxsd.schemaless.profile.ProfileLimits | None)
- Return type:
- 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:
- 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.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
Decimalvalues, andNoneare accepted. Tuples become lists, and the input is copied so later changes to value cannot affect the document. Values outside the native model raiseJsonParseError; structural budgets raiseJsonLimitError.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, seefrom_json().- Parameters:
value (object)
limits (pyxsd.schemaless.json_values.JsonLimits | None)
types (pyxsd.schemaless.types.TypePolicy | None)
json_schema (_JsonSchemaInput | None)
base_uri (str | None)
reference_registry (referencing.jsonschema.SchemaRegistry | None)
resource_policy (pyxsd.resource_policy.ResourcePolicy | None)
format_assertion (bool)
format_typing (bool)
- Return type:
- 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
intand other number tokens becomeDecimal; no number passes through float. Malformed text, duplicate object keys, non-standard numeric constants, and non-UTF-8 bytes raiseJsonParseErrornamed for the source: a named stream keeps itsnameand every anonymous source is"<memory>". An exceeded structural budget raisesJsonLimitError.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, andtimeplusuuid,ipv4,ipv6,json-pointer,regex,int32,int64,float,double, andbyte;regexfollows Pythonresyntax, and unlisted formats depend on the installedjsonschemaenvironment. Invalid schemas or unresolved references raiseJsonSchemaError; 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, andipv6return standard-library values with canonicalxs:stringXDM;int32,int64,float,double, andbyteorcontentEncoding: base64reuse their XSD SimpleTypes. It never changes validation, native storage, or JSON output, and unsupported or rejected values keep their native interpretation.- Parameters:
source (_JsonSource)
limits (pyxsd.schemaless.json_values.JsonLimits | None)
types (pyxsd.schemaless.types.TypePolicy | None)
json_schema (_JsonSchemaInput | None)
base_uri (str | None)
reference_registry (referencing.jsonschema.SchemaRegistry | None)
resource_policy (pyxsd.resource_policy.ResourcePolicy | None)
format_assertion (bool)
format_typing (bool)
- Return type:
- class pyxsd.schemaless.JsonLimits¶
Optional budgets for one native JSON input.
Every structural bound is inclusive and positive:
max_bytescounts the input bytes as supplied (UTF-8 bytes for text, including a leading BOM),max_depthcounts nesting with the root at depth one, andmax_valuescounts every value (containers and scalars) but not object member names.max_diagnosticsis a non-negative retention budget for diagnostics that later JSON Schema evaluation may attach to the document.Noneleaves that budget unset.
- 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.
kindoverrides the default node kind.noneinlines container children and drops scalar values with a warning.nameanditem_nameare local or Clark names; keys used as names must be local.namespacequalifies a localname;prefixsupplies a lexical binding.Arrays wrap by default. Unwrapped arrays repeat the occurrence name unless
item_namesupplies a separate name.orderlists object keys to emit first. By default null emitsxsi:nilfor elements and is omitted with a warning for attributes and text.typeformats a scalar’s lexical value without annotating the XML or changing the JSON.- 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.
rulesmaps RFC 6901 JSON Pointers toMappingRulevalues. 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. Usecompact()to opt into scalar attributes. Rules are checked when their occurrences are projected, because only then are their XML paths known.- Parameters:
root_name (str)
default (str)
rules (collections.abc.Mapping[str, MappingRule] | None)
- property root_name: str | None¶
The static root name, or None when OpenAPI selects it per instance.
- Return type:
str | None
- property rules: collections.abc.Mapping[str, MappingRule]¶
An immutable view of the JSON Pointer to rule policy.
- Return type:
- classmethod elements(root_name, *, rules=None)¶
Return the conservative element-first mapping for root_name.
- Parameters:
root_name (str)
rules (collections.abc.Mapping[str, MappingRule] | None)
- Return type:
- classmethod compact(root_name, *, rules=None)¶
Map scalar object properties to attributes unless overridden.
- Parameters:
root_name (str)
rules (collections.abc.Mapping[str, MappingRule] | None)
- Return type:
- 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_assertionchecks recognized formats during validation;format_typingindependently 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:
schema (pyxsd.schemaless.json_document._JsonSchemaInput)
root_name (str)
rules (collections.abc.Mapping[str, MappingRule] | None)
base_uri (str | None)
reference_registry (referencing.jsonschema.SchemaRegistry | None)
resource_policy (pyxsd.resource_policy.ResourcePolicy | None)
format_assertion (bool)
format_typing (bool)
- Return type:
- 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_nameoverrides 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_assertionchecks recognized formats during validation;format_typingindependently formats compatible values through the mapped XSD SimpleTypes unless an explicit rule provides a type, and rejected values keep the native spelling.- Parameters:
schema_object (collections.abc.Mapping[str, object] | bool)
root_name (str | None)
rules (collections.abc.Mapping[str, MappingRule] | None)
base_uri (str | None)
reference_registry (referencing.jsonschema.SchemaRegistry | None)
resource_policy (pyxsd.resource_policy.ResourcePolicy | None)
dialect (str | None)
format_assertion (bool)
format_typing (bool)
- Return type:
- 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 laterpin_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_valueand therefore follow the document’s effective scalar policy; a missing attribute reads asNone. 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
Nonewhen no child has name. More than one matching child is ambiguous and raisesValueError, unless the generated mapped class keeps achildren()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_valuefor 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; descriptortype=entries merge beneath types into the document’s effective scalar policy as occurrence pins.- Parameters:
source (str | os.PathLike[str] | bytes | bytearray | memoryview | IO[str] | IO[bytes] | xml.etree.ElementTree.Element)
xml_policy (pyxsd.xml_policy.XmlParserPolicy | None)
xml_limits (pyxsd.xml_policy.XmlLimits | None)
types (pyxsd.schemaless.types.TypePolicy | None)
node_mapping (pyxsd.schemaless.nodes.NodeMapping | None)
- Return type:
- class pyxsd.schemaless.DocumentProfile¶
One immutable profile snapshot of a document’s current revision.
revision_idis the XML revision identifier andrevision_dirtyits edited state at snapshot time; a native JSON document has no revision counter, so it recordsNoneandFalse.rowsfollows document order, andcompleteis false whenever a limit truncated evidence.- rows: tuple[PathProfile, ...]¶
- at(path, kind=None)¶
Return the row for path, preferring its own row over an aggregate.
kindselects one row when a path owns more than one, as a JSON array does with"value"and"array-items". Withoutkindthe 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:
- Return type:
- class pyxsd.schemaless.PathProfile¶
Bounded evidence for one structural XML path or exact JSON pointer.
kindis"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.occurrencescounts every value at the path;parentscounts the containing occurrences (one document context for a root row) andmin_occurs/max_occursdescribe how many occurrences each parent holds;missingcounts parents holding none.emptiescounts empty elements, empty attributes, empty strings, and empty JSON containers;nullscounts JSON nulls;mixedcounts XML occurrences that mix character data with element children.distinct_valuesandsampleshold bounded lexical text in document order (samples may repeat),native_kindsholds the observed native JSON kinds, andcandidatesholds 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 throughmixed, 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.interpretationslists the distinct sources of the current interpretation in first-seen order.- candidates: tuple[TypeCandidate, ...] = ()¶
- class pyxsd.schemaless.ProfileLimits¶
Optional budgets for one profile walk.
Every bound is inclusive and positive.
max_pathsbounds the number of reported path rows,max_distinctthe distinct-value list of each row,max_samplesthe sample list of each row, andmax_value_bytesthe UTF-8 length of each stored value.Noneleaves 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.
- class pyxsd.schemaless.TypeCandidate¶
One ranked scalar type evaluated against every value at a path.
first_failureis the first rejecting occurrence in document order, in the same location family the document uses for diagnostics: an XMLIssueLocationor a JSONDataLocation.from_schema_annotationis true when at least one applied JSON Schema annotation suggested the type.- first_failure: pyxsd.locations.IssueLocation | None = None¶
- 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:
- 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:
- scalar_value(node)¶
- Parameters:
node (SchemalessElement)
- Return type:
Any
- attribute_value(node, expanded_name)¶
- Parameters:
node (SchemalessElement)
expanded_name (str)
- Return type:
Any
- class pyxsd.schemaless.ScalarAdapter¶
Convert lexical strings to Python values and back.
The
parsecallback rejects invalid input with aValueError,TypeError, orArithmeticError.formattakes a typed value and returns its lexical representation. An optionalxdmcallback 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.
- to_xdm(value)¶
Convert a typed value to an XDM atomic item.
- Parameters:
value (Any)
- Return type:
- 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:
- classmethod native()¶
Keep native scalar kinds unless they are pinned.
- Return type:
- classmethod infer()¶
Conservatively interpret lexical scalars unless they are pinned.
- Return type:
- static resolve(type_ref)¶
Resolve an XSD scalar name or a caller-supplied adapter.
- Parameters:
type_ref (TypeRef)
- Return type:
- with_pin(path, type_ref)¶
Return a new policy with the adapter pinned at path.
- Parameters:
path (str)
type_ref (TypeRef)
- Return type:
- 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).
assertedis the document layer’s extension point for a schema that proves this occurrence’s type; inference never reinterprets a non-string native value.- Parameters:
pointer (str)
value (object)
asserted (ScalarAdapter | None)
- Return type:
ScalarAdapter | None