Import a function from one python file and use that function as a step function in metaflow

I have a function sayHello defined in one python file I also have a python file that runs a simple metaflow. I want to import sayHello from and use sayHello as a step function in Is it possible to do that? This might be hard because we need self in the class. If it’s possible, one question is that we how do pass output from the previous step into the function and pass the output to next step. The following is my attempt.
def sayHello():
    print("hello world")
from metaflow import FlowSpec, step, Parameter
from metaflow import Metaflow
from utils import sayHello

def function(p):
    return p

class BranchFlow(FlowSpec):
    def start(self):, self.b, self.sayHello)

    def a(self):
        self.x = 1

    def b(self):
        self.x = 2

    def join(self, inputs):
        print('a is %s' % inputs.a.x)
        print('b is %s' % inputs.b.x)
        print('total is %d' % sum(input.x for input in inputs))

    def end(self):

if __name__ == '__main__':

>Solution :

According to the documentation for, the method you pass to must be a member of the current class and decorated with @step.

Probably the easiest way to use another function from another module is to wrap it in a member function:

class BranchFlow(FlowSpec):
    # ...

    def sayHello(self):

Now you can do

Leave a Reply