2.4. datatypes - Native Python Datatypes for Simple XSD-types

This module defines native Python types for all simple built-in XSD datatypes, as well as functions to (de)serialize them from/into their lexical XML representation.

See https://www.w3.org/TR/xmlschema-2/#built-in-datatypes for the XSD simple type hierarchy and more information on the datatypes. All types from this type hierarchy (except for token and its descendants) are implemented or aliased in this module using their pythonized: Duration, DateTime, GMonthDay, String, Integer, Decimal, Short …. These types are meant to be used directly for data values in the context of Asset Administration Shells.

There are three conversion functions for usage in BaSyx Python SDK’s model and adapters:

  • xsd_repr() serializes any XSD type from this module into its lexical representation

  • from_xsd() parses an XSD type from its lexical representation (its required to name the type for unambiguous conversion)

  • trivial_cast() type-cast a python value into an XSD type, if this is trivially possible. Meant for fixing the type of Properties' values automatically, esp. for literal values.

class AnyURI
class Base64Binary
class Byte(*args, **kwargs)
class Date(year: int, month: int | None = None, day: int | None = None, tzinfo: tzinfo | None = None)
begin() datetime
property tzinfo

timezone info object

utcoffset()

Return the timezone offset as timedelta positive east of UTC (negative west of UTC).

class Float(x=0, /)

A 32bit IEEE754 float. This can not be represented with Python

class GDay(day: int, tzinfo: tzinfo | None = None)
day: int
classmethod from_date(date: date) GDay
into_date(year: int = 1970, month: int = 1) Date
tzinfo: tzinfo | None
class GMonth(month: int, tzinfo: tzinfo | None = None)
classmethod from_date(date: date) GMonth
into_date(year: int = 1970, day: int = 1) Date
month: int
tzinfo: tzinfo | None
class GMonthDay(month: int, day: int, tzinfo: tzinfo | None = None)
day: int
classmethod from_date(date: date) GMonthDay
into_date(year: int = 1970) Date
month: int
tzinfo: tzinfo | None
class GYear(year: int, tzinfo: tzinfo | None = None)
classmethod from_date(date: date) GYear
into_date(month: int = 1, day: int = 1) Date
tzinfo: tzinfo | None
year: int
class GYearMonth(year: int, month: int, tzinfo: tzinfo | None = None)
classmethod from_date(date: date) GYearMonth
into_date(day: int = 1) Date
month: int
tzinfo: tzinfo | None
year: int
class HexBinary
class Int(*args, **kwargs)
class Long(*args, **kwargs)
class NegativeInteger(*args, **kwargs)
class NonNegativeInteger(*args, **kwargs)
class NonPositiveInteger(*args, **kwargs)
class NormalizedString(*args, **kwargs)
classmethod from_string(value: str) NormalizedString

Make a string a normalized string by simply dropping all carriage return, newline and tab characters.

class PositiveInteger(*args, **kwargs)
class Short(*args, **kwargs)
class UnsignedByte(*args, **kwargs)
class UnsignedInt(*args, **kwargs)
class UnsignedLong(*args, **kwargs)
class UnsignedShort(*args, **kwargs)
from_xsd(value: str, type_: Type[relativedelta | datetime | Date | time | GYearMonth | GYear | GMonthDay | GMonth | GDay | bool | Base64Binary | HexBinary | Float | float | Decimal | int | Long | Int | Short | Byte | NonPositiveInteger | NegativeInteger | NonNegativeInteger | PositiveInteger | UnsignedLong | UnsignedInt | UnsignedShort | UnsignedByte | AnyURI | str | NormalizedString]) relativedelta | datetime | Date | time | GYearMonth | GYear | GMonthDay | GMonth | GDay | bool | Base64Binary | HexBinary | Float | float | Decimal | int | Long | Int | Short | Byte | NonPositiveInteger | NegativeInteger | NonNegativeInteger | PositiveInteger | UnsignedLong | UnsignedInt | UnsignedShort | UnsignedByte | AnyURI | str | NormalizedString

Parse an XSD type value from its lexical representation

Parameters:
  • value – Lexical representation

  • type – The expected XSD type (from this module). It is required to chose the correct conversion.

trivial_cast(value, type_: Type[relativedelta | datetime | Date | time | GYearMonth | GYear | GMonthDay | GMonth | GDay | bool | Base64Binary | HexBinary | Float | float | Decimal | int | Long | Int | Short | Byte | NonPositiveInteger | NegativeInteger | NonNegativeInteger | PositiveInteger | UnsignedLong | UnsignedInt | UnsignedShort | UnsignedByte | AnyURI | str | NormalizedString]) relativedelta | datetime | Date | time | GYearMonth | GYear | GMonthDay | GMonth | GDay | bool | Base64Binary | HexBinary | Float | float | Decimal | int | Long | Int | Short | Byte | NonPositiveInteger | NegativeInteger | NonNegativeInteger | PositiveInteger | UnsignedLong | UnsignedInt | UnsignedShort | UnsignedByte | AnyURI | str | NormalizedString

Type-cast a python value into an XSD type, if this is a trivial conversion

The main purpose of this function is to allow AAS Properties (and similar objects with XSD-type values) to take Python literal values and convert them to their XSD type. However, we want to stay strongly typed, so we only allow this type-cast if it is trivial to do, i.e. does not change the value’s semantics. Examples, where this holds true:

  • int → Int (if the value is in the expected range)

  • bytes → Base64Binary

  • datetime.date → Date

Yet, it is not allowed to cast float → basyx.aas.model.datatypes.Int.

Parameters:
  • value – The value to cast

  • type – Target type to cast into. Must be an XSD type from this module

xsd_repr(value: relativedelta | datetime | Date | time | GYearMonth | GYear | GMonthDay | GMonth | GDay | bool | Base64Binary | HexBinary | Float | float | Decimal | int | Long | Int | Short | Byte | NonPositiveInteger | NegativeInteger | NonNegativeInteger | PositiveInteger | UnsignedLong | UnsignedInt | UnsignedShort | UnsignedByte | AnyURI | str | NormalizedString) str

Serialize an XSD type value into it’s lexical representation

Parameters:

value – Any XSD type (from this module)

Returns:

Lexical representation as string