Skip to main content
The W&B Python SDK, accessible at wandb, enables you to train and fine-tune models, and manage models from experimentation to production.
After performing your training and fine-tuning operations with this SDK, you can use the Public API to query and analyze the data that was logged, and the Reports and Workspaces API to generate a web-publishable report summarizing your work.

Sign up and create an API key

To authenticate your machine with W&B, you must first generate an API key at https://wandb.ai/authorize.

Install and import packages

Install the W&B Python SDK using pip:
pip install wandb

Import W&B Python SDK

The following code snippet demonstrates how to import the W&B Python SDK and initialize a run. Replace <team_entity> with your team entity name.
import wandb

# Specify your team entity
entity = "<team_entity>"

# Project that the run is recorded to
project = "my-awesome-project"

with wandb.init(entity=entity, project=project) as run:
   run.log({"accuracy": 0.9, "loss": 0.1})

Python SDK extras

Install optional Python extras to extend the functionality of the W&B Python SDK. Specify the name of the extra you want to install within square brackets after wandb. The syntax is:
pip install wandb[extra]
For example, to install W&B with Google Cloud Storage support, run:
pip install wandb[gcp]
Install more than one optional dependency by separating them with commas:
pip install wandb[gcp,aws,media]
The following table lists Python SDK extras and their suggested use cases.
ExtraPackages includedInstall if you
gcpgoogle-cloud-storageUse gs:// artifact references.
awsboto3, botocoreUse s3:// artifact references.
azureazure-identity, azure-storage-blobUse Azure Blob Storage artifact references.
medianumpy, moviepy, imageio, pillow, bokeh, soundfile, plotly, rdkitLog images, video, audio, or plots from raw data (numpy arrays, tensors).
sweepssweepsRun local sweep controller (wandb.controller()).
workspaceswandb-workspacesProgrammatically manage workspaces.
The following tabs provide more details about each extra, including installation instructions, dependencies, and code examples.
Use the gcp extra if you add reference artifacts that start with gs:// URIs.Installation:
pip install wandb[gcp]
Dependencies:
  • google-cloud-storage
Example:
import wandb

artifact = wandb.Artifact("my-artifact", type="dataset")
artifact.add_reference("gs://bucket/path/to/file")

with wandb.init() as run:
    run.log_artifact(artifact)