Skip to main content

Programmatic Access to Metrics

Created on September 12|Last edited on September 12
If you'd like to query points via the W&B API, you can do so via the following:

Querying sampled points in a run (more performant)

If you'd like to return sampled history metrics for a run, you can do the following (docs):
import wandb

api = wandb.Api()

# access the run object via the api
run = api.run('<entity>/<project>/<run_id>')

# history is a dataframe where each column corresponds to a metric
history = run.history()

Querying all points in a run:

import wandb

api = wandb.Api()

# access the run object via the api
run = api.run('<entity>/<project>/<run_id>')

# full_history is an iterator that yields dictionaries from the run's history, one at a time.
full_history = run.scan_history()

# list of dictionaries where each dictionary represents a single step's data from the run's history.
losses = [row for row in full_history]

Querying a summary metric (final point, best point, min/max)

The last value logged with wandb.log is automatically set as the summary dictionary in a W&B Run.
If you would like to utilize custom summary metrics to capture model performance at the best, min, or max step, check out the docs here.
import wandb


api = wandb.Api()


# access the run object via the api
run = api.run('<entity>/<project>/<run_id>')


# run.summary is a dictionary of the final points in training
run.summary