Run the first flow
After you have configured access to the platform, let's run a simple Metaflow flow to confirm that everything works.
If you are new to Metaflow, take a quick look at the Metaflow documentation. All features of Metaflow work on Outerbounds.
Save the following code snippet in a file, hello.py
from metaflow import FlowSpec, step
class HelloFlow(FlowSpec):
@step
def start(self):
print("Hello world! 👋")
self.next(self.end)
@step
def end(self):
pass
if __name__ == "__main__":
HelloFlow()
and execute it as follows:
# python hello.py run
If you see Hello World!
in the output, congratulations! You just ran your first flow
successfully.
In the output, you should see a link to the Runs view
which shows all executions, both prototyping and production, taking place on the platform.
You can click the latest HelloFlow
run to explore information about the run that you
just executed.
Hello artifacts​
Extend the above example with the following lines, storing data in self.
variables
that are persisted automatically as artifacts which
are a core concept of Metaflow.
from metaflow import FlowSpec, step, card
class HelloFlow(FlowSpec):
@card
@step
def start(self):
self.greeting = "Hello world!"
self.x = 1
self.next(self.end)
@card
@step
def end(self):
print(self.greeting)
self.x += 10
print("x is", self.x)
if __name__ == "__main__":
HelloFlow()
Note how we refer to the variables self.x
and self.greeting
both in the start
and end
steps. By design, this doesn't seem that special but notably the steps could execute on
separate cloud instances, as we will see when executing the code in the cloud. The data is moved automatically between steps and stored for later inspection.
Run the flow as before
# python hello.py run
Check the the Runs view again for the latest run.
Navigate to the start
task and observe a new card section in the task view, as shown
in this clip:
The card section is produced by the @card
decorator that allows you to attach custom visualizations in the UI. Note how
the card shows how the value of x
changes between the start
and end
steps - Metaflow
versions data automatically. You can use this feature to track metrics, models, dataframes, or any other data across prototypes and production runs.
If you are feeling adventurous, you can explore various options for visualizing artifacts
through cards. Feel free to
hack HelloFlow
freely - you can't break anything!