Skip to main content

NativeInterface

A class representing the native interface for a task. This is used to interact with the task and its execution context.

Attributes

AttributeTypeDescription
inputsDict[str, Tuple[Type, Any]]A mapping of input names to tuples containing their Python type and default value, used to define the task's input signature.
outputsDict[str, Type]A mapping of output names to their Python types, used to define the task's return signature.
docstringOptional[Docstring] = nullAn optional parsed docstring object containing documentation for the task and its parameters.
has_defaultClassVar[Type[_has_default]]This can be used to indicate if a specific input has a default value or not, in the case when the default value is not known.

Constructor

Signature

def NativeInterface(
inputs: Dict[str, Tuple[Type, Any]],
outputs: Dict[str, Type],
docstring: Optional[Docstring] = None,
_remote_defaults: Optional[Dict[str, literals_pb2.Literal]] = None
) - > null

Parameters

NameTypeDescription
inputsDict[str, Tuple[Type, Any]]A dictionary mapping input names to a tuple containing their Python type and default value.
outputsDict[str, Type]A dictionary mapping output names to their respective Python types.
docstringOptional[Docstring] = NoneAn optional Docstring object parsed from the task function.
_remote_defaultsOptional[Dict[str, literals_pb2.Literal]] = NoneAn optional dictionary of default values for remote tasks in protobuf literal format.

Methods


has_outputs()

@classmethod
def has_outputs() - > bool

Check if the task has outputs. This is used to determine if the task has outputs or not.

Returns

TypeDescription
boolTrue if the task defines one or more output parameters, False otherwise

required_inputs()

@classmethod
def required_inputs() - > List[str]

Get the names of the required inputs for the task. This is used to determine which inputs are required for the task execution.

Returns

TypeDescription
List[str]A list of required input names.

num_required_inputs()

@classmethod
def num_required_inputs() - > int

Get the number of required inputs for the task. This is used to determine how many inputs are required for the task execution.

Returns

TypeDescription
intThe total count of input parameters that do not have a default value

from_types()

@classmethod
def from_types(
inputs: Dict[str, Tuple[Type, Type[_has_default]| Type[inspect._empty]]],
outputs: Dict[str, Type],
default_inputs: Optional[Dict[str, literals_pb2.Literal]] = None
) - > [NativeInterface](nativeinterface.md?sid=flyte_models_nativeinterface)

Create a new NativeInterface from the given types. This is used to create a native interface for the task.

Parameters

NameTypeDescription
inputs`Dict[str, Tuple[Type, Type[_has_default]Type[inspect._empty]]]`
outputsDict[str, Type]A dictionary of output names and their types.
default_inputsOptional[Dict[str, literals_pb2.Literal]] = NoneOptional dictionary of default inputs for remote tasks.

Returns

TypeDescription
[NativeInterface](nativeinterface.md?sid=flyte_models_nativeinterface)A NativeInterface object with the given inputs and outputs.

from_callable()

@classmethod
def from_callable(
func: Callable
) - > [NativeInterface](nativeinterface.md?sid=flyte_models_nativeinterface)

Extract the native interface from the given function. This is used to create a native interface for the task.

Parameters

NameTypeDescription
funcCallableThe Python function or callable to inspect for parameters and return types

Returns

TypeDescription
[NativeInterface](nativeinterface.md?sid=flyte_models_nativeinterface)A new interface instance derived from the function signature, type hints, and docstrings

convert_to_kwargs()

@classmethod
def convert_to_kwargs(
*args: Any,
**kwargs: Any
) - > Dict[str, Any]

Convert the given arguments to keyword arguments based on the native interface. This is used to convert the arguments to the correct types for the task execution.

Parameters

NameTypeDescription
*argsAnyPositional arguments to be mapped to the interface's input names
**kwargsAnyKeyword arguments representing task inputs

Returns

TypeDescription
Dict[str, Any]A dictionary mapping input names to their corresponding values

get_input_types()

@classmethod
def get_input_types() - > Dict[str, Type]

Get the input types for the task. This is used to get the types of the inputs for the task execution.

Returns

TypeDescription
Dict[str, Type]A dictionary mapping input names to their Python types

json_schema()

@classmethod
def json_schema() - > Dict[str, Any]

Convert task inputs to a JSON schema dict. Uses the Flyte type engine to produce a LiteralType for each input, then converts to JSON schema.

Returns

TypeDescription
Dict[str, Any]A JSON schema object representing the required and optional inputs