Skip to main content
Install W&B to track, visualize, and manage machine learning experiments of any size.
Are you looking for information on W&B Weave? See the Weave Python SDK quickstart or Weave TypeScript SDK quickstart.

Sign up and create an API key

To authenticate your machine with W&B, you need an API key. To create an API key, select the Personal API key or Service Account API key tab for details.
To create a personal API key owned by your user ID:
  1. Log in to W&B, then click your user profile icon > User Settings.
  2. Click Create new API key.
  3. Provide a descriptive name for your API key.
  4. Click Create.
  5. Copy the displayed API key immediately and store it securely.
W&B shows the full API key only once, when you create it. After you close the dialog, you cannot view the full API key again. Your settings display only the key ID (the first part of the key). If you lose the full API key, you must create a new one.
For secure storage options, see Store API keys securely.

Install the wandb library and log in

  1. Set the WANDB_API_KEY environment variable:
  2. Install the wandb library and log in:

Initialize a run and track hyperparameters

In your Python script or notebook, initialize a W&B run object with wandb.init(). Use a dictionary for the config parameter to specify hyperparameter names and values. Within the with statement, you can log metrics and other information to W&B.
For a complete example that simulates a training run and logs accuracy and loss metrics to W&B, see Create a machine learning training experiment.
A run is a core element of W&B. You use runs to track metrics, create logs, and track artifacts.

Create a machine learning training experiment

This mock training script logs simulated accuracy and loss metrics to W&B. Copy and paste the following code into a Python script or notebook cell and run it:
Visit your W&B home page to view recorded metrics such as accuracy and loss, and to see how they change during each training step. The following image shows the loss and accuracy tracked from each run. Each run object appears in the Runs column with a generated name.
Loss and accuracy tracked from each run

Next steps

Explore more W&B features:
  • Learn about and create your first run.
  • Track models, datasets, and other files with W&B Artifacts.
  • Automate hyperparameter searches and optimize models with W&B Sweeps.
  • Share models, prompts, and datasets with W&B Registry.
  • Analyze runs, visualize model predictions, and view artifacts in your project’s dashboard.
  • Summarize findings and share updates with collaborators with W&B Reports.
  • Trace and evaluate LLM applications with W&B Weave.