@card decorator adds progress bars, metrics, and charts to a step and updates them while the step runs, without needing to set up a separate service. You can watch the card while the step progresses. Because the card is stored with the task, it still shows what the step reported after the run finishes, so it can’t drift from the code that produced it.

Prerequisites
Before you begin, make sure you have the following:-
A macOS or Linux machine, or a cloud workstation.
Metaflow is built for macOS and Linux. Windows machines require Windows Subsystem for Linux (WSL) to run Metaflow.
-
The
outerboundspackage installed and connected to your platform. - Access to a compute pool for running Metaflow Tasks.
How cards work
By default, adding the@card decorator to a step produces a visual report of the step after it finishes. However, you can instruct your flow to update the card as the step runs, allowing you to watch the step complete in real time. You can view the card in the Runs view, or in Metaflow’s local card viewer, which shows cards in your browser without the platform UI.
Cards display components that you configure, such as blocks of text, progress bars, and charts. Each component is a Python object that you create in your step’s code.
To configure a card to update while a step runs:
1
Attach a card to the step
@card(type="blank") attaches an empty card that you fill with components. Without type="blank", Metaflow uses the default card, which also lists the step’s artifacts.2
Add components to the card
There are two methods for adding components to your card:
current.card.append(<COMPONENT>)adds one componentcurrent.card.extend([<COMPONENT_1>, <COMPONENT_2>])adds a list of components
3
Update component values
Each component has its own
update() method, which sets a new value for that component, such as a progress bar’s position or the text in a Markdown block. Call it from the loop or callback where your step does its work.4
Refresh the card
New values received from calling
update() stay in your step’s memory until you refresh the card. current.card.refresh() sends the current state of every component to the viewer. Call it after your updates, in the same loop.Minimal training loop example
Building a step that updates its card
In this section, you’ll create two files: a module that builds and updates the card during XGBoost training and the flow that uses it.1
Create a project directory
Create a directory for the tutorial and navigate to it:Metaflow packages every Python file in this directory with your flow, so the flow can import the module you create next, both locally and in the cloud.
2
Create the card callback
XGBoost calls a training callback after every boosting round, along with the latest evaluation scores. That makes a callback a natural place to update the card. Create a file named The file defines two callbacks:
live_card.py with the following contents:live_card.py
CardUpdater: Builds the card and keeps it current. The highlighted lines are where it works with the card:- When training starts, it creates the four components, adds them to the card with
current.card.extend(), and callsrefresh()so the card appears before the first round finishes. - After each round, it adds the latest training and validation loss to the chart’s data, calls
update()on each component, and then callsrefresh(). - When training ends, it updates the status heading with the total training time.
- When training starts, it creates the four components, adds them to the card with
SlowDown: Pauses after each round so that training lasts about two minutes, long enough to watch the card change. The sample dataset trains in seconds on most machines. Leave this callback out of your own projects.
3
Create the flow
Create a file named The flow has two parameters you can change on the command line.
live_card_flow.py with the following contents:live_card_flow.py
--rounds sets the total number of boosting rounds, and --pause sets the seconds to wait after each round. The default pause of 0.2 seconds makes the run last about two minutes. Set --pause 0 to disable it.The highlighted lines connect the card to training:@card(type="blank", id="training", refresh_interval=1)attaches an empty card to thetrainstep that updates at most once per second. Theidgives the card a name, which the Runs view uses as the card’s tab label.- The
callbackslist passesCardUpdaterto XGBoost, along withSlowDownunless you set--pause 0. - The
evalsargument tells XGBoost to score the model on the training and validation data after every round. Those scores arrive in the callback asevals_log, a dictionary keyed by dataset name and then by metric name.
start step generates a sample classification dataset with scikit-learn and splits it into training and validation sets. @anaconda_base declares the packages every step needs, sourced from Anaconda’s main channel. After training, Metaflow saves self.model as an artifact of the train task, which you can load later with the Client API.live-card-tutorial directory now contains live_card.py and live_card_flow.py.
Watching the card locally
Metaflow includes a local card viewer that shows cards in your browser as a flow runs. It’s the quickest way to check a card while you’re developing it.1
Start the card viewer
From the The viewer follows the latest run of
live-card-tutorial directory, start the card viewer:LiveCardFlow and switches to each new run automatically when it starts. The --poll-interval 1 option checks for card updates every second instead of every five seconds.Leave the viewer running, and open http://localhost:8324 in your browser.2
Run the flow
Open a second terminal, navigate to the
live-card-tutorial directory, and run the flow:3
Watch the card update
When the
train step starts, return to your browser. The viewer shows the card for the train task and updates it every second as training progresses.As the card updates, watch the two lines on the chart. Training loss keeps falling for the whole run, but validation loss flattens out near 0.09 within the first hundred rounds, and the gap between the two lines keeps growing. The Best validation log loss box stops changing at round 194 and holds that score for the rest of the run, with Round 194 underneath. The growing gap is the model learning details of the training data that don’t carry over to new data. In a real training job, a card like this tells you while the job is still running that the remaining rounds won’t improve the model, so you can stop early or adjust your settings.Expected result: The card shows Training finished in followed by the total time, and the progress bar shows 500/500. In the second terminal, the run ends with Trained 500 rounds.When you’re done, press Ctrl+C in the first terminal to stop the card viewer.Watching the card in the cloud
The card works the same way when the step runs on cloud compute. The task sends card updates to your platform’s storage as it runs, and the Runs view shows them, so you can check on a long training job from anywhere without keeping a terminal open.1
Run the flow on cloud compute
Run the same flow on cloud compute. You don’t need to change any code:Anaconda Platform builds the environment into a container image and runs each step in its own container on the cluster. The first run takes a few minutes while the image builds and the cluster starts the containers.
2
Open the card in the Runs view
When the output shows that the 
Expected result: The training card shows the same components as in the local viewer and updates while the task runs. After the run finishes, the card stays with the task, so you can return to it at any time to see how training went.
train step has started, follow the link printed at the start of the run to view it in the UI. Select the train task, then select the Cards tab.
Tutorial wrap up
You’ve built a card that reports on training while it happens. The card showed training progress, the best validation score, and the loss curves as each round finished, first in the local card viewer and then in the Runs view while the step ran on cloud compute. What you learned- How a card behaves differently when you update it while a step runs
- How to add components to a card with
current.card.extend()and keep them current withupdate()andcurrent.card.refresh() - How to use a training callback to update a card after every round
- How to watch cards locally with the card viewer and in the Runs view
- How a chart of the loss curves shows when more training stops helping
- The dynamic card gallery includes
monitor-callback, which uses the same callback pattern as this tutorial. It also shows work in separate threads and subprocesses, and charts built with Altair. - Card templates explain how to build fully custom cards with any JavaScript library and share them as Python packages. The 3D scatter plot card is a starter template for a custom card.
- Training models that recover from interruptions shows how to resume a failed training step from its latest checkpoint, which pairs well with an updating card on long training jobs.