flytekit.extend.DictTransformer#

class flytekit.extend.DictTransformer[source]#

Transformer that transforms an univariate dictionary Dict[str, T] to a Literal Map or transforms an untyped dictionary to a Binary Scalar Literal with a Struct Literal Type.

Methods

assert_type(t, v)[source]#
Parameters:
async async_to_literal(ctx, python_val, python_type, expected)[source]#

Converts a given python_val to a Flyte Literal, assuming the given python_val matches the declared python_type. Implementers should refrain from using type(python_val) instead rely on the passed in python_type. If these do not match (or are not allowed) the Transformer implementer should raise an AssertionError, clearly stating what was the mismatch :param ctx: A FlyteContext, useful in accessing the filesystem and other attributes :param python_val: The actual value to be transformed :param python_type: The assumed type of the value (this matches the declared type on the function) :param expected: Expected Literal Type

Parameters:
Return type:

Literal

async async_to_python_value(ctx, lv, expected_python_type)[source]#

Converts the given Literal to a Python Type. If the conversion cannot be done an AssertionError should be raised :param ctx: FlyteContext :param lv: The received literal Value :param expected_python_type: Expected native python type that should be returned

Parameters:
Return type:

dict

async static dict_to_binary_literal(ctx, v, python_type, allow_pickle)[source]#

Converts a Python dictionary to a Flyte-specific Literal using MessagePack encoding. Falls back to Pickle if encoding fails and allow_pickle is True.

Parameters:
Return type:

Literal

async static dict_to_generic_literal(ctx, v, python_type, allow_pickle)[source]#

This is deprecated from flytekit 1.14.0. Creates a flyte-specific Literal value from a native python dictionary. Note: This is deprecated and will be removed in the future.

Parameters:
Return type:

Literal

static dict_types(python_type)[source]#
Parameters:

python_type (Type)

Return type:

Tuple[Any, …]

static extract_types_or_metadata(t)[source]#
Parameters:

t (Type[dict] | None)

Return type:

Tuple

from_binary_idl(binary_idl_object, expected_python_type)[source]#

This function primarily handles deserialization for untyped dicts, dataclasses, Pydantic BaseModels, and attribute access.`

For untyped dict, dataclass, and pydantic basemodel: Life Cycle (Untyped Dict as example):

python val -> msgpack bytes -> binary literal scalar -> msgpack bytes -> python val

(to_literal) (from_binary_idl)

For attribute access: Life Cycle:

python val -> msgpack bytes -> binary literal scalar -> resolved golang value -> binary literal scalar -> msgpack bytes -> python val

(to_literal) (propeller attribute access) (from_binary_idl)

Parameters:
  • binary_idl_object (Binary)

  • expected_python_type (Type[T])

Return type:

T | None

from_generic_idl(generic, expected_python_type)[source]#

TODO: Support all Flyte Types. This is for dataclass attribute access from input created from the Flyte Console.

Note: - This can be removed in the future when the Flyte Console support generate Binary IDL Scalar as input.

Parameters:
  • generic (Struct)

  • expected_python_type (Type[T])

Return type:

T | None

get_literal_type(t)[source]#

Transforms a native python dictionary to a flyte-specific LiteralType

Parameters:

t (Type[dict])

Return type:

LiteralType

guess_python_type(literal_type)[source]#

Converts the Flyte LiteralType to a python object type.

Parameters:

literal_type (LiteralType)

Return type:

Union[Type[dict], Dict[Type, Type]]

static is_pickle(python_type)[source]#
Parameters:

python_type (Type[dict])

Return type:

Tuple[bool, Type]

isinstance_generic(obj, generic_alias)[source]#
to_html(ctx, python_val, expected_python_type)[source]#

Converts any python val (dataframe, int, float) to a html string, and it will be wrapped in the HTML div

Parameters:
Return type:

str

to_literal(ctx, python_val, python_type, expected)[source]#

Converts a given python_val to a Flyte Literal, assuming the given python_val matches the declared python_type. Implementers should refrain from using type(python_val) instead rely on the passed in python_type. If these do not match (or are not allowed) the Transformer implementer should raise an AssertionError, clearly stating what was the mismatch :param ctx: A FlyteContext, useful in accessing the filesystem and other attributes :param python_val: The actual value to be transformed :param python_type: The assumed type of the value (this matches the declared type on the function) :param expected: Expected Literal Type

Parameters:
Return type:

Literal

to_python_value(ctx, lv, expected_python_type)[source]#

Converts the given Literal to a Python Type. If the conversion cannot be done an AssertionError should be raised :param ctx: FlyteContext :param lv: The received literal Value :param expected_python_type: Expected native python type that should be returned

Parameters:
Return type:

T | None

Attributes

is_async
name
python_type

This returns the python type

type_assertions_enabled

Indicates if the transformer wants type assertions to be enabled at the core type engine layer