leetcode-fetch-cli
v1.2.0
Published
CLI tool to download LeetCode problems with solutions, pack and sync via Google Drive
Downloads
185
Maintainers
Readme
leetcode-fetch-cli
CLI tool to batch download LeetCode problems with solutions using leetcode's GraphQL endpoint. Languages are automatically detected for each problem.
Features
- Download problem descriptions (HTML, Markdown, Raw)
- Auto-detect available languages for each problem
- Download code templates for all available languages
- Download community solutions (top voted, filtered by language)
- Download official solutions
- Automatic image downloading
- Multi-dataset management with custom directories
- Pack and sync data via Google Drive
- Flexible export with language and format filtering
Installation
Global Installation (Recommended)
npm install -g leetcode-fetch-cliAfter installation, the leetcode-fetch command will be available globally.
Using npx (No Installation Required)
npx leetcode-fetch-cli <command>Local Development
git clone https://github.com/Djanghao/leetcode-fetch-cli.git
cd leetcode-fetch-cli
npm install
npm linkQuick Start
Option 1: Sync from Google Drive (Recommended - Fast!)
Don't want to wait for downloading 3700+ problems? Use our pre-downloaded backup:
# Install gdown (required for Google Drive downloads)
pip install gdown
# Sync data to default location (data/)
leetcode-fetch sync -u "https://drive.google.com/uc?id=1f55eigTfb2O2Vl_-3p3QgoiHN04WQd41"
# Then export what you need
leetcode-fetch export -s data/downloads -o ./my-problems -l python3Backup Info:
- Size: ~2 GB (compressed)
- Problems: 3786 completed
- Last Updated: 2024-12-21
- Includes: All descriptions, templates, and solutions
Option 2: Download from LeetCode
# Login first
leetcode-fetch login
# Download all problems
leetcode-fetch download
# Or download to custom directory
leetcode-fetch download -d data/my-datasetUsage
1. Login
leetcode-fetch loginThe tool will automatically open your browser for LeetCode authentication:
- Browser opens to LeetCode authorization page
- Log in to your LeetCode account (if not already logged in)
- Authorize the application
- Session is automatically saved
2. Download Problems
Download All Problems
leetcode-fetch downloadDownload Specific Problem
leetcode-fetch download 1Download with Custom Formats
leetcode-fetch download -f html,mdDownload Without Templates or Solutions
leetcode-fetch download --no-templates
leetcode-fetch download --no-solutions --no-officialDownload with Custom Concurrency
leetcode-fetch download -c 10
leetcode-fetch download --concurrency 20Download Specific Problem with Options
leetcode-fetch download 1 -f md --no-templates3. Check Status
leetcode-fetch status4. Export Problems
Export downloaded problems with filtering options.
Export with Specific Language
leetcode-fetch export -o ./my-problems -l python3Export Multiple Languages
leetcode-fetch export -o ./export -l python3,cpp,javascriptExport with HTML Format
leetcode-fetch export -o ./export -l python3 -f htmlExport with Official Solutions
leetcode-fetch export -o ./my-problems -l python3,cpp -f md --officialExport All Languages (Default)
leetcode-fetch export -o ./export5. Pack Data for Backup
Create a zip backup of your downloaded data:
# Pack default directory (data/downloads)
leetcode-fetch pack
# Creates: leetcode-problems-backup-YYMMDD.zip
# Pack custom directory
leetcode-fetch pack -s data/my-dataset
# Custom output filename
leetcode-fetch pack -s data/downloads -o my-backup.zipThen manually upload the zip file to Google Drive for sharing or backup.
6. Sync from Google Drive
Download and extract pre-packaged data:
# Install gdown first
pip install gdown
# Sync to default location (data/)
leetcode-fetch sync -u "https://drive.google.com/uc?id=YOUR_FILE_ID"
# Sync to custom location
leetcode-fetch sync -d custom-folder/ -u "https://drive.google.com/uc?id=YOUR_FILE_ID"
# Skip integrity verification (faster)
leetcode-fetch sync -u "https://drive.google.com/uc?id=YOUR_FILE_ID" --skip-verify7. Logout
leetcode-fetch logoutCommon Use Cases
Download Everything (Default)
leetcode-fetch downloadDownloads all problems with all available languages, all formats, templates, and solutions.
Markdown Only (Save Space)
leetcode-fetch download -f mdDownloads only markdown descriptions, useful for saving disk space.
Templates Only (For Practice)
leetcode-fetch download --no-solutions --no-officialDownloads only problem descriptions and code templates, ideal for practice.
Output Structure
data/
├── downloads/ # Default download directory
│ ├── .download-progress.json # Resume progress tracking
│ ├── array/ # Organized by problem tags
│ │ ├── 0001_Easy_two-sum/
│ │ │ ├── description/
│ │ │ │ ├── problem.html
│ │ │ │ ├── problem.md
│ │ │ │ ├── problem.raw.txt
│ │ │ │ └── images/ # Description images
│ │ │ │ ├── 0.jpg
│ │ │ │ └── 1.jpg
│ │ │ ├── templates/ # All available languages for this problem
│ │ │ │ ├── solution.py
│ │ │ │ ├── solution.js
│ │ │ │ ├── solution.cpp
│ │ │ │ └── ...
│ │ │ └── solutions/
│ │ │ ├── official/
│ │ │ │ ├── solution.md
│ │ │ │ └── images/ # Official solution images
│ │ │ │ └── 0.png
│ │ │ └── community/ # Top voted solution per language
│ │ │ ├── python3/
│ │ │ │ ├── solution.md
│ │ │ │ └── images/
│ │ │ │ └── 0.jpeg
│ │ │ ├── javascript/
│ │ │ │ └── solution.md
│ │ │ └── ...
│ │ └── ...
│ ├── database/ # Database problems
│ │ ├── 1280_Easy_students-and-examinations/
│ │ │ ├── templates/
│ │ │ │ ├── solution.sql
│ │ │ │ ├── solution.mssql.sql
│ │ │ │ ├── solution.pgsql.sql
│ │ │ │ ├── solution.oracle.sql
│ │ │ │ └── solution.pandas.py
│ │ │ └── ...
│ │ └── ...
│ └── ...
└── my-dataset/ # You can have multiple datasets
└── ...Download Progress
The tool shows real-time progress and resumes interrupted downloads:
[1/3682] data/downloads/array/0001_Easy_two-sum Description: 1/1, Templates: 19/19, Official: 1/1, Community: 19/19
[2/3682] data/downloads/database/1280_Easy_students-and-examinations Description: 1/1, Templates: 5/5, Official: 1/1, Community: 5/5Progress is saved to .download-progress.json for resuming.
Options Reference
Commands
COMMANDS
login Authenticate with LeetCode
logout Clear authentication session
status Check authentication status
download [id] Download problems (optionally specify problem ID)
export Export downloaded problems with filtering
pack Pack data for Google Drive upload
sync Sync data from Google DriveDownload Options
DOWNLOAD OPTIONS
[id] Download specific problem by ID (optional)
-d, --data-dir Data directory (default: data/downloads)
-f, --formats Comma-separated formats: html,md,raw (default: all)
--no-templates Skip downloading code templates
--no-solutions Skip downloading community solutions
--no-official Skip downloading official solutions
-c, --concurrency Number of concurrent downloads (default: 5)
-h, --help Show help messageExport Options
EXPORT OPTIONS
-s, --source-dir <path> Source data directory (default: data/downloads)
-o, --output <path> Destination folder (required)
-l, --languages <langs> Languages to export (comma-separated)
Example: python3,cpp,javascript
Default: all available languages
-f, --format <format> Description format: html, md, or raw
Default: md
--official Include official solutions
-h, --help Show help messagePack Options
PACK OPTIONS
-s, --source-dir <path> Source data directory (default: data/downloads)
-o, --output <filename> Output filename (default: leetcode-problems-backup-YYMMDD.zip)
-h, --help Show help messageSync Options
SYNC OPTIONS
-d, --data-dir <path> Destination directory (default: data/)
-u, --url <url> Google Drive URL (required)
--skip-verify Skip integrity verification
-h, --help Show help messageNote: Languages are automatically detected from each problem. Algorithm problems usually have 19 languages, database problems usually have 5 languages (SQL dialects + Pandas), and shell problems have Bash.
Examples
Download Examples
# Quick start
leetcode-fetch login
leetcode-fetch download
# Download specific problem
leetcode-fetch download 1
# Download to custom directory
leetcode-fetch download -d data/my-dataset
# Download all problems, markdown only
leetcode-fetch download -f md
# Download templates only (for practice)
leetcode-fetch download --no-solutions --no-official
# Download with 10 concurrent downloads
leetcode-fetch download -c 10
# Download specific problem with custom options
leetcode-fetch download 1 -f md --no-templatesExport Examples
# Export Python problems with markdown format
leetcode-fetch export -o ./my-problems -l python3
# Export from custom source directory
leetcode-fetch export -s data/my-dataset -o ./export -l python3
# Export multiple languages with HTML
leetcode-fetch export -o ./export -l python3,cpp,javascript -f html
# Export with official solutions
leetcode-fetch export -o ./export -l python3,cpp -f md --official
# Export all languages (default)
leetcode-fetch export -o ./all-problems
# Export single language for practice
leetcode-fetch export -o ./python-only -l python3 -f mdPack & Sync Examples
# Pack default directory
leetcode-fetch pack
# Creates: leetcode-problems-backup-251221.zip
# Pack custom directory with custom name
leetcode-fetch pack -s data/my-dataset -o my-backup.zip
# Sync from Google Drive
leetcode-fetch sync -u "https://drive.google.com/uc?id=YOUR_FILE_ID"
# Sync to custom location
leetcode-fetch sync -d data/custom/ -u "https://drive.google.com/uc?id=YOUR_FILE_ID"Other Examples
# Check authentication
leetcode-fetch status
# Logout
leetcode-fetch logoutRequirements
- Node.js >= 14.0.0
- LeetCode account (for downloading from LeetCode)
- Python with pip (for Google Drive sync - optional)
- Run
pip install gdownto enable sync command
- Run
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
MIT
Repository
https://github.com/Djanghao/leetcode-fetch-cli
Issues
https://github.com/Djanghao/leetcode-fetch-cli/issues
NPM Package
https://www.npmjs.com/package/leetcode-fetch-cli
