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 mapping of input names to tuples containing their Python type and default value, used to define the task's input signature. |
| outputs | Dict[str, Type] | A mapping of output names to their expected Python types, used to define the task's return signature. |
| docstring | Optional[Docstring] = None | The parsed documentation object for the task, used to provide metadata and descriptions for the interface components. |
| has_default | ClassVar[Type[_has_default]] = _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
| Name | Type | Description |
|---|---|---|
| inputs | Dict[str, Tuple[Type, Any]] | A dictionary mapping input names to a tuple containing their Python type and default value. |
| outputs | Dict[str, Type] | A dictionary mapping output names to their respective Python types. |
| docstring | Optional[Docstring] = None | An optional Docstring object containing documentation for the task. |
| _remote_defaults | Optional[Dict[str, literals_pb2.Literal]] = None | An optional dictionary of default values for inputs already in remote literal form. |
Methods
has_outputs()
def has_outputs(self) -> bool: ...
Check if the task has outputs. This is used to determine if the task has outputs or not.
Returns
| Type | Description |
|---|---|
boolean | True if the interface defines one or more output parameters, False otherwise |
required_inputs()
def required_inputs(self) -> 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 |
|---|---|
array | A list of required input names. |
num_required_inputs()
def num_required_inputs(self) -> 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 |
|---|---|
integer | The total count of input parameters that do not have a default value |
from_types()
@classmethod
def from_types(
cls,
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: ...
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 | A dictionary of input names and their types and a value indicating if they have a default value. |
| outputs | dict | A dictionary of output names and their types. |
| default_inputs | dict | 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(cls, func: Callable) -> 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 Python function or callable to inspect for parameter and return type information |
Returns
| Type | Description |
|---|---|
[NativeInterface](nativeinterface.md?sid=flyte_models_nativeinterface) | A new NativeInterface instance derived from the function's signature, type hints, and docstring |
convert_to_kwargs()
def convert_to_kwargs(self, *args, **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 | any | Positional arguments provided by the caller to be mapped to interface input names |
| kwargs | any | Keyword arguments provided by the caller |
Returns
| Type | Description |
|---|---|
dict | A dictionary mapping input names to their corresponding values provided via positional or keyword arguments |
get_input_types()
def get_input_types(self) -> 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 | A dictionary mapping input names to their respective Python types |
json_schema()
@property
def json_schema(self) -> 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 | A JSON schema representation of the inputs, including property types and a list of required fields |