flytekit.types.iterator.json_iterator
Directory
Classes
Class | Description |
---|---|
JSONIterator |
Abstract base class for generic types. |
JSONIteratorTransformer |
A JSON iterator that handles conversion between an iterator/generator and a JSONL file. |
flytekit.types.iterator.json_iterator.JSONIterator
Abstract base class for generic types.
On Python 3.12 and newer, generic classes implicitly inherit from Generic when they declare a parameter list after the class’s name::
class Mapping[KT, VT]:
def __getitem__(self, key: KT) -> VT:
...
# Etc.
On older versions of Python, however, generic classes have to explicitly inherit from Generic.
After a class has been declared to be generic, it can then be used as follows::
def lookup_name[KT, VT](mapping: Mapping[KT, VT], key: KT, default: VT) -> VT:
try:
return mapping[key]
except KeyError:
return default
class JSONIterator(
reader: jsonlines.jsonlines.Reader,
)
Parameter | Type |
---|---|
reader |
jsonlines.jsonlines.Reader |
flytekit.types.iterator.json_iterator.JSONIteratorTransformer
A JSON iterator that handles conversion between an iterator/generator and a JSONL file.
def JSONIteratorTransformer()
Methods
Method | Description |
---|---|
assert_type() |
|
async_to_literal() |
Converts a given python_val to a Flyte Literal, assuming the given python_val matches the declared python_type. |
async_to_python_value() |
Converts the given Literal to a Python Type. |
from_binary_idl() |
This function primarily handles deserialization for untyped dicts, dataclasses, Pydantic BaseModels, and attribute access. |
from_generic_idl() |
TODO: Support all Flyte Types. |
get_literal_type() |
Converts the python type to a Flyte LiteralType. |
guess_python_type() |
Converts the Flyte LiteralType to a python object type. |
isinstance_generic() |
|
to_html() |
Converts any python val (dataframe, int, float) to a html string, and it will be wrapped in the HTML div. |
to_literal() |
Converts a given python_val to a Flyte Literal, assuming the given python_val matches the declared python_type. |
to_python_value() |
Converts the given Literal to a Python Type. |
assert_type()
def assert_type(
t: Type[T],
v: T,
)
Parameter | Type |
---|---|
t |
Type[T] |
v |
T |
async_to_literal()
def async_to_literal(
ctx: flytekit.core.context_manager.FlyteContext,
python_val: typing.Iterator[typing.Union[typing.Dict[str, typing.Any], typing.List[typing.Any], bool, float, int, str]],
python_type: typing.Type[typing.Iterator[typing.Union[typing.Dict[str, typing.Any], typing.List[typing.Any], bool, float, int, str]]],
expected: flytekit.models.types.LiteralType,
) -> flytekit.models.literals.Literal
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
Parameter | Type |
---|---|
ctx |
flytekit.core.context_manager.FlyteContext |
python_val |
typing.Iterator[typing.Union[typing.Dict[str, typing.Any], typing.List[typing.Any], bool, float, int, str]] |
python_type |
typing.Type[typing.Iterator[typing.Union[typing.Dict[str, typing.Any], typing.List[typing.Any], bool, float, int, str]]] |
expected |
flytekit.models.types.LiteralType |
async_to_python_value()
def async_to_python_value(
ctx: flytekit.core.context_manager.FlyteContext,
lv: flytekit.models.literals.Literal,
expected_python_type: typing.Type[typing.Iterator[typing.Union[typing.Dict[str, typing.Any], typing.List[typing.Any], bool, float, int, str]]],
) -> flytekit.types.iterator.json_iterator.JSONIterator
Converts the given Literal to a Python Type. If the conversion cannot be done an AssertionError should be raised
Parameter | Type |
---|---|
ctx |
flytekit.core.context_manager.FlyteContext |
lv |
flytekit.models.literals.Literal |
expected_python_type |
typing.Type[typing.Iterator[typing.Union[typing.Dict[str, typing.Any], typing.List[typing.Any], bool, float, int, str]]] |
from_binary_idl()
def from_binary_idl(
binary_idl_object: Binary,
expected_python_type: Type[T],
) -> Optional[T]
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)
Parameter | Type |
---|---|
binary_idl_object |
Binary |
expected_python_type |
Type[T] |
from_generic_idl()
def from_generic_idl(
generic: Struct,
expected_python_type: Type[T],
) -> Optional[T]
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.
Parameter | Type |
---|---|
generic |
Struct |
expected_python_type |
Type[T] |
get_literal_type()
def get_literal_type(
t: typing.Type[typing.Iterator[typing.Union[typing.Dict[str, typing.Any], typing.List[typing.Any], bool, float, int, str]]],
) -> flytekit.models.types.LiteralType
Converts the python type to a Flyte LiteralType
Parameter | Type |
---|---|
t |
typing.Type[typing.Iterator[typing.Union[typing.Dict[str, typing.Any], typing.List[typing.Any], bool, float, int, str]]] |
guess_python_type()
def guess_python_type(
literal_type: flytekit.models.types.LiteralType,
) -> typing.Type[typing.Iterator[typing.Union[typing.Dict[str, typing.Any], typing.List[typing.Any], bool, float, int, str]]]
Converts the Flyte LiteralType to a python object type.
Parameter | Type |
---|---|
literal_type |
flytekit.models.types.LiteralType |
isinstance_generic()
def isinstance_generic(
obj,
generic_alias,
)
Parameter | Type |
---|---|
obj |
|
generic_alias |
to_html()
def to_html(
ctx: FlyteContext,
python_val: T,
expected_python_type: Type[T],
) -> str
Converts any python val (dataframe, int, float) to a html string, and it will be wrapped in the HTML div
Parameter | Type |
---|---|
ctx |
FlyteContext |
python_val |
T |
expected_python_type |
Type[T] |
to_literal()
def to_literal(
ctx: FlyteContext,
python_val: typing.Any,
python_type: Type[T],
expected: LiteralType,
) -> Literal
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
Parameter | Type |
---|---|
ctx |
FlyteContext |
python_val |
typing.Any |
python_type |
Type[T] |
expected |
LiteralType |
to_python_value()
def to_python_value(
ctx: FlyteContext,
lv: Literal,
expected_python_type: Type[T],
) -> Optional[T]
Converts the given Literal to a Python Type. If the conversion cannot be done an AssertionError should be raised
Parameter | Type |
---|---|
ctx |
FlyteContext |
lv |
Literal |
expected_python_type |
Type[T] |
Properties
Property | Type | Description |
---|---|---|
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 |