Create and run your first Metaflow flow in minutes
This quickstart guide will walk you through creating and running your first Metaflow flow. In just a few minutes, you’ll understand the basics of how Metaflow works.
Let’s start with the classic “Hello World” example. Create a new file called helloworld.py:
helloworld.py
from metaflow import FlowSpec, stepclass HelloFlow(FlowSpec): """ A flow where Metaflow prints 'Hi'. Run this flow to validate that Metaflow is installed correctly. """ @step def start(self): """ This is the 'start' step. All flows must have a step named 'start' that is the first step in the flow. """ print("HelloFlow is starting.") self.next(self.hello) @step def hello(self): """ A step for metaflow to introduce itself. """ print("Metaflow says: Hi!") self.next(self.end) @step def end(self): """ This is the 'end' step. All flows must have an 'end' step, which is the last step in the flow. """ print("HelloFlow is all done.")if __name__ == "__main__": HelloFlow()
Flows become interesting when they process data. Let’s create a flow that stores and accesses data:
data_flow.py
from metaflow import FlowSpec, stepclass DataFlow(FlowSpec): """ A flow that demonstrates data artifacts. """ @step def start(self): """ Create some data. """ self.my_data = {"message": "Hello", "count": 42} print(f"Created data: {self.my_data}") self.next(self.process) @step def process(self): """ Access and transform the data. """ print(f"Received data: {self.my_data}") self.result = self.my_data["count"] * 2 self.next(self.end) @step def end(self): """ Display the results. """ print(f"Final result: {self.result}")if __name__ == "__main__": DataFlow()
Key Concept: Any instance variable you set in a step (like self.my_data) is automatically persisted and available in subsequent steps. Metaflow handles all the versioning and storage behind the scenes.