npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

leetcode-fetch-cli

v1.2.0

Published

CLI tool to download LeetCode problems with solutions, pack and sync via Google Drive

Downloads

185

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-cli

After 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 link

Quick 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 python3

Backup 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-dataset

Usage

1. Login

leetcode-fetch login

The tool will automatically open your browser for LeetCode authentication:

  1. Browser opens to LeetCode authorization page
  2. Log in to your LeetCode account (if not already logged in)
  3. Authorize the application
  4. Session is automatically saved

2. Download Problems

Download All Problems

leetcode-fetch download

Download Specific Problem

leetcode-fetch download 1

Download with Custom Formats

leetcode-fetch download -f html,md

Download Without Templates or Solutions

leetcode-fetch download --no-templates
leetcode-fetch download --no-solutions --no-official

Download with Custom Concurrency

leetcode-fetch download -c 10
leetcode-fetch download --concurrency 20

Download Specific Problem with Options

leetcode-fetch download 1 -f md --no-templates

3. Check Status

leetcode-fetch status

4. Export Problems

Export downloaded problems with filtering options.

Export with Specific Language

leetcode-fetch export -o ./my-problems -l python3

Export Multiple Languages

leetcode-fetch export -o ./export -l python3,cpp,javascript

Export with HTML Format

leetcode-fetch export -o ./export -l python3 -f html

Export with Official Solutions

leetcode-fetch export -o ./my-problems -l python3,cpp -f md --official

Export All Languages (Default)

leetcode-fetch export -o ./export

5. 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.zip

Then 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-verify

7. Logout

leetcode-fetch logout

Common Use Cases

Download Everything (Default)

leetcode-fetch download

Downloads all problems with all available languages, all formats, templates, and solutions.

Markdown Only (Save Space)

leetcode-fetch download -f md

Downloads only markdown descriptions, useful for saving disk space.

Templates Only (For Practice)

leetcode-fetch download --no-solutions --no-official

Downloads 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/5

Progress 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 Drive

Download 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 message

Export 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 message

Pack 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 message

Sync 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 message

Note: 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-templates

Export 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 md

Pack & 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 logout

Requirements

  • Node.js >= 14.0.0
  • LeetCode account (for downloading from LeetCode)
  • Python with pip (for Google Drive sync - optional)
    • Run pip install gdown to enable sync command

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