Solve LeetCode problems in your local IDE
Project description
Leet2Local
A CLI tool that brings LeetCode problems into your local IDE. Fetch problem descriptions, solve in your editor, run tests locally, and submit directly to LeetCode — all from the terminal.
lc fetch 1 --lang python
lc run 1
lc submit 1
Features
- Fetch any problem by number — creates a local directory with the description, code stub, and sample test cases
- Run locally — executes your solution against sample test cases without touching LeetCode servers
- Submit remotely — sends your code to LeetCode and polls for full results including hidden test cases, runtime, and memory percentile
- Multi-language — Python, JavaScript, C++, and Java
- VS Code integration — generates
tasks.jsonfor keyboard-shortcut access to all commands - Secure auth — session cookies stored in OS native keychain (Windows Credential Manager / macOS Keychain)
Installation
Requirements: Python 3.11+
pip install leet2local
Or install from source:
git clone https://github.com/dhineshtheprogrammer/leet2local.git
cd Leet2Local
pip install -e .
For development (includes pytest and ruff):
pip install -e ".[dev]"
Quick Start
1. Log in
Get your session cookies from your browser after logging in to leetcode.com:
- Open DevTools → Application → Cookies →
leetcode.com - Copy
LEETCODE_SESSIONandcsrftoken
lc login
2. Fetch a problem
lc fetch 1 # Two Sum, defaults to Python
lc fetch 42 --lang cpp # Trapping Rain Water in C++
This creates:
./leetcode/1-two-sum/
├── question.md # Problem description in Markdown
├── solution.py # Code stub from LeetCode
└── test_cases.json # Sample inputs and expected outputs
3. Write your solution
Open solution.py in your editor and implement the function.
4. Run locally
lc run 1
┌─ Test Results ──────────────────────────────────┐
│ # │ Status │ Details │
│ 0 │ PASS │ │
│ 1 │ PASS │ │
│ 2 │ FAIL │ got: [] expected: [0, 1] │
└────────────────────────────────────────────────-┘
✗ 1/3 test(s) failed
5. Submit to LeetCode
lc submit 1
┌─ Accepted ──────────────────────────────────────┐
│ Runtime: 52 ms (beats 87.3%) │
│ Memory: 16.4 MB (beats 62.1%) │
│ Tests: 54/54 │
└─────────────────────────────────────────────────┘
Commands
| Command | Description |
|---|---|
lc login |
Store LeetCode session cookies securely |
lc fetch <number> [--lang] |
Fetch problem and create local files |
lc run <number> |
Run solution against sample test cases |
lc submit <number> |
Submit to LeetCode and get full results |
lc config |
Show current configuration |
lc config --set key=value |
Update a config value |
lc config --vscode-init |
Generate .vscode/tasks.json |
Language Support
| Language | Flag | Runtime Required |
|---|---|---|
| Python 3 | --lang python |
python |
| JavaScript | --lang javascript |
node |
| C++ | --lang cpp |
g++ |
| Java | --lang java |
javac, java |
Set your default language so you don't need --lang on every fetch:
lc config --set settings.default_language=javascript
Configuration
On first run, create .leet2local.toml in your project root:
[settings]
default_language = "python" # python | javascript | cpp | java
problems_dir = "./leetcode" # where problem directories are created
run_mode = "local" # local | remote
[api]
graphql_endpoint = "https://leetcode.com/graphql"
request_timeout = 30
max_retries = 5
[runtime]
python_cmd = "python"
node_cmd = "node"
java_cmd = "java"
javac_cmd = "javac"
cpp_compiler = "g++"
runner_timeout = 10 # seconds per test execution
[display]
show_difficulty = true
show_tags = false # hide tags to avoid spoilers
syntax_highlight = true
Config is loaded from the nearest .leet2local.toml walking up from the current directory, falling back to ~/.config/leet2local/config.toml.
VS Code Integration
Generate keyboard-shortcut tasks:
lc config --vscode-init
This creates .vscode/tasks.json with three tasks. Add to your keybindings.json:
[
{ "key": "ctrl+shift+r", "command": "workbench.action.tasks.runTask", "args": "LC: Run Local" },
{ "key": "ctrl+shift+s", "command": "workbench.action.tasks.runTask", "args": "LC: Submit" }
]
How It Works
lc fetch 1
└─ GraphQL: questionList (slug resolution)
└─ GraphQL: questionData (description, stub, test cases)
└─ HTML → Markdown (BeautifulSoup + markdownify)
└─ Write question.md, solution.py, test_cases.json
lc run 1
└─ Read test_cases.json
└─ Render Jinja2 test harness template
└─ subprocess → python harness.py
└─ Parse LEET_PASS / LEET_FAIL / LEET_ERROR output lines
lc submit 1
└─ GraphQL: submitCode mutation → submission_id
└─ Poll: checkSubmission every 2s
└─ Display Rich result table
Project Structure
Leet2Local/
├── leet2local/
│ ├── cli.py # Typer CLI entry point
│ ├── auth.py # Login, keyring credential storage
│ ├── fetcher.py # GraphQL client, file creation
│ ├── runner.py # Local runner dispatcher
│ ├── submitter.py # Remote submission + polling
│ ├── html_parser.py # HTML → Markdown conversion
│ ├── models.py # Pydantic data models
│ ├── config.py # TOML config management
│ ├── queries.py # GraphQL query strings
│ ├── rate_limiter.py # Tenacity retry decorator
│ └── runners/
│ ├── base.py # Abstract Runner base class
│ ├── python_runner.py
│ ├── javascript_runner.py
│ ├── cpp_runner.py
│ └── java_runner.py
├── templates/ # Jinja2 test harness templates
├── scripts/
│ └── generate_slug_map.py # Build slug fallback map
└── tests/
Limitations
- Sample test cases only for local runs — hidden test cases require
lc submit - LeetCode's API is unofficial and undocumented; field names may change
- C++ and Java require the respective compilers installed and on PATH
lc submitrequires a valid session cookie (obtained vialc login)
Development
# Run tests
pytest
# Lint
ruff check .
# Regenerate slug fallback map (run once, requires internet)
python scripts/generate_slug_map.py
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file leet2local-0.1.0.tar.gz.
File metadata
- Download URL: leet2local-0.1.0.tar.gz
- Upload date:
- Size: 73.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c2bd03570de0e42331482457c2fe4f2b08692637306a8e99b24317b84c4a930b
|
|
| MD5 |
dffe7e0f6f6a9c87a2b599e933f08d4a
|
|
| BLAKE2b-256 |
54f7147a909feed8acb0a37ff51ebf62d892e2030f9de5cd29231eb57a0a70d9
|
Provenance
The following attestation bundles were made for leet2local-0.1.0.tar.gz:
Publisher:
publish.yml on dhineshtheprogrammer/leet2local
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
leet2local-0.1.0.tar.gz -
Subject digest:
c2bd03570de0e42331482457c2fe4f2b08692637306a8e99b24317b84c4a930b - Sigstore transparency entry: 1868936116
- Sigstore integration time:
-
Permalink:
dhineshtheprogrammer/leet2local@93adb1d6466d92ba07c02b4378c8c95de394c71f -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/dhineshtheprogrammer
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@93adb1d6466d92ba07c02b4378c8c95de394c71f -
Trigger Event:
push
-
Statement type:
File details
Details for the file leet2local-0.1.0-py3-none-any.whl.
File metadata
- Download URL: leet2local-0.1.0-py3-none-any.whl
- Upload date:
- Size: 82.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3afd7e1e388baad9d7671ddf359bcf509936d440366ee476bfd90c6b85f31622
|
|
| MD5 |
53b263e20acc690d1846abfd835050fe
|
|
| BLAKE2b-256 |
077e8230e5e210532fdb2b98abf2523e16746a6eb723072646e560ddc511d9c0
|
Provenance
The following attestation bundles were made for leet2local-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on dhineshtheprogrammer/leet2local
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
leet2local-0.1.0-py3-none-any.whl -
Subject digest:
3afd7e1e388baad9d7671ddf359bcf509936d440366ee476bfd90c6b85f31622 - Sigstore transparency entry: 1868936222
- Sigstore integration time:
-
Permalink:
dhineshtheprogrammer/leet2local@93adb1d6466d92ba07c02b4378c8c95de394c71f -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/dhineshtheprogrammer
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@93adb1d6466d92ba07c02b4378c8c95de394c71f -
Trigger Event:
push
-
Statement type: