Note
Go to the end to download the full example code
Flyte and Python Types#
FlyteKit automatically maps Python types to Flyte types. This section provides details of the mappings, but for the most part you can skip this section, as almost all of Python types are mapped automatically.
The following table provides a quick overview of how types are converted from the type-hints (python native) to Flyte-understood, cross-language types.
Python Type |
Flyte Type |
Conversion |
Comment |
---|---|---|---|
int |
Integer |
Automatic |
just use python 3 type hints |
float |
Float |
Automatic |
just use python 3 type hints |
str |
String |
Automatic |
just use python 3 type hints |
bool |
Boolean |
Automatic |
just use python 3 type hints |
bytes/bytearray |
binary |
Not Supported |
Let us know if this is an interesting usecase that you can currently support using your own transformers. |
complex |
NA |
Not Supported |
Let us know if this is an interesting usecase that you can currently support using your own transformers. |
datetime.timedelta |
Duration |
Automatic |
just use python 3 type hints |
datetime.datetime |
Datetime |
Automatic |
just use python 3 type hints |
Univariate List / typing.List |
Collection [ type ] |
Automatic |
Use python 3 type hints e.g |
file / file-like / os.PathLike / flytekit.types.file.FlyteFile |
Blob - Single |
Automatic |
Use python 3 type hints. if using |
Directory / flytekit.types.directory.FlyteDirectory |
Blob - MultiPart |
Automatic |
Use python 3 type hints. If using FlyteDirectory[“protocol”] it is assumed that all the files are of the specified protocol |
Typed dictionary with str key - typing.Dict[str, V] |
Map[str, V] |
Automatic |
Use python 3 type hints e.g |
Untyped dictionary - dict |
JSON (struct.pb) |
Automatic |
Use python 3 type hints e.g |
Dataclasses |
Struct |
Automatic |
Use python 3 type hints. The class should be a pure value class and should be annotated with |
pandas.DataFrame |
Schema |
Automatic |
Use python 3 type hints. Pandas column types are not preserved |
pyspark.DataFrame |
Schema |
Automatic |
Use python 3 type hints. Column types are not preserved. Install |
torch.Tensor & torch.nn.Module |
Blob - Single |
Automatic |
Use PyTorch type hints. |
User defined types |
Any |
Custom Transformers |
Use python 3 type hints. We use |
Total running time of the script: ( 0 minutes 0.000 seconds)