Data Types
Keep your parameters and return values typed and constrained.
Data types are specified according to PEP 484. The type hints are automatically converted to the respective SiLA data types. The datatypes, as specified by the SiLA 2 Standard Part A, and their respective counterparts are defined in the data_types folder.
Example:
@sila.UnobservableCommand()
async def prepare_for_input(
self,
handover_position: HandoverPosition,
internal_position: PositionIndex,
labware_type: str,
labware_unique_ID: str,
) -> None:
The input parameters "handover_position" and "internal_position" are of type "CustomDataType" which must be defined. The parameters "labware_type" and "labware_unique_id" are of type "string". The return type of this method is "None". The identifier, display name and description of an input and a return parameter can be specified in the docstring using the following syntax:
"""
My method description.
.. parameter:: This is the parameter description.
:display_name: Parameter display name
:identifier: ParameterDisplayName
.. return:: This is the return description
:display_name: Return display name
:identifier: ReturnDisplayName
"""
The parameters must be annotated in the docstring in the same order as in the method declaration.
CustomDataType
Custom Data Types are defined in the same base file as a Python data class. You can find further examples in the LabwareTransferFeature in the feature library.
@dataclasses.dataclass
class HandoverPosition(sila.CustomDataType):
"""
Specifies one of the possible positions of a device where labware items can be handed over. Can contain a
sub-position, e.g. for specifying a position in a rack.
"""
position: str
sub_position: PositionIndex
Constraints
If the input parameters are constrained, you can use the SiLA Constraints as defined by the standards using our SiLA Python library. Read up on available constraints in the installed Python SiLA library.
@dataclasses.dataclass
class PositionIndex(sila.CustomDataType):
"""Specifies a position via an index number, starting at 1."""
position_index: typing.Annotated[int, sila.constraints.MinimalInclusive(value=1)]