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 — one command.

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

Installation

pip install lc2git

Or install from source:

git clone https://github.com/you/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.1.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.1-py3-none-any.whl (13.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: lc2git-1.0.1.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.1.tar.gz
Algorithm Hash digest
SHA256 7826b90c39cf3b9867f85977d3d3a85cb063b554f102046494f636e1a5da93c0
MD5 b27bf7c71276915aae3032c04c7cbe2c
BLAKE2b-256 255124130b590b55d4edb4b134bb9d0ddfeefb14c3c74e4091aa2af2929bac44

See more details on using hashes here.

File details

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

File metadata

  • Download URL: lc2git-1.0.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c4a7b0ccf9e1b42a023372cecc06aa271305a5bcb0aab6d7ebbcbc87400bf038
MD5 027038df70a50ba9c8208fdf067316b0
BLAKE2b-256 e3870f77d29a775cb1aaa12f6108fd8e58dbd4a18136ae2af899fd734841fc4f

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