acoustic-carpenter-78188
09/04/2025, 12:08 AMFlyteFile 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/flyteacoustic-carpenter-78188
09/04/2025, 12:08 AM