Pull and push DVC data
dvc_syq.py
pulls and pushes DVC data with syq, so you can try syq’s transfers on an
existing DVC repository. It is a short program built on the
Python SDK, meant to be used, read, and adapted. It shares DVC’s
cache and remote, so dvc status, dvc push, and dvc pull treat its results
as their own.
Run it
Install it as a dvc-syq command with uv:
uv tool install 'git+https://github.com/greaber/syq#subdirectory=examples/dvc-syq'
Then, inside a DVC repository:
# Pull one tracked path, or the .dvc file that describes it.
dvc-syq pull models/speech.dvc
# Pull everything tracked under a directory; "-R ." covers the repository.
dvc-syq pull -R datasets
# Download into DVC's cache without touching the workspace.
dvc-syq fetch -R datasets
# Upload what the remote does not have yet.
dvc-syq push models/speech.dvc
uv tool upgrade dvc-syq updates it. You can also run the downloaded file
without installing it: uv run dvc_syq.py pull -R datasets.
These options have the same meaning as in DVC:
| Option | Meaning |
|---|---|
-R, --recursive | Include every .dvc file under a directory target |
-r NAME, --remote NAME | Use this DVC remote instead of the default one |
-f, --force | Let pull replace files you have changed and remove untracked files from tracked directories. Without it, pull stops and lists them |
These are the script’s own:
| Option | Meaning |
|---|---|
--verify | Check downloaded files against their DVC MD5 and reject mismatches |
--dry-run | Show what would be copied |
--syq PATH | Run this syq executable instead of the one installed with the Python package |
How it works
DVC names each object after its MD5, at the same relative path in the cache
and the remote. The script downloads missing objects to the same path in the
cache, then copies each one to the name recorded in its .dvc file:
def object_path(md5):
return f"files/md5/{md5[:2]}/{md5[2:]}"
# Remote to cache: the same path on both sides.
downloads = [MappingEntry(src=object_path(md5), dst=object_path(md5)) for md5 in missing_from_cache]
client.cp(mapping=downloads, from_="s3://my-bucket", into=".dvc/cache", if_exists="keep")
# Cache to workspace: each object gets the name recorded in its .dvc file.
checkout = [MappingEntry(src=object_path(md5), dst=path) for path, md5 in tracked_files]
client.cp(mapping=checkout, cwd=".dvc/cache", into=".")
Each list is a mapping that syq copies in one run. A push is the
first copy in reverse, and if_exists="keep" skips objects the remote already
has. With --verify, each download carries its expected MD5, so syq checks the
file before it enters the cache. Older DVC text objects can have an MD5 of
their newline-normalized contents; the script checks those itself after
download and removes mismatches.
Differences from DVC
- A target is required. DVC pulls or pushes the whole repository when you
name none; here that is
-R .. - Remotes can be local directories,
ssh://host/pathwithout a port, ors3://bucket/prefix. For S3 the script readsprofileandendpointurlfrom the DVC remote and otherwise uses your usual AWS credentials. Remotes with DVC’s cloud versioning are refused. - Data from
dvc importlives in another repository’s remote, so the script skips it; usedvc pullfor it. - DVC options not listed above, such as
--all-branches, are not available.