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.3.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.3-py3-none-any.whl (13.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: lc2git-1.0.3.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.3.tar.gz
Algorithm Hash digest
SHA256 d54562b7cb7200f545a9c99b01ea69e92b0cf9388e3364046fad6a6579d5c7dc
MD5 6e978c119b53de1bf6956cab4d668ac7
BLAKE2b-256 37ccec491f809db11aaa2dfd5a1ba7099d903b576f08c55958d0fd346afb338d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: lc2git-1.0.3-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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 d05c558209ad62d37044fe851f91c07208a7f0885d3468f82f756ae761030ee7
MD5 885236df7375777a3d7a73a2cf81937b
BLAKE2b-256 a23fa03265f4646a9164d1e3825c72e5f953010f50b830a6295f73ce335cbef9

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