pyxsd.xdm

Independent, immutable XDM 3.1 values.

The package is reusable by XPath, serialization, and other consumers and is independent of stylesheet execution; it does not import pyxsd.xslt.

Attributes

XdmSequence

an ordered tuple of items, possibly empty.

Classes

XdmArray

An immutable XDM array whose members are XDM sequences, indexed from one.

XdmAtomic

One immutable XDM atomic value with its XSD type identity.

XdmFunction

An immutable XDM function item.

XdmFunctionSignature

The declared parameter and return sequence types of a function item.

XdmItem

Base class for one XDM item.

XdmMap

An immutable XDM map with XDM key equality and update semantics.

XdmSequenceType

One XDM sequence type: a type name and an occurrence indicator.

Functions

as_xdm(value)

Convert one host value to an XDM sequence at the explicit seam.

Package Contents

class pyxsd.xdm.XdmArray(members=())

An immutable XDM array whose members are XDM sequences, indexed from one.

Parameters:

members (collections.abc.Iterable[Any])

property members: tuple[XdmSequence, ...]
Return type:

tuple[XdmSequence, …]

property size: int
Return type:

int

get(index)

Return the one-based member at index.

Parameters:

index (int)

Return type:

XdmSequence

class pyxsd.xdm.XdmAtomic

One immutable XDM atomic value with its XSD type identity.

value: Any
type_name: str
datatype: type[Any] | None = None
classmethod string(value)
Parameters:

value (str)

Return type:

XdmAtomic

classmethod integer(value)
Parameters:

value (int)

Return type:

XdmAtomic

classmethod decimal(value)
Parameters:

value (int | decimal.Decimal | str)

Return type:

XdmAtomic

classmethod double(value)
Parameters:

value (int | float)

Return type:

XdmAtomic

classmethod float(value)
Parameters:

value (int | float)

Return type:

XdmAtomic

classmethod boolean(value)
Parameters:

value (bool)

Return type:

XdmAtomic

classmethod untyped_atomic(value)
Parameters:

value (str)

Return type:

XdmAtomic

classmethod any_uri(value)
Parameters:

value (str)

Return type:

XdmAtomic

classmethod typed(value, datatype)

Wrap a value and its XSD datatype at the atomic invariant boundary.

List values are not atomic, the payload must carry its actual XSD datatype class (Python storage bases are not accepted), and the payload must be hashable so it can serve as an XDM map key. The function-item layer never constructs an atomic from a mutable Python container.

Parameters:
  • value (Any)

  • datatype (type[Any])

Return type:

XdmAtomic

property lexical: str

The XSD lexical form, including INF/-INF/NaN spellings.

Return type:

str

property string_value: str

The string value, as computed by fn:string (F&O 3.1 §19.1.1).

Numeric and boolean values convert by value rather than by their XSD lexical form: xs:double 2.0 is "2", xs:decimal 2.50 is "2.5", and values outside [1e-6, 1e6) use scientific notation. Every other family’s XSD lexical form is already its string value.

Return type:

str

same_key(other)

XDM op:same-key map-key equality.

Numeric keys compare by exact mathematical value with no rounding, so map keys stay transitive and distinct xs:decimal/xs:double values are not collapsed. Strings and their derived types compare by value, QNames compare by expanded name, and two NaNs are the same key even though NaN eq NaN is false.

Parameters:

other (object)

Return type:

bool

cast(type_name)

Cast this value to another built-in XSD atomic type.

Casting uses the XSD lexical space. Types that require schema or namespace context (for example xs:QName) are rejected rather than approximated.

Parameters:

type_name (str)

Return type:

XdmAtomic

class pyxsd.xdm.XdmFunction(implementation, *, arity=None, signature=None, closure=None, name=None, declared_types=None)

An immutable XDM function item.

implementation is called as implementation(arguments, environment, closure) after arity checking and optional signature coercion. It must return an XDM value or a host container convertible by as_xdm(). The implementation is private to the item and is never exposed as a plain Python call surface.

Parameters:
arity: tuple[int, int | None]
signature: XdmFunctionSignature | None
closure: Any
name: str | None
declared_types: XdmFunctionSignature | None
invoke(arguments, environment=None)

Invoke with XDM argument sequences and one invocation environment.

Parameters:
Return type:

XdmSequence

class pyxsd.xdm.XdmFunctionSignature

The declared parameter and return sequence types of a function item.

parameters: tuple[XdmSequenceType, ...] = ()
return_type: XdmSequenceType | None = None
class pyxsd.xdm.XdmItem

Base class for one XDM item.

Concrete items are immutable. Nodes extend this class in pyxsd.xdm.nodes; they are not value items and are never compared by value here.

class pyxsd.xdm.XdmMap(entries=())

An immutable XDM map with XDM key equality and update semantics.

Parameters:

entries (collections.abc.Iterable[tuple[XdmAtomic, Any]])

classmethod empty()
Return type:

XdmMap

classmethod merge(*maps, duplicates='use-first')

Merge maps with the normative map:merge duplicate policies.

Parameters:
Return type:

XdmMap

classmethod from_mapping(mapping)

Explicit host-dictionary conversion; keys must atomize to one atomic.

Parameters:

mapping (collections.abc.Mapping[Any, Any])

Return type:

XdmMap

property entries: tuple[tuple[XdmAtomic, XdmSequence], ...]
Return type:

tuple[tuple[XdmAtomic, XdmSequence], …]

property size: int
Return type:

int

get(key)
Parameters:

key (XdmAtomic)

Return type:

XdmSequence

contains(key)
Parameters:

key (XdmAtomic)

Return type:

bool

put(key, value)
Parameters:
Return type:

XdmMap

remove(key)
Parameters:

key (XdmAtomic)

Return type:

XdmMap

keys()
Return type:

tuple[XdmAtomic, …]

values()
Return type:

tuple[XdmSequence, …]

type pyxsd.xdm.XdmSequence = tuple[XdmItem, ...]

an ordered tuple of items, possibly empty.

Type:

An XDM sequence

class pyxsd.xdm.XdmSequenceType

One XDM sequence type: a type name and an occurrence indicator.

type_name: str = 'item()'
occurrence: str = 'zero-or-more'
pyxsd.xdm.as_xdm(value)

Convert one host value to an XDM sequence at the explicit seam.

An XdmItem becomes a one-item sequence. A host list, tuple, or other iterable is a sequence (nested host sequences flatten, since XDM sequences never nest). A mapping is one XdmMap item. Strings and byte strings are single atomic items and are never iterated as characters or integers. None is rejected because the empty sequence is ().

Parameters:

value (Any)

Return type:

XdmSequence