Download Selected Files from a Kaggle Competition

· 1 min read · #linux #bash kaggle

To download selected files from a kaggle competition:

  • install kaggle with pip install kaggle

  • authenticate by saving the kaggle.json file in ~/.kaggle/kaggle.json.

  • Optional: chmod 600 ~/.kaggle/kaggle.json

#!/bin/bash
mkdir -p /tmp/kaggle-sample /workspace/sample
SLUG=<competition-slug>
for f in <filename>.csv <filename>.csv <filename>.csv; do
  kaggle competitions download "$SLUG" -f "$f" -p /tmp/kaggle-sample -o
done
cp -f /tmp/kaggle-sample/*.csv /workspace/sample/

if the download hangs on IPv6 you can add at the top

printf 'precedence ::ffff:0:0/96  100\n' >> /etc/gai.conf