Datasets
A dataset on Mabyduck represents a structured collection of media files — audio, images, or videos — organized for subjective evaluation. Datasets are the foundation of every experiment: before you can run a study, you need to create and upload a dataset.
For a detailed guide on how to structure your media files, see the Datasets documentation.
How it works
The API follows a three-step process to create a dataset:
- Create a dataset — send a
POSTrequest that returns signed URLs for uploading the file in parts. - Upload a file — upload a
.ziparchive or a.txtfile of URLs to the signed URLs. - Poll status — poll the status endpoint until the dataset is processed and ready.
Once a dataset reaches the ready state, it can be attached to experiments.
Authentication
All API requests require an API key, which you can generate from your
project settings.
Include it in the Authorization header of every request:
Authorization: Api-Key YOUR_API_KEY
Creating a dataset
To create a dataset, send a POST request to the create dataset endpoint with a name and a filename.
The filename determines how the dataset will be processed:
.zip— a zip archive containing your organized media files..txt— a plain text file with one URL per line, for externally hosted media.
import os
import requests
API_KEY = 'YOUR_API_KEY'
PROJECT_ID = 'YOUR_PROJECT_ID'
headers = {'Authorization': f'Api-Key {API_KEY}'}
response = requests.post(
f'https://api.mabyduck.com/projects/{PROJECT_ID}/datasets/',
headers=headers,
json={
'name': 'My Dataset',
'filename': 'dataset.zip',
'file_size': os.path.getsize('dataset.zip'),
},
)
response.raise_for_status()
dataset = response.json()
print(dataset['upload_urls']) # Signed URLs for uploading
print(dataset['id']) # Dataset ID
curl -X POST \
'https://api.mabyduck.com/projects/{project_id}/datasets/' \
-H 'Authorization: Api-Key YOUR_API_KEY' \
-H 'Content-Type: application/json' \
-d "{\"name\": \"My Dataset\", \"filename\": \"dataset.zip\", \"file_size\": $(wc -c < dataset.zip)}"
The response includes:
id— the dataset identifier.part_size— the number of bytes per part except the last. It isnulliffile_sizewas omitted.upload_urls— time-limited signed URLs, ordered by part number.upload_url— a compatibility alias for the only URL when there is one part.status_url— the URL to check the processing status.
Uploading the file
Split the file into part_size-byte parts and upload part 1 to the first URL, part 2 to the second, and so on. The final part can be smaller. Include file_size when creating datasets larger than 5 GB.
Uploading a zip archive
A zip archive should contain your media files organized into folders. Each folder represents a source, and files within represent different conditions. See the datasets documentation for details on structuring your files.
with open('dataset.zip', 'rb') as f:
for upload_url in dataset['upload_urls']:
part = f.read(dataset['part_size'])
requests.put(upload_url, data=part).raise_for_status()
This example reads one whole part into memory. For very large files, stream each part instead.
For smaller files, you can omit file_size and upload the entire file to upload_url in one PUT (up to 5 GB):
curl --fail --upload-file dataset.zip '{upload_url}'
Refreshing upload URLs
The signed URLs expire after four hours. For a long upload, refresh the URLs for parts that have not yet been uploaded before they expire. Part numbers are one-based. A successful refresh also keeps the draft active for another six hours; the storage provider may abort an incomplete upload after one day.
response = requests.post(
f'https://api.mabyduck.com/projects/{PROJECT_ID}/datasets/{dataset["id"]}/part-urls/',
headers=headers,
json={'part_numbers': [2, 3]},
)
response.raise_for_status()
urls = response.json()['urls'] # e.g. {'2': 'https://...', '3': 'https://...'}
# Use urls['2'] and urls['3'] for parts 2 and 3.
This endpoint only works while the dataset is a draft. Use the refreshed URLs in place of the corresponding entries in upload_urls.
Uploading externally hosted files
For media hosted on external URLs (e.g., cloud storage), create your dataset with a .txt
filename and upload a text file with one URL per line. The last two path segments of each URL
are interpreted as <source>/<condition>, following the same folder structure as local datasets:
https://cdn.example.com/source_1/method_a.wav
https://cdn.example.com/source_1/method_b.wav
https://cdn.example.com/source_2/method_a.wav
https://cdn.example.com/source_2/method_b.wav
urls = [
'https://cdn.example.com/source_1/method_a.wav',
'https://cdn.example.com/source_1/method_b.wav',
'https://cdn.example.com/source_2/method_a.wav',
'https://cdn.example.com/source_2/method_b.wav',
]
# Create a dataset for external URLs
response = requests.post(
f'https://api.mabyduck.com/projects/{PROJECT_ID}/datasets/',
headers=headers,
json={'name': 'External Dataset', 'filename': 'urls.txt'},
)
response.raise_for_status()
dataset = response.json()
# Upload the URL list
requests.put(dataset['upload_url'], data='\n'.join(urls)).raise_for_status()
Polling the status
After uploading, the dataset is processed server-side (e.g., collecting stimulus durations).
Poll the status endpoint until the status is ready or error:
from time import sleep
while True:
response = requests.get(dataset['status_url'], headers=headers)
response.raise_for_status()
status = response.json()
if status['status'] in ('ready', 'error'):
break
sleep(1.0)
print(status['status']) # "ready" or "error"
The possible statuses are:
| Status | Description |
|---|---|
draft | Dataset created but file not yet uploaded |
enqueued | File uploaded and waiting for processing |
processing | File uploaded and being processed |
ready | Processing complete — dataset can be used in experiments |
error | Processing failed (check the error field for details) |
Retrieving stimuli and stimulus groups
Once a dataset is ready, you can retrieve its details to inspect the resulting stimuli and stimulus groups:
response = requests.get(
f'https://api.mabyduck.com/projects/{PROJECT_ID}/datasets/{dataset["id"]}/',
headers=headers,
)
detail = response.json()
for stimulus in detail['stimuli']:
print(stimulus['filepath'], stimulus['group_id'])
Each stimulus has:
filepath— the path of the media file within the dataset (e.g.,source_1/method_a.wav).group_id— an identifier grouping stimuli that belong to the same source folder.
Stimuli within the same group correspond to different conditions applied to the same source. In an experiment, stimuli from the same group are evaluated together — for example, as a single MUSHRA slate or a pairwise comparison.
Once your dataset is ready, you can create an experiment. See the Experiments section for a step-by-step guide on creating and launching an experiment using the API.