skip to content

In DVC, when do you use `dvc get`, `dvc import` or `dvc import-url` to bring data from another repository or a bucket into a project?

level: middleimportance: should knowfreq 12%

answer

  1. download once or keep a link
  2. a repository versus a storage URL
  3. rev and rev_lock
  4. dvc update, not dvc repro
  5. what dvc push skips

basics

~20 s

dvc get copies data from a DVC or Git repository once and tracks nothing. dvc import also writes an import .dvc file pinning the source repo and commit, refreshed by dvc update. dvc import-url does that for a storage URL.

solid answer

~40 s

`dvc get <repo> <path>` is a one-off copy, like `wget` for repositories: no `.dvc` file, no link, and it does not even need a DVC project. `dvc import <repo> <path>` caches the data and writes an import `.dvc` file whose `repo` section records `url`, an optional `rev` and the resolved `rev_lock` commit, so the version is pinned in Git; `dvc update` moves it. `dvc import-url <url>` tracks data at a storage location (`s3://`, `gs://`, `azure://`, `ssh://`, HTTP with an ETag) and records the URL and its checksum. Import stages are frozen, so `dvc repro` never refreshes them. Data from `dvc import` is not pushed to your remote; `dvc pull` gets it from the source. `dvc list` browses a repository first.

code

bash · 13 lines
bash
[email protected]:robotics/lidar-data.git

dvc list "$SRC" lidar-scans --dvc-only        # browse the source's outputs

# pinned, updatable dependency
dvc import "$SRC" lidar-scans/aisle-07 --rev v2.1 -o data/aisle-07
git add data/aisle-07.dvc && git commit -m "Import aisle-07 lidar scans at v2.1"

# later: move the pin to a newer tag
dvc update --rev v2.2 data/aisle-07.dvc

# one-off copy, nothing tracked
dvc get "$SRC" lidar-scans/aisle-07 -o /tmp/aisle-07

go deeper

for a junior

Recall the three commands: get downloads and forgets, import downloads and records a link to a repository, import-url records a link to a storage URL.

for a middle

Explain the import .dvc file's repo section, rev against rev_lock, why imports are frozen, and how dvc update and dvc status treat them.

for a senior

Anticipate where imported bytes come from on pull, and pin imports to tags or commits so a consuming project's history reproduces the exact data version.

for a principal

Decide when a central data repository consumed through dvc import beats copying data into each project, and what access every consumer then needs.

## The situation A second repository's data engineers need one directory, `lidar-scans/aisle-07`, from the robotics team's DVC project. DVC offers three ways to bring data in, and they differ in what they record and how the data is refreshed. ## Browse first with dvc list `dvc list <repo> [path]` (alias `dvc ls`) shows both Git-tracked files and DVC-tracked outputs of a repository, which a code-hosting page alone does not. `--dvc-only` shows only DVC outputs, `-R` recurses, `--rev` lists another revision. It does not check that the data actually exists in the source's remote storage, so a listed path can still fail to download. ## The three commands | | `dvc get` | `dvc import` | `dvc import-url` | |---|---|---|---| | Source | a DVC or Git repository | a DVC or Git repository | a storage URL or path | | Writes a `.dvc` file | no | yes, with a `repo` section | yes, with the URL as a dependency | | Needs a DVC project | no | yes | yes | | Refresh | run it again | `dvc update` | `dvc update` | | `dvc push` to your remote | nothing tracked | skipped; pulled from the source | pushed like any output | - **`dvc get`** copies a file or directory into the current directory with its original name (or `-o`). `--rev` picks a revision; `--show-url` prints the storage location instead of downloading. Because nothing is recorded, nobody can later tell which version arrived. - **`dvc import`** downloads, caches and links the data, then writes an import `.dvc` file. Its `deps` entry holds the source `path` and a `repo` section with `url`, `rev` if `--rev` was given, and `rev_lock`, the exact commit resolved at import time; `outs` holds the local path and hash. Commit that file and the version is pinned for everyone. - **`dvc import-url`** does the same for data outside any DVC repository: `s3://`, `gs://`, `azure://`, `ssh://`, `hdfs://`, `http(s)://`, `webdav(s)://` or a local path. The `deps` entry records the URL and a checksum such as an ETag. HTTP, HDFS, WebHDFS and WebDAV sources accept single files only, and an HTTP source needs an ETag for change detection. `--to-remote` streams the data straight into your remote without keeping a local copy. ## What the import file records After the `dvc import ... --rev v2.1 -o data/aisle-07` shown below, `data/aisle-07.dvc` looks roughly like this (hashes shortened): ```yaml frozen: true deps: - path: lidar-scans/aisle-07 repo: url: [email protected]:robotics/lidar-data.git rev: v2.1 rev_lock: 9c1e4f... outs: - md5: 4b7d02....dir path: aisle-07 cache: true ``` `frozen: true` is what keeps `dvc repro` away from it, `rev` is what was asked for, and `rev_lock` is the commit it resolved to. The `outs` hash ends in `.dir` because the output is a directory. Committing this one file is what pins the dataset version in the consuming repository's history. ## Refreshing an import Import stages are **frozen**: `dvc repro` does not check or update them. Instead: 1. `dvc status` reports `update available` when the source has moved on (`--no-updates` skips that check). 2. `dvc update <file>.dvc` re-resolves the source and rewrites `rev_lock` and the hashes. 3. If `rev` is a branch or tag, a plain `dvc update` follows it. If `rev` is a commit hash, a plain `dvc update` changes nothing; `dvc update --rev <new>` moves the pin. ## Where imported bytes come from later - A source repository needs a **default remote** that holds the target data; a local source repository is the exception, where DVC tries its cache first. - Data from `dvc import` is **not** pushed to the consuming project's remote. A later `dvc pull` downloads it from the source repository's storage, so every consumer needs read access there. - Data from `dvc import-url` is cached like an ordinary output and can be pushed and pulled through your own remote. ## Choosing - A one-off look, a script that needs a file, or a machine without a DVC project: `dvc get`. - A dependency whose version must be reproducible from the consuming repo's history: `dvc import`, pinned with `--rev`. - Data produced outside DVC, such as a nightly export dropped in a bucket: `dvc import-url`. The choice is about the link you want to keep. `dvc get` keeps none, `dvc import` keeps a link to a repository and a commit, and `dvc import-url` keeps a link to a storage location and its checksum.

  • What do `rev` and `rev_lock` record in an import `.dvc` file?
    `rev` is what you asked for with `--rev`: a branch, tag or commit. `rev_lock` is the exact commit DVC resolved at import or update time, so everyone pulls the same version. `dvc update` re-resolves `rev` and rewrites `rev_lock`; if `rev` is a commit hash, only `dvc update --rev` moves it.
  • The source team pushed new scans, but `dvc repro` in the consuming project changed nothing. Why?
    Import stages are frozen, so `dvc repro` never checks or updates them. `dvc status` reports `update available` for the import, and `dvc update` on its `.dvc` file brings in the new version and rewrites `rev_lock`.
  • When is `dvc import-url --to-remote` the right call?
    When you want to track a large external dataset without storing it on the current machine. DVC writes the import `.dvc` file and transfers the data directly into your remote; anyone who needs it runs `dvc pull` later.

  • dvc get creates a .dvc file so the download can be updated later
  • dvc import reads straight from an s3:// bucket URL
  • dvc repro picks up new versions of imported data
  • dvc list guarantees the listed data can be downloaded
  • Data from dvc import is pushed to your own remote like any output