NativeInterface
A class representing the native interface for a task. This is used to interact with the task and its execution context.
Attributes
| Attribute | Type | Description |
|---|---|---|
| inputs | Dict[str, Tuple[Type, Any]] | A dictionary where keys are input names and values are tuples containing the input's type and its default value or an indicator if it has a default. |
| outputs | Dict[str, Type] | A dictionary where keys are output names and values are their corresponding types. |
| docstring | Optional[Docstring] = None | The parsed docstring of the task, providing documentation for the task's purpose and parameters. |
| has_default | ClassVar[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. |
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
| Type | Description |
|---|---|
bool | True if the task has outputs, 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
| Type | Description |
|---|---|
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
| Type | Description |
|---|---|
int | The count of required inputs for the task. |
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
| Name | Type | Description |
|---|---|---|
| inputs | `Dict[str, Tuple[Type, Type[_has_default] | Type[inspect._empty]]]` |
| outputs | Dict[str, Type] | A dictionary of output names and their types. |
| default_inputs | Optional[Dict[str, literals_pb2.Literal]] = None | Optional dictionary of default inputs for remote tasks. |
Returns
| Type | Description |
|---|---|
[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
| Name | Type | Description |
|---|---|---|
| func | Callable | The callable (function) from which to extract the native interface. |
Returns
| Type | Description |
|---|---|
[NativeInterface](nativeinterface.md?sid=flyte_models_nativeinterface) | A NativeInterface object representing the interface of the provided callable. |
convert_to_kwargs()
@classmethod
def convert_to_kwargs(
args: *args,
kwargs: **kwargs
) - > 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
| Name | Type | Description |
|---|---|---|
| args | *args | Positional arguments to convert. |
| kwargs | **kwargs | Keyword arguments to convert. |
Returns
| Type | Description |
|---|---|
Dict[str, Any] | A dictionary of keyword arguments derived from the provided positional and keyword arguments. |
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
| Type | Description |
|---|---|
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
| Type | Description |
|---|---|
Dict[str, Any] | A dictionary representing the JSON schema for the task's inputs. |