Skip to main content
This page shows you how to download and use an artifact that’s already stored on the W&B server, or construct an artifact object and pass it in for de-duplication. Use these workflows when you need to consume datasets, models, or other versioned files produced earlier in your pipeline, either inside a W&B run or as a standalone operation. Replace placeholders in the code examples with your own values:
  • [PROJECT-NAME]: The name of your W&B project.
  • [JOB-TYPE]: A label describing the type of run, such as training or eval.
Team members with view-only seats can’t download artifacts.

Download and use an artifact stored on W&B

Download and use an artifact stored in W&B either inside or outside a W&B run. Use the Public API (wandb.Api) to export or update data already saved in W&B.
Import the W&B Python SDK, then create a W&B Run:
import wandb

with wandb.init(project="[PROJECT-NAME]", job_type="[JOB-TYPE]") as run:
    # See next step
Indicate the artifact you want to use with the wandb.Run.use_artifact() method. This returns an artifact object. The following code snippet specifies an artifact called bike-dataset with the alias latest:
# Indicate the artifact to use. Format is "name:alias"
artifact = run.use_artifact("bike-dataset:latest")
Use the object returned to download all the contents of the artifact:
# Download the entire artifact
datadir = artifact.download()
You can optionally pass a path to the root parameter to download the contents of the artifact to a specific directory.Use the wandb.Artifact.get_entry() method to download only a subset of files:
# Download a specific file
entry = artifact.get_entry(name)
Putting this together, the complete code example looks like this:
import wandb

with wandb.init(project="[PROJECT-NAME]", job_type="[JOB-TYPE]") as run:
    # Indicate the artifact to use. Format is "name:alias"
    artifact = run.use_artifact("bike-dataset:latest")

    # Download the entire artifact
    datadir = artifact.download()

    # Download a specific file
    entry = artifact.get_entry("bike.png")
This fetches only the file at the path name. It returns an Entry object with the following methods:
  • Entry.download: Downloads the file from the artifact at path name.
  • Entry.ref: Returns the URI if add_reference stored the entry as a reference.

Partially download an artifact

If you only need a subset of an artifact’s contents, download part of an artifact based on a prefix. Use the path_prefix= (wandb.Artifact.download(path_prefix=)) parameter to download a single file or the content of a sub-folder.
with wandb.init(project="[PROJECT-NAME]", job_type="[JOB-TYPE]") as run:
    # Indicate the artifact to use. Format is "name:alias"
    artifact = run.use_artifact("bike-dataset:latest")

    # Download a specific file or sub-folder
    artifact.download(path_prefix="bike.png")  # Downloads only bike.png
Alternatively, you can download files from a certain directory. To do so, specify the directory within the path_prefix= parameter. Continuing from the previous code snippet:
# Downloads files in the images/bikes directory
artifact.download(path_prefix="images/bikes/")

Use an artifact from a different project

Specify the name of the artifact along with its project name to reference an artifact. You can also reference artifacts across entities by specifying the name of the artifact with its entity name. The following code example queries an artifact from another project and uses it as input to the current W&B run.
with wandb.init(project="[PROJECT-NAME]", job_type="[JOB-TYPE]") as run:
    # Query W&B for an artifact from another project and mark it
    # as an input to this run.
    artifact = run.use_artifact("my-project/artifact:alias")

    # Use an artifact from another entity and mark it as an input
    # to this run.
    artifact = run.use_artifact("my-entity/my-project/artifact:alias")

Construct and use an artifact simultaneously

When you want to log an artifact and immediately mark it as an input to the same run, construct and use the artifact in a single step. Create an artifact object and pass it to use_artifact. This creates the artifact in W&B if it doesn’t exist yet. The wandb.Run.use_artifact() API is idempotent, so you can call it as many times as needed.
import wandb

with wandb.init(project="[PROJECT-NAME]", job_type="[JOB-TYPE]") as run:
    artifact = wandb.Artifact("reference model")
    artifact.add_file("model.h5")
    run.use_artifact(artifact)
For more information about constructing an artifact, see Construct an artifact.