Beginner

Setup & Configuration

Install the W&B Python SDK, authenticate with your API key, and log your first experiment in under 5 minutes.

Installation

Bash — Install W&B
# Install via pip
pip install wandb

# Or with conda
conda install -c conda-forge wandb

# Verify installation
wandb --version

Authentication

Bash — Login to W&B
# Interactive login (opens browser)
wandb login

# Or set API key directly
export WANDB_API_KEY="your-api-key-here"

# Or pass in Python
import wandb
wandb.login(key="your-api-key-here")
💡
Get your API key: Sign up at wandb.ai/authorize to get your free API key. It's stored locally at ~/.netrc after the first login.

Your First Experiment

Python — Complete first experiment
import wandb
import random
import math

# Initialize a new run
run = wandb.init(
    project="my-first-project",   # project name
    name="baseline-experiment",    # run name (optional)
    config={                       # hyperparameters
        "learning_rate": 0.01,
        "epochs": 50,
        "batch_size": 32,
        "architecture": "CNN",
        "dataset": "CIFAR-10"
    }
)

# Access config
config = wandb.config

# Simulate training
for epoch in range(config.epochs):
    train_loss = math.exp(-epoch / 20) + random.gauss(0, 0.05)
    val_loss = math.exp(-epoch / 25) + random.gauss(0, 0.08)
    accuracy = 1 - math.exp(-epoch / 15) + random.gauss(0, 0.02)

    # Log metrics
    wandb.log({
        "epoch": epoch,
        "train/loss": train_loss,
        "val/loss": val_loss,
        "val/accuracy": max(0, min(1, accuracy)),
    })

# Finish the run
wandb.finish()

wandb.init() Parameters

ParameterDescriptionExample
projectGroup runs into a project"image-classification"
nameHuman-readable run name"resnet50-lr0.001"
configHyperparameters dict{"lr": 0.001, "epochs": 100}
tagsTags for filtering["baseline", "v2"]
groupGroup related runs"experiment-1"
notesFree-form notes"Testing new augmentation"
mode"online", "offline", "disabled""offline" for no internet

Offline Mode

Python — Running without internet
# Option 1: Environment variable
import os
os.environ["WANDB_MODE"] = "offline"

# Option 2: In code
wandb.init(mode="offline")

# Later, sync offline runs
# $ wandb sync ./wandb/offline-run-*
Best practice: Always use wandb.init() with a config dictionary containing all hyperparameters. This makes runs reproducible and enables the Sweeps feature to automatically tune them later.