Group analysis #
The simplest way to analyze data across subjects is in brainlife.io itself: open a project, go to 4. Analysis and select New analysis to launch a Jupyter notebook on the project's data, from Blank Template Notebooks or Notebooks from Publications. See Analysis.
This page shows how to collect dataset metadata and product.json summaries outside brainlife.io, with the warehouse API or the CLI.
Overview #
Apps can store small results in `product.json`. You can read these results for many datasets through the warehouse API without downloading the datasets themselves, and analyze them in MATLAB, Python or any other tool.
Query the warehouse API #
If you build scripts or services that read dataset metadata and product.json summaries from the warehouse API, authenticate with the token that bl login saves.
1. Authentication #
The CLI stores your token in:
~/.config/brainlife.io/.jwt
Create or renew it with:
bl login --ttl 30
2. Python example #
#!/usr/bin/env python3
import os
import json
import requests
# Load the JWT token generated by 'bl login'
jwt_path = os.path.expanduser('~/.config/brainlife.io/.jwt')
with open(jwt_path, 'r') as f:
jwt = f.read().strip()
headers = {
'Authorization': f'Bearer {jwt}',
'Content-Type': 'application/json'
}
# Define search parameters for the warehouse API
# Replace 'YOUR_PROJECT_ID' and 'YOUR_DATATYPE_ID' with real IDs
find_query = {
'project': 'YOUR_PROJECT_ID',
'datatype': 'YOUR_DATATYPE_ID',
'removed': False
}
params = {
'limit': 100,
'select': 'meta tags',
'find': json.dumps(find_query)
}
url = 'https://brainlife.io/api/warehouse/dataset'
res = requests.get(url, params=params, headers=headers)
if res.status_code == 200:
data = res.json()
datasets = data.get('datasets', [])
print(f"Found {len(datasets)} dataset records.")
for d in datasets:
subject = d.get('meta', {}).get('subject', 'unknown')
# product.json of each dataset
prod = requests.get(f"https://brainlife.io/api/warehouse/dataset/product/{d['_id']}", headers=headers)
product = prod.json().get('product') if prod.status_code == 200 else None
print(f"Dataset {d['_id']} - Subject: {subject} - product: {product}")
else:
print(f"Failed to query datasets: {res.status_code} - {res.text}")
3. Or use the CLI #
To list and download datasets from the command line, use bl instead of writing API queries:
- To query datasets:
bl data query --project--subject - To download datasets in BIDS format:
bl bids download --project--output ./bids_output - To download individual datasets:
bl data download -i
See Installing the CLI and Downloading data.