Skip to main content

CLI tool to sync LeetCode submissions into structured Git repository

Project description

PyPI version Python versions License

๐Ÿš€ leetcode-sync-cli

A powerful CLI tool to automatically sync your LeetCode submissions into a clean, structured GitHub repository โ€” with versioning, difficulty grouping, dashboard generation, and optional auto-sync via GitHub Actions.


โœจ Features

  • ๐Ÿ” Secure credential handling (persistent session storage)
  • โœ… Credential validation before syncing
  • ๐Ÿ”„ Automatic re-authentication if session expires
  • ๐Ÿ“‚ Organizes problems by difficulty (Easy / Medium / Hard)
  • ๐Ÿง  Keeps only latest submission per language
  • โšก Caches problem difficulty for performance
  • ๐Ÿ“ Auto-generates README per problem
  • ๐Ÿ“Š Auto-updates progress dashboard in root README
  • ๐Ÿš€ Optional Git auto-commit & push
  • ๐Ÿค– Optional GitHub Actions daily auto-sync
  • ๐Ÿ“ฆ Installable via pip

๐Ÿ“ฆ Installation

Install from PyPI:

pip install leetcode-sync-cli

๐Ÿ” First-Time Setup

On first run, the CLI will prompt for:

  • LEETCODE_SESSION
  • CSRFTOKEN

You can find these in:

LeetCode โ†’ DevTools โ†’ Application โ†’ Cookies

They are stored securely in:

~/.leetcode_sync/.env

๐Ÿ”„ Basic Usage

Sync your submissions:

leetcode-sync --sync

Sync and push changes to GitHub:

leetcode-sync --sync --push

๐Ÿ“‚ Generated Repository Structure

problems/
โ”œโ”€โ”€ easy/
โ”‚   โ””โ”€โ”€ two_sum/
โ”‚       โ”œโ”€โ”€ solution.py
โ”‚       โ””โ”€โ”€ README.md
โ”‚
โ”œโ”€โ”€ medium/
โ”‚   โ””โ”€โ”€ group_anagrams/
โ”‚
โ””โ”€โ”€ hard/

Root README automatically contains:

Difficulty Count
Easy 24
Medium 38
Hard 8
Total 70

๐Ÿค– Enable Daily Auto-Sync (Optional)

Generate GitHub Actions workflow:

leetcode-sync --setup-autosync

This creates:

.github/workflows/leetcode-sync.yml

Then:

  1. Commit & push the workflow
  2. Go to GitHub โ†’ Settings โ†’ Secrets
  3. Add:
    • LEETCODE_SESSION
    • CSRFTOKEN Your repo will now auto-sync daily.

๐Ÿ”„ Session Expiration Handling

If your LeetCode session expires:

  • The CLI detects invalid credentials
  • Prompts for new session
  • Updates stored credentials automatically
  • Continues execution No manual cleanup needed.

โš™๏ธ Advanced Features

  • Automatic difficulty caching
  • Graceful Git error handling
  • Safe commit (no changes โ†’ no crash)
  • Clean package architecture
  • Compatible with GitHub Actions
  • Ready for pipx installation

๐Ÿง  How It Works

  • Uses LeetCode's internal GraphQL API
  • Fetches accepted submissions
  • Deduplicates by latest per language
  • Retrieves difficulty (cached)
  • Generates structured folders
  • Updates progress dashboard
  • Optionally commits and pushes

๐Ÿ›ก Security Note

This tool uses your LeetCode session cookie.

  • Credentials are never committed
  • Stored locally in user config directory
  • Not shared externally
  • Can be reset anytime by deleting:
~/.leetcode_sync/

๐Ÿ›  Development

Clone Repo:

git clone https://github.com/WixBe/leetcode-sync-cli
cd leetcode-sync-cli
pip install -e .

Run locally:

leetcode-sync --sync

๐Ÿ“ˆ Roadmap

  • Runtime & memory stats in problem README
  • Exponential retry/backoff
  • Multi-profile support
  • Progress badges
  • Semantic version automation

โญ Contributing

Contributions are welcome! Feel free to open issues or submit pull requests.

Built with โค๏ธ by Narendran

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

leetcode_sync_cli-0.1.1.tar.gz (9.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

leetcode_sync_cli-0.1.1-py3-none-any.whl (10.4 kB view details)

Uploaded Python 3

File details

Details for the file leetcode_sync_cli-0.1.1.tar.gz.

File metadata

  • Download URL: leetcode_sync_cli-0.1.1.tar.gz
  • Upload date:
  • Size: 9.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.3

File hashes

Hashes for leetcode_sync_cli-0.1.1.tar.gz
Algorithm Hash digest
SHA256 bab0e11fee112c149f9ea564d647916ff6277de562a6e2129d3db92f109a26b6
MD5 db1bc2765935d3614b0eefc7434d39e7
BLAKE2b-256 b044ca0e85c5ecd8703acd8cc2b2134d76892461292a8ab417308e76c432143b

See more details on using hashes here.

File details

Details for the file leetcode_sync_cli-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for leetcode_sync_cli-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 754ceee4c65f6e8e4a41fd2ad8df28508528419ebbbf61386b384e238eb27c4c
MD5 6dc53f911b073e79ea8b192a7bab8d32
BLAKE2b-256 0f725dfa69815de6fc24ddab1733cf9179f89bf44c4650fc60afbd4177f80795

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page