gdown: Google Drive Public File/Folder Downloader
gdown is a Python package (current version 5.2.1) designed to download public files and folders from Google Drive, providing functionality that standard tools like curl or wget often lack for Google Drive links. It handles large files by skipping security notices and supports recursive downloads for folders (up to 50 files per folder). The library has an active development cycle with regular updates addressing features, enhancements, and bug fixes.
Warnings
- breaking gdown dropped support for Python 2 in version 5.0.0. The library now requires Python 3.8 or higher.
- gotcha Older versions of gdown (before 4.7.3) might fail to download files due to changes in Google Drive's User-Agent handling.
- deprecated The `--id` command-line option was deprecated in version 4.3.1 and removed in 5.0.0. File IDs or URLs can now be passed directly without the `--id` flag.
- gotcha Prior to v5.2.1, if hash verification failed for a downloaded file, a corrupted file might have been left in the final destination. Hash verification now occurs before moving the file.
- gotcha Files and folders downloaded via gdown must have their sharing permissions set to 'Anyone with the link can view' on Google Drive.
- gotcha When downloading folders, gdown has a limitation of processing a maximum of 50 files per folder. Attempting to download larger folders may result in incomplete downloads.
- breaking In `gdown.cached_download`, the `md5` argument was replaced with a more general `hash` argument in v5.1.0 to support various hash algorithms.
Install
-
pip install gdown
Imports
- gdown
import gdown
Quickstart
import gdown
import os
# A public Google Drive file URL (replace with your desired file if needed)
# This specific file is a public example from the gdown GitHub repo
url = "https://drive.google.com/uc?id=1l_5RK28JRL19wpT22B-DY9We3TVXnnQQ"
output_filename = "fcn8s_from_caffe.npz"
try:
gdown.download(url, output_filename, quiet=False)
print(f"Successfully downloaded {output_filename}")
except Exception as e:
print(f"Error downloading file: {e}")
finally:
# Clean up the downloaded file for a repeatable quickstart
if os.path.exists(output_filename):
os.remove(output_filename)
print(f"Cleaned up {output_filename}")