Hi, I have a simple question: From the Flyte docum...
# ask-the-community
x
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
you means using classes as task input / output ?
x
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
why do you want use task or workflow in the class?
x
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
do you mind share some examples of your classes? I’m thinking how to easily convert your class to flyte task.
x
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
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
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
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
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
Thank you
154 Views