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 representationfrom_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 ofProperties'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)
-
- 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 GYearMonth(year: int, month: int, tzinfo: tzinfo | None = None)
- classmethod from_date(date: date) GYearMonth
- 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 →
Base64Binarydatetime.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