https://prefect.io logo
#prefect-community
Title
# prefect-community
e

eddy davies

01/11/2023, 3:56 PM
From reading other messages I am aware the statefulness classes does not work well with class method as tasks or flows. I have however written my python code using classes, I like them for keeping my code in manageable segments. As long as I do not need to pass any self attributes from when task to another I assume I am ok to use a class? I am thinking I have a separate
prefect-flow.py
file that imports my class. Should I create an instance in the flow and pass to each task? Or create a class instance in each task?
n

Nate

01/11/2023, 4:30 PM
Hey @eddy davies! Could you provide an example of what you mean by this?
the statefulness classes does not work well with class method as tasks or flows
I'm not sure what you mean by
statefulness classes
a

Anna Geller

01/11/2023, 4:49 PM
Eddy, you may consider creating a custom block if you need to store some configuration to external system that needs to be reused across various methods
e

eddy davies

01/11/2023, 4:56 PM
@Nate Sorry, I meant “statefulness of classes”. I am just referring to this discussion. @Anna Geller Good idea if I need to pass something between tasks.
🙌 1
n

Nate

01/11/2023, 5:06 PM
Ahh gotcha, thanks for the context I would recommend importing your class into your file where your flow will be defined, and wrapping useful calls of class's methods with
@task
or
@flow
when you need orchestration on some of your class functionality
💙 1
🎯 1
e

eddy davies

01/11/2023, 6:08 PM
perfect prefect advise, just the conclusion i was coming to, just wanted some reassurance, much appreciated
👍 1
3 Views