Daniel Hurst
02/10/2025, 4:33 PMMarvin
02/10/2025, 4:33 PMpython
from prefect import flow, task
class MyFlow:
def __init__(self, dependency):
self.dependency = dependency
@task
def my_task(self, x):
return self.dependency.process(x)
@flow
def my_flow(self, data):
results = []
for item in data:
result = self.my_task(item)
results.append(result)
return results
# Usage
class Dependency:
def process(self, x):
return x * 2
dependency = Dependency()
my_flow_instance = MyFlow(dependency)
result = my_flow_instance.my_flow([1, 2, 3])
print(result)
In this example, Dependency
is a class that provides some processing logic, which is injected into MyFlow
. The my_flow
method orchestrates the execution of my_task
.
For more details on Prefect's capabilities, you can explore their GitHub repository or the Prefect documentation.Bring your towel and join one of the fastest growing data communities. Welcome to our second-generation open source orchestration platform, a completely rethought approach to dataflow automation.
Powered by