<#5688 [Core feature] Simple Type Transformers for...
# flyte-github
a
#5688 [Core feature] Simple Type Transformers for data backed by FlyteFile or FlyteDirectory Issue created by thomasjpfan ### Motivation: Why do you think this is important? Currently, creating a type transformer requires learning about the TypeTransformer API which requires someone to learn about Flyte Literals, Flyte Context, etc. For example, here is the TypeTransformer for `np.ndarray` For the simple case, most data are backed by just a
FlyteFile
or
FlyteDirectory
at rest. I propose we have a simplified interface for creating these type transformers. This way, we can make it very easy for users to define their own serializers and deserializers. ### Goal: What should the final outcome look like, ideally? I propose this simplified TypeTransformer API for data backed by FlyteFile: from typing import Protocol, runtime_checkable, Any, Protocol from flytekit.types.file import FlyteFile @runtime_checkable class FlyteFileBackedTransformerProtocol(Protocol): name: str python_type: type def save(self, obj: Any) -> FlyteFile: """Serialized obj and return a FlyteFile""" def load(self, file: FlyteFile) -> Any: """Load model from file.""" The same API can then be applied to
FlyteDirectory
. For example, we can define the NumPy Transformer as: import numpy as np class NumPyTransformer: name: str = "NumPy" python_type: type = np.ndarray def save(self, obj: np.ndarray) -> FlyteFile: new_file = FlyteFile.new_remote_file() with new_file.open("wb") as f: np.save(f, obj) return new_file def load(self, file: FlyteFile) -> np.ndarray: with file.open("rb") as f: return np.load(f) TypeEngine.register(NumPyTransformer()) ### Describe alternatives you've considered Do nothing and only have
TypeTransformer
API. ### Propose: Link/Inline OR Additional context No response ### Are you sure this issue hasn't been raised already? • Yes ### Have you read the Code of Conduct? • Yes flyteorg/flyte