Github: https://github.com/Kaggle/kaggle-api
Kaggle API
Pythonで実装されたコマンドラインツールを使用してアクセス可能なhttps://www.kaggle.comの公式API。
ベータリリース – Kaggleは現在提供されているAPI機能を変更する権利を留保します。
インストール
Pythonとパッケージマネージャーpip
インストールされていることを確認してください。
コマンドラインを使用してKaggle APIにアクセスするには、次のコマンドを実行します。
pip install kaggle
(Mac / Linuxでpip install --user kaggle
を実行する必要があるかもしれませんが、インストールプロセス中に問題が発生した場合はこれをお勧めします)
以下の例に示すように、 kaggle
コマンドを使用できるようになりました。
kaggle: command not found
エラーが発生した場合は、pythonバイナリがあなたのパスにあることを確認してください。 pip uninstall kaggle
を実行し、バイナリがどこにあるpip uninstall kaggle
を見ることで、 kaggle
がインストールされている場所をkaggle
ことができます。 Linuxでローカルユーザーをインストールする場合、デフォルトの場所は~/.local/bin
です。 Windowsでは、デフォルトの場所は$PYTHON_HOME/Scripts
です。
API資格情報
Kaggle APIを使用するには、 https: //www.kaggle.comでKaggleアカウントに登録します 。 その後、ユーザープロフィール( https://www.kaggle.com/<username>/account
)の「アカウント」タブに移動し、「APIトークンを作成」を選択します。 これにより、API資格情報を含むファイルkaggle.json
がダウンロードされます。 このファイルを~/.kaggle/kaggle.json
(WindowsではC:\Users\<Windows-username>\.kaggle\kaggle.json
)に配置します。
セキュリティを確保するため、コンピュータの他のユーザーに資格情報への読み取りアクセス権がないことを確認してください。 Unixベースのシステムでは、次のコマンドでこれを行うことができます:
chmod 600 ~/.kaggle/kaggle.json
コマンド
コマンドラインツールは、次のコマンドをサポートしています。
kaggle competitions {list,files,download,submit,submissions,leaderboard}
kaggle datasets {list, files, download, create, version, init}
kaggle config {view, set, unset}
これらの各コマンドの使用については、以下の詳細を参照してください。
コンテスト
APIはKaggle Competitionsのための以下のコマンドをサポートしています。
競争のリスト
usage: kaggle competitions list [-h] [-p PAGE] [-s SEARCH] [-v]
optional arguments:
-h, --help show this help message and exit
-p PAGE, --page PAGE page number
-s SEARCH, --search SEARCH
term(s) to search for
-v, --csv print in CSV format
(if not set print in table format)
例:
kaggle competitions list -s health
競合ファイルの一覧表示
usage: kaggle competitions files [-h] [-c COMPETITION] [-v] [-q]
optional arguments:
-h, --help show this help message and exit
-c COMPETITION, --competition COMPETITION
Competition URL suffix (use "kaggle competitions list" to show options)
If empty, the default competition will be used (use "kaggle config set competition")"
-v, --csv Print results in CSV format (if not set print in table format)
-q, --quiet Suppress printing information about download progress
例:
kaggle competitions files -c favorita-grocery-sales-forecasting
競技ファイルをダウンロードする
usage: kaggle competitions download [-h] [-c COMPETITION] [-f FILE] [-p PATH]
[-w] [-o] [-q]
optional arguments:
-h, --help show this help message and exit
-c COMPETITION, --competition COMPETITION
Competition URL suffix (use "kaggle competitions list" to show options)
If empty, the default competition will be used (use "kaggle config set competition")"
-f FILE, --file FILE File name, all files downloaded if not provided
(use "kaggle competitions files -c <competition>" to show options)
-p PATH, --path PATH Folder where file(s) will be downloaded, defaults to ~/.kaggle
-w, --wp Download files to current working path
-o, --force Skip check whether local version of file is up to date, force file download
-q, --quiet Suppress printing information about download progress
例:
kaggle competitions download -c favorita-grocery-sales-forecasting
kaggle competitions download -c favorita-grocery-sales-forecasting -f test.csv.7z
注: https://www.kaggle.com/c/<competition-name>/rules
competition-name>/rulesで競技規則を受け入れる必要がありhttps://www.kaggle.com/c/<competition-name>/rules
。
競争に参加する
usage: kaggle competitions submit [-h] [-c COMPETITION] -f FILE -m MESSAGE
[-q]
required arguments:
-f FILE, --file FILE File for upload (full path)
-m MESSAGE, --message MESSAGE
Message describing this submission
optional arguments:
-h, --help show this help message and exit
-c COMPETITION, --competition COMPETITION
Competition URL suffix (use "kaggle competitions list" to show options)
If empty, the default competition will be used (use "kaggle config set competition")"
-q, --quiet Suppress printing information about download progress
例:
kaggle competitions submit -c favorita-grocery-sales-forecasting -f sample_submission_favorita.csv.7z -m "My submission message"
注: https://www.kaggle.com/c/<competition-name>/rules
competition-name>/rulesで競技規則を受け入れる必要がありhttps://www.kaggle.com/c/<competition-name>/rules
。
競争の提出をリストする
usage: kaggle competitions submissions [-h] [-c COMPETITION] [-v] [-q]
optional arguments:
-h, --help show this help message and exit
-c COMPETITION, --competition COMPETITION
Competition URL suffix (use "kaggle competitions list" to show options)
If empty, the default competition will be used (use "kaggle config set competition")"
-v, --csv Print results in CSV format (if not set print in table format)
-q, --quiet Suppress printing information about download progress
例:
kaggle competitions submissions -c favorita-grocery-sales-forecasting
注: https://www.kaggle.com/c/<competition-name>/rules
competition-name>/rulesで競技規則を受け入れる必要がありhttps://www.kaggle.com/c/<competition-name>/rules
。
競争ランキングを取得する
usage: kaggle competitions leaderboard [-h] [-c COMPETITION] [-s] [-d]
[-p PATH] [-q]
optional arguments:
-h, --help show this help message and exit
-c COMPETITION, --competition COMPETITION
Competition URL suffix (use "kaggle competitions list" to show options)
If empty, the default competition will be used (use "kaggle config set competition")"
-s, --show Show the top of the leaderboard
-d, --download Download entire leaderboard
-p PATH, --path PATH Folder where file(s) will be downloaded, defaults to ~/.kaggle
-q, --quiet Suppress printing information about download progress
例:
kaggle competitions leaderboard -c favorita-grocery-sales-forecasting -s
データセット
このAPIはKaggleデータセットに対して以下のコマンドをサポートしています。
リストデータセット
usage: kaggle datasets list [-h] [-p PAGE] [-s SEARCH] [-v]
optional arguments:
-h, --help show this help message and exit
-p PAGE, --page PAGE Page number for results paging
-s SEARCH, --search SEARCH
Term(s) to search for
-v, --csv Print results in CSV format (if not set print in table format)
例:
kaggle datasets list -s demographics
データセットのファイルを一覧表示する
usage: kaggle datasets files [-h] -d DATASET [-v]
required arguments:
-d DATASET, --dataset DATASET
Dataset URL suffix in format <owner>/<dataset-name> (use "kaggle datasets list" to show options)
optional arguments:
-h, --help show this help message and exit
-v, --csv Print results in CSV format (if not set print in table format)
例:
kaggle datasets files -d zillow/zecon
データセットファイルをダウンロードする
usage: kaggle datasets download [-h] -d DATASET [-f FILE] [-p PATH] [-w] [-o]
[-q]
required arguments:
-d DATASET, --dataset DATASET
Dataset URL suffix in format <owner>/<dataset-name> (use "kaggle datasets list" to show options)
optional arguments:
-h, --help show this help message and exit
-f FILE, --file FILE File name, all files downloaded if not provided
(use "kaggle datasets files -d <dataset>" to show options)
-p PATH, --path PATH Folder where file(s) will be downloaded, defaults to ~/.kaggle
-w, --wp Download files to current working path
-o, --force Skip check whether local version of file is up to date, force file download
-q, --quiet Suppress printing information about download progress
例:
kaggle datasets download -d zillow/zecon
kaggle datasets download -d zillow/zecon -f State_time_series.csv
データセット作成用のメタデータファイルを初期化する
usage: kaggle datasets init [-h] -p FOLDER
required arguments:
-p FOLDER, --path FOLDER
Folder for upload, containing data files and a special metadata.json file (https://github.com/Kaggle/kaggle-api/wiki/Metadata)
optional arguments:
-h, --help show this help message and exit
例:
kaggle datasets init -p /path/to/dataset
新しいデータセットを作成する
usage: kaggle datasets create [-h] -p FOLDER [-u] [-q]
required arguments:
-p FOLDER, --path FOLDER
Folder for upload, containing data files and a special metadata.json file (https://github.com/Kaggle/kaggle-api/wiki/Metadata)
optional arguments:
-h, --help show this help message and exit
-u, --public Create the Dataset publicly (default is private)
-q, --quiet Suppress printing information about download progress
-t, --keep-tabular Do not convert tabular files to CSV (default is to convert)
例:
kaggle datasets create -p /path/to/dataset
新しいデータセットバージョンを作成する
usage: kaggle datasets version [-h] -m VERSION_NOTES -p FOLDER [-q]
required arguments:
-m VERSION_NOTES, --message VERSION_NOTES
Message describing the new version
-p FOLDER, --path FOLDER
Folder for upload, containing data files and a special metadata.json file (https://github.com/Kaggle/kaggle-api/wiki/Metadata)
optional arguments:
-h, --help show this help message and exit
-q, --quiet Suppress printing information about download progress
-t, --keep-tabular Do not convert tabular files to CSV (default is to convert)
-d, --delete-old-versions
Delete old versions of this dataset
例:
kaggle datasets version -p /path/to/dataset -m "Updated data"
設定
現在の設定値を見る
usage: kaggle config path [-h] [-p PATH]
optional arguments:
-h, --help show this help message and exit
-p PATH, --path PATH folder where file(s) will be downloaded, defaults to ~/.kaggle
例:
kaggle config path -p C:\
現在の設定値を見る
usage: kaggle config view [-h]
optional arguments:
-h, --help show this help message and exit
例:
kaggle config view
設定値を設定する
usage: kaggle config set [-h] -n NAME -v VALUE
required arguments:
-n NAME, --name NAME Name of the configuration parameter
(one of competition, path, proxy)
-v VALUE, --value VALUE
Value of the configuration parameter, valid values depending on name
- competition: Competition URL suffix (use "kaggle competitions list" to show options)
- path: Folder where file(s) will be downloaded, defaults to ~/.kaggle
- proxy: Proxy for HTTP requests
例:
kaggle config set -n competition -v titanic
設定値を消去する
usage: kaggle config unset [-h] -n NAME
required arguments:
-n NAME, --name NAME Name of the configuration parameter
(one of competition, path, proxy)
例:
kaggle config unset -n competition
制限事項
現時点での最大の制限は、この時点でどのような方法でもカーネルがサポートされていないことです。 ETAはありませんが、近いうちにサポートを実施するつもりです。 さらに、大規模なデータセット(> = 2GB)での作業は現在不可能です。
ライセンス
Kaggle APIはApache 2.0ライセンスでリリースされています。