This page describes how to update the description, metadata, and alias of an existing artifact. Update an artifact when you want to refine its documentation, adjust its metadata, or manage its aliases without creating a new version. To update an artifact from a previously logged run, use the W&B Public API (wandb.Api). To update an artifact while its run is still active, use the wandb.Artifact class and call Artifact.save().
When to use wandb.Artifact.save() or wandb.Run.log_artifact()
- Use
Artifact.save() to update an existing artifact without starting a new run.
- Use
wandb.Run.log_artifact() to create a new artifact and associate it with a specific run.
Choose the approach that matches your workflow. Use the W&B Public API (wandb.Api) to update an artifact outside of a run, or use the wandb.Artifact class while a run is active.
You can’t update the alias of an artifact linked to a model in Model Registry.
During a run
W&B Public API
With collections
The following code example shows how to update the description of an artifact with the wandb.Artifact API:import wandb
with wandb.init(project="[EXAMPLE]") as run:
artifact = run.use_artifact("[ARTIFACT-NAME]:[ALIAS]")
artifact.description = "[DESCRIPTION]"
artifact.save()
The following example updates an artifact with wandb.Api:import wandb
api = wandb.Api()
artifact = api.artifact("entity/project/artifact:alias")
# Update the description
artifact.description = "My new description"
# Selectively update metadata keys
artifact.metadata["oldKey"] = "new value"
# Replace the metadata entirely
artifact.metadata = {"newKey": "new value"}
# Add an alias
artifact.aliases.append("best")
# Remove an alias
artifact.aliases.remove("latest")
# Replace the aliases
artifact.aliases = ["replaced"]
# Persist all artifact modifications
artifact.save()
For more information, see the W&B Artifact API. You can also update an artifact collection the same way as a singular artifact. The following example renames a collection and updates its description:import wandb
with wandb.init(project="[EXAMPLE]") as run:
api = wandb.Api()
artifact = api.artifact_collection(type="[TYPE-NAME]", collection="[COLLECTION-NAME]")
artifact.name = "[NEW-COLLECTION-NAME]"
artifact.description = "[COLLECTION-DESCRIPTION]"
artifact.save()
For more information, see the Artifacts Collection reference.