Skip to main content

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

Metadata

Release files for lc2git 1.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for lc2git 1.0.3
File Size Uploaded Provenance Actions
lc2git-1.0.3.tar.gz 13.0 kB Without provenance Details for lc2git-1.0.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for lc2git 1.0.3
File Interpreter ABI Platform Actions
lc2git-1.0.3-py3-none-any.whl Python 3 none any Details for lc2git-1.0.3-py3-none-any.whl

Total release size: 26.0 kB

Release files / lc2git-1.0.3.tar.gz

Download URL lc2git-1.0.3.tar.gz
Size 13.0 kB
Tags Source
SHA-256 checksum
How to use checksums
d54562b7cb7200f545a9c99b01ea69e92b0cf9388e3364046fad6a6579d5c7dc
BLAKE2b-256 checksum
How to use checksums
37ccec491f809db11aaa2dfd5a1ba7099d903b576f08c55958d0fd346afb338d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.18

Release files / lc2git-1.0.3-py3-none-any.whl

Download URL lc2git-1.0.3-py3-none-any.whl
Size 13.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d05c558209ad62d37044fe851f91c07208a7f0885d3468f82f756ae761030ee7
BLAKE2b-256 checksum
How to use checksums
a23fa03265f4646a9164d1e3825c72e5f953010f50b830a6295f73ce335cbef9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.18

Security for lc2git 1.0.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page