Skip to main content

Sync your LeetCode solutions, stats and problem descriptions to GitHub

Project description

lc2git 🚀

Push your daily LeetCode solutions to GitHub automatically.

Features

  • Fetches all accepted submissions from today (deduplicates per problem)
  • Organises files by date & problem: YYYY-MM-DD/0001-two-sum/solution.py
  • Auto-generates a README.md per problem with difficulty, tags, runtime & memory
  • Adds a language-specific header comment to every solution file
  • Supports 20+ languages (Python, Java, C++, Go, Rust, TypeScript, …)
  • Credentials stored securely at ~/.config/lc2git/config.json (mode 600)
  • All secrets can also be passed via environment variables

Install

pip install lc2git

Or install from source:

git clone https://github.com/prasanth3316/lc2git.git
cd lc2git
pip install -e .

Quick Start

1. Configure credentials

lc2git configure

You'll be prompted for:

Field Where to find it
GitHub PAT github.com → Settings → Developer settings → Personal access tokens → (needs repo scope)
GitHub repo e.g. alice/leetcode-solutions (must already exist)
LEETCODE_SESSION leetcode.com → DevTools → Application → Cookies → LEETCODE_SESSION
csrftoken Same cookie jar → csrftoken

2. Sync today's solutions

lc2git sync

3. Preview without pushing

lc2git sync --dry-run

Output Layout

2025-05-07/
  0001-two-sum/
    solution.py        ← your code + header comment
    README.md          ← problem metadata
  0042-trapping-rain-water/
    solution.cpp
    README.md

Example solution file

# Two Sum
# Difficulty : Easy
# Tags       : Array, Hash Table
# Runtime    : 52 ms
# Memory     : 16.4 MB
# Link       : https://leetcode.com/problems/two-sum/

class Solution:
    def twoSum(self, nums, target):
        seen = {}
        for i, n in enumerate(nums):
            if target - n in seen:
                return [seen[target - n], i]
            seen[n] = i

Environment Variables

All credentials can be provided via environment variables (useful for CI):

export GITHUB_TOKEN=ghp_...
export GITHUB_REPO=alice/leetcode-solutions
export GITHUB_BRANCH=main
export LEETCODE_SESSION=eyJ...
export LEETCODE_CSRF_TOKEN=abc123...

lc2git sync

Automate with cron

Run every night at 23:55 to capture the day's work:

# crontab -e
55 23 * * * /usr/local/bin/lc2git sync >> ~/.lc2git.log 2>&1

Commands

Command Description
lc2git configure Interactive credential setup
lc2git sync Fetch & push today's solutions
lc2git sync --dry-run Fetch only, no push
lc2git show-config Print config (tokens masked)

How LeetCode Auth Works

LeetCode's API uses two cookies for authentication:

  • LEETCODE_SESSION — your main session token
  • csrftoken — required for POST/GraphQL requests

These expire periodically (usually every 30–90 days). Re-run lc2git configure when they do.

License

MIT

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

lc2git-1.0.2.tar.gz (13.0 kB view details)

Uploaded Source

Built Distribution

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

lc2git-1.0.2-py3-none-any.whl (13.0 kB view details)

Uploaded Python 3

File details

Details for the file lc2git-1.0.2.tar.gz.

File metadata

  • Download URL: lc2git-1.0.2.tar.gz
  • Upload date:
  • Size: 13.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.18

File hashes

Hashes for lc2git-1.0.2.tar.gz
Algorithm Hash digest
SHA256 a1c2bdd5eadaf0a4d93d5ea0eb428b8d48d700a81e41ce63ecbd16a8b2f52cb1
MD5 8af96a22afd694a77689f9c4bdc0e051
BLAKE2b-256 d283d7ad101e1c65433b80b3adc52c63bebfbeb85c3fecad4fcc2d809995b807

See more details on using hashes here.

File details

Details for the file lc2git-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: lc2git-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 13.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.18

File hashes

Hashes for lc2git-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c683200789a78847bf5bb8ccfe0571951f4a7f42f3654e76aa0361b00215ae42
MD5 f31cb4d927f4803a81524f9a44d4d6f7
BLAKE2b-256 be8a1c856c9cec57c6898ac83c32325429bcdfddcd3cba3eb31aef5217da3d64

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