Public API
3 minute read
The W&B Public API provides programmatic access to query, export, and update data stored in W&B. Use this API for post-hoc analysis, data export, and programmatic management of runs, artifacts, and sweeps. While the main SDK handles real-time logging during training, the Public API enables you to retrieve historical data, update metadata, manage artifacts, and perform analysis on completed experiments. The main Api
class serves as the entry point to most functionality.
Training and fine-tuning models is done elsewhere in the W&B Python SDK. Use the Public API for querying and managing data after it has been logged to W&B.
Available Components
Component | Description |
---|---|
Api |
Main entry point for the Public API. Query runs, projects, and artifacts across your organization. |
Runs |
Access and manage individual training runs, including history, logs, and metrics. |
Artifacts |
Query and download model artifacts, datasets, and other versioned files. |
Sweeps |
Access hyperparameter sweep data and analyze optimization results. |
Projects |
Manage projects and access project-level metadata and settings. |
Reports |
Programmatically access and manage W&B Reports. |
Teams |
Query team information and manage team-level resources. |
Users |
Access user profiles and user-specific data. |
Files |
Download and manage files associated with runs. |
History |
Access detailed time-series metrics logged during training. |
Automations |
Manage automated workflows and actions. |
Integrations |
Configure and manage third-party integrations. |
Common Use Cases
Data Export and Analysis
- Export run history as DataFrames for analysis in Jupyter notebooks
- Download metrics for custom visualization or reporting
- Aggregate results across multiple experiments
Post-Hoc Updates
- Update run metadata after completion
- Add tags or notes to completed experiments
- Modify run configurations or summaries
Artifact Management
- Query artifacts by version or alias
- Download model checkpoints programmatically
- Track artifact lineage and dependencies
Sweep Analysis
- Access sweep results and best performing runs
- Export hyperparameter search results
- Analyze parameter importance
Authentication
The Public API uses the same authentication mechanism as the Python SDK. You can authenticate in several ways:
Use the WANDB_API_KEY
environment variable to set your API key:
export WANDB_API_KEY=your_api_key
Pass the API key directly when initializing the Api
class:
api = Api(api_key="your_api_key")
Or use wandb.login()
to authenticate the current session:
import wandb
wandb.login()
api = Api()
Example Usage
Download an Artifact by name and alias
The following example shows how to retrieve an artifact logged to W&B by its name and alias, and then download its contents.
import wandb
api = wandb.Api()
artifact = api.artifact("entity/project/artifact:alias")
artifact.download()
Download an Artifact from a registry
The following example shows how to retrieve a linked artifact from a W&B Registry
import wandb
REGISTRY = "<registry_name>"
COLLECTION = "<collection_name>"
VERSION = "<version>"
api = wandb.Api()
artifact_name = f"wandb-registry-{REGISTRY}/{COLLECTION}:{VERSION}"
# Fetch the artifact
fetched_artifact = api.artifact(name = artifact_name)
# Download artifact. Returns path to downloaded contents
downloaded_path = fetched_artifact.download()
Query W&B Registry
Use Mongo-like filters to query W&B Registries, Collections, and Artifacts. The following example demonstrates how to filter collections by name using a regular expression.
import wandb
# Initialize wandb API
api = wandb.Api()
# Filter all collections, independent of registry, that
# contains the string `yolo` in the collection name
collection_filters = {
"name": {"$regex": "yolo"}
}
# Returns an iterable of all collections that match the filters
collections = api.registries().collections(filter=collection_filters)
For more information on how to query a registry, collection, or artifact, see the Find registry items.
Feedback
Was this page helpful?
Glad to hear it! If you have more to say, please let us know.
Sorry to hear that. Please tell us how we can improve.