https://flyte.org logo
#ask-the-community
Title
# ask-the-community
x

Xin Shi

03/17/2023, 7:41 PM
Hi, I have a simple question: From the Flyte documentation and tutorial, it seems classes are not supported by Flyte. Is this correct? If not, is there any material that you can share about using classes in Flyte. Thanks!
k

Kevin Su

03/17/2023, 8:23 PM
you means using classes as task input / output ?
x

Xin Shi

03/17/2023, 8:33 PM
Like can we define some tasks, workflows, launchplans within a class.
Or in another way, the questions is: can we convert the functions in classes to tasks, workflows and launchplans.
k

Kevin Su

03/17/2023, 8:37 PM
why do you want use task or workflow in the class?
x

Xin Shi

03/17/2023, 8:37 PM
I am asking this question as we wanted to build a flyte pipeline in my company and we noticed that there are lots of classes in this project. If we need to convert these classes to be functions (which can be decorated to be tasks), then there will be a lot of work.
So do we have any workaround in this situation?
k

Kevin Su

03/17/2023, 8:39 PM
do you mind share some examples of your classes? I’m thinking how to easily convert your class to flyte task.
x

Xin Shi

03/17/2023, 8:41 PM
I may need to ask in my team to see if it is good to share some examples. I will let you know later. Thanks anyway. This is helpful!
k

Kevin Su

03/17/2023, 8:46 PM
I wrote a simple example, is this what you want?
Copy code
from flytekit import workflow, task


class MyClass:

    @task
    def t1(self):
        return 'hello world'


@workflow
def wf():
    MyClass().t1()
x

Xin Shi

03/17/2023, 8:49 PM
yes, does flyte support this? My understanding is no. But I am not sure.
In some cases, we may also want to have
Copy code
from flytekit import workflow, task


class MyClass:

    @task
    def t1(self):
        return 'hello world'

    @task
    def t2(self):
        return 'hello world too'


@workflow
def wf():
    MyClass().t1()
    MyClass().t2()
k

Kevin Su

03/17/2023, 8:53 PM
Not now, but I think it’s doable. mind creating an issue here [flyte-core]. we will work on that. contributions welcome too.
[flyte-core]
x

Xin Shi

03/17/2023, 9:10 PM
just created an issue for this. Not sure if what I filled in is correct or not. Feel free to add anything to make it more clear to people. Thanks!
k

Kevin Su

03/17/2023, 9:12 PM
Thank you
72 Views