-
Hi. I know how to download a dandiset from the command line, but what if I want to do it inside another python script? I am currently doing the following... os.system("dandi download https://dandiarchive.org/dandiset/000140 -o /path/to/my/datasets/") But is there a cleaner way to do it? I was hoping for something like this: import dandi
data_url = "https://dandiarchive.org/dandiset/000140"
dandi.download(data_url, output="path/to/my/datasets/") |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
here is an example: from dandi.dandiapi import DandiAPIClient
from pathlib import Path
api = DandiAPIClient("https://api.dandiarchive.org/api")
ds = api.get_dandiset("000140")
for asset in ds.get_assets(order="path"):
break
Path(asset.path).parent.mkdir()
asset.download(asset.path) for full reference of asset see: https://dandi.readthedocs.io/en/latest/modref/dandiapi.html#dandi.dandiapi.BaseRemoteAsset.download |
Beta Was this translation helpful? Give feedback.
-
with "mid-layer" DandiAPIClient you can indeed have most of the flexibility for coding your own scripts, but might need to code your logic for incremental updates (if to do) etc. But if you just want to really do what CLI is doing, use lena:/tmp
$> python -c 'from dandi.download import download; download("https://dandiarchive.org/dandiset/000027", output_dir="/tmp/")'
PATH SIZE DONE DONE% CHECKSUM STATUS MESSAGE
dandiset.yaml done updated
sub-RAT123/sub-RAT123.nwb 18.8 kB 18.8 kB 100% ok done
Summary: 18.8 kB 18.8 kB 2 done 1 updated
100.00%
$> ls -l 000027
total 8
-rw------- 1 yoh yoh 2711 Jan 17 11:22 dandiset.yaml
drwx------ 2 yoh yoh 4096 Jun 1 14:06 sub-RAT123/ |
Beta Was this translation helpful? Give feedback.
here is an example:
for full reference of asset see: https://dandi.readthedocs.io/en/latest/modref/dandiapi.html#dandi.dandiapi.BaseRemoteAsset.download