> ## Documentation Index
> Fetch the complete documentation index at: https://wb-21fd5541-codex-link-agent-evals-docs.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

> Download and use Artifacts from multiple projects.

# Download and use artifacts

Download and use an artifact that is already stored on the W\&B server or construct an artifact object and pass it in for de-duplication as necessary.

<Note>
  Team members with a Models **Viewer** seat cannot download artifacts.
</Note>

### Download and use an artifact stored on W\&B

Download an artifact as a tracked run input when it is a run dependency, or fetch it directly for workflows that don’t require lineage tracking.

<Info>
  References that have schemes that W\&B knows how to handle get downloaded just like artifact files. For more information, see [Track external files](/models/artifacts/track-external-files/).
</Info>

You can download all files in an artifact or download individual files:

* Use [`Artifact.download()`](/models/ref/python/experiments/artifact#download) to download all files.
* Use [`Artifact.get_entry()`](/models/ref/python/experiments/artifact#get_entry) to retrieve a specific entry, and then call `.download()` to download it.

<Tabs>
  <Tab title="Track run input">
    Use `wandb.Run.use_artifact()` to download an artifact as part of a W\&B run. W\&B records the artifact as an input to the run.

    1. Import the W\&B Python SDK and initialize a W\&B [Run](/models/ref/python/experiments/run).
    2. Retrieve the artifact version with `wandb.Run.use_artifact()`.
    3. Download all files or a specific file from the returned `Artifact` object.

    ```python theme={null}
    import wandb    

    with wandb.init(project="<example>", 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")
        file_path = entry.download() # downloads only bike.png
    ```
  </Tab>

  <Tab title="Fetch directly">
    Use the Public API to download an artifact without creating a run or recording a run input relationship.

    1. Import the W\&B Python SDK and create a client object with `wandb.Api()`.
    2. Retrieve the artifact version with `wandb.Api.artifact()`.
    3. Download all files or a specific file from the returned `Artifact` object.

    Specify the artifact path in the format `entity/project/artifact:alias`.

    ```python theme={null}
    import wandb

    api = wandb.Api()
    artifact = api.artifact("entity/project/artifact:alias")
    artifact.download()
    ```
  </Tab>

  <Tab title="W&B CLI">
    Use the `wandb artifact get` command to download an artifact from the W\&B server.

    ```
    $ wandb artifact get project/artifact:alias --root mnist/
    ```
  </Tab>
</Tabs>

### Partially download an artifact

You can optionally 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.

```python theme={null}
with wandb.init(project="<example>", 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:

```python theme={null}
# 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 demonstrates how to query an artifact from another project as input to the current W\&B run.

```python theme={null}
with wandb.init(project="<example>", 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

Simultaneously construct and use an artifact. Create an artifact object and pass it to use\_artifact. This creates an artifact in W\&B if it does not exist yet. The [`wandb.Run.use_artifact()`](/models/ref/python/experiments/run#use_artifact) API is idempotent, so you can call it as many times as you like.

```python theme={null}
import wandb

with wandb.init(project="<example>", 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](/models/artifacts/construct-an-artifact/).
