Weights & Biases Workspaces

0.3.9 · active · verified Thu Apr 16

wandb-workspaces is a Python library designed for programmatic interaction with the Weights & Biases (W&B) UI, specifically for creating, modifying, and sharing W&B Reports and Workspaces. It allows users to define complex data visualizations, organize runs into runsets, and manage report layouts directly from Python code. The current version is 0.3.9, with a frequent release cadence, typically releasing minor bug fixes and new features every few weeks. This feature is in Public Preview.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to create a basic Weights & Biases Report with a title, description, and a grid of common panels (LinePlot, BarPlot, ScalarChart). It emphasizes the need for W&B authentication and proper import paths.

import os
import wandb
from wandb_workspaces.reports import Report, H1, P, PanelGrid
from wandb_workspaces.panels import LinePlot, BarPlot, ScalarChart

# Ensure you are logged into W&B (e.g., via `wandb login` or WANDB_API_KEY env var)
# For a runnable example, ensure WANDB_API_KEY is set in your environment
# os.environ['WANDB_API_KEY'] = 'YOUR_API_KEY' 
# os.environ['WANDB_ENTITY'] = 'your-entity'
# os.environ['WANDB_PROJECT'] = 'your-project'

entity = os.environ.get('WANDB_ENTITY', 'your-entity') # Replace with your W&B entity
project = os.environ.get('WANDB_PROJECT', 'your-project') # Replace with your W&B project

# Initialize a dummy W&B run to ensure authentication if not already logged in
# Not strictly necessary for report creation if API key is set, but good practice.
# try:
#     wandb.init(project=project, entity=entity, mode='offline')
# finally:
#     wandb.finish()


# Create a W&B Report
report = Report(
    entity=entity,
    project=project,
    title="My Programmatic Report Example",
    description="A report created entirely with wandb-workspaces."
)

# Add blocks and panels to the report
report.blocks = [
    H1("Introduction"),
    P("This report demonstrates how to programmatically generate W&B reports with various visualizations."),
    H1("Key Metrics"),
    PanelGrid(
        panels=[
            LinePlot(x="Step", y=["val_loss", "train_loss"], title="Loss Over Steps"),
            BarPlot(metrics=["val_accuracy"], title="Validation Accuracy"),
            ScalarChart(metric="f1_score", groupby_aggfunc="mean", title="Mean F1 Score")
        ]
    )
]

# Save the report
report.save()

print(f"Report saved: {report.url}")

view raw JSON →