Repository navigation
Development Download Internals
How npdb download turns a Neurobagel query-results TSV into files on disk. User instructions: docs/download-data.md.
sequenceDiagram
actor User
participant CLI as npdb download
participant TSV as Query-results TSV
participant HTTP as HTTP server
participant Git as NeuroData / Git
participant Annex as git-annex
participant Disk as Output folder
User->>CLI: query.tsv + options
CLI->>TSV: Read and group rows
loop Each dataset with AccessLink
CLI->>HTTP: Download each unique URL (parallel)
HTTP-->>Disk: File under dataset/subject
end
loop Each dataset without HTTP links
CLI->>Git: Sparse checkout selected paths
Git-->>Disk: Repository metadata and selected files
opt git-annex branch exists
CLI->>Annex: Retrieve annexed content
Annex-->>Disk: Imaging file contents
end
end
CLI-->>User: Summary and exit status

The TSV exported from the Neurobagel query tool has one row per subject and session. npdb download uses:
| Column | Used for |
|---|---|
DatasetName |
Output sub-folder and grouping. |
SubjectID |
Output sub-folder (HTTP) and sparse checkout. |
AccessLink |
Direct HTTP(S) download when it is a valid URL. |
RepositoryURL |
Git clone URL when no HTTP link exists for the dataset. |
ImagingSessionPath |
Path of the session inside the repository, used for sparse checkout. |
The backend is chosen per dataset, so one TSV can mix backends:
-
HTTP. If
AccessLinkholds a valid HTTP(S) URL, the dataset is downloaded withhttpx. Each unique URL is fetched once into<output>/<DatasetName>/<SubjectID>/<filename>, in parallel (--max-workers, default 4). -
Git. Otherwise, the repository at
RepositoryURLis cloned with sparse checkout, limited to theImagingSessionPathof the selected rows. Derivatives linked to those subjects are included by default (--no-derivativesto skip). -
Git-annex. If the repository has a
git-annexbranch, annexed file content is retrieved after the git checkout (requiresgit-annexonPATH).
Datasets with neither a valid AccessLink nor RepositoryURL + ImagingSessionPath are skipped.
Git and git-annex downloads go through the NeuroData manager and need, in .env (current folder first, then the repository root) or the environment:
NP_GITEA_APP_URL=https://data.neuro.polymtl.ca
NP_GITEA_APP_USER=<username>
NP_GITEA_APP_TOKEN=<token>HTTP downloads need no credentials.
--no-verify-ssl is currently required for NeuroData because the server's certificate chain is not trusted by default clients. The risk is mitigated by the mandatory VPN. NP_GITEA_APP_VERIFY_SSL in template.env is not read by the CLI; only the flag counts. Remove this requirement from the user docs once the chain of trust is fixed.
| Option | Default | Effect |
|---|---|---|
--output-dir, -o
|
current directory | Where files are written. |
--derivatives / --no-derivatives |
derivatives | Include derivatives (git mode). |
--max-workers |
4 | Parallel HTTP downloads. |
--verify-ssl / --no-verify-ssl |
verify | SSL verification towards NeuroData (git mode). |
--verbose, -v
|
off | Print each git command before it runs. |
# Typical user run
npdb download --no-verify-ssl results.tsv -o ./my-cohort
# Raw data only, show git commands
npdb download --no-verify-ssl --no-derivatives -v results.tsv -o ./my-cohort
# HTTP-only TSV, more parallelism
npdb download --max-workers 8 results.tsv -o ./downloadsTests for this command live in test/test_download.py and mock the NeuroData manager; they must stay offline.
Using data
Tutorials
Infrastructure