A tool to organize and generate LeetCode problems and solutions.
Project description
leetcrate
A CLI tool that fetches LeetCode problems via the GraphQL API and generates language-specific boilerplate solution files with runnable test harnesses.
Table of Contents
- leetcrate
Overview
- Fetch problem metadata via LeetCode's GraphQL API
- Generate boilerplate solutions in five languages: Python, JavaScript, Go, Java, and C++
- Populate runnable test harnesses for every supported language
- Organize output inside
problems/undercompleted/andincomplete/ - Optional workspace folders for contests, courses, and interview prep
Prerequisites
- Python 3.10+ on your
PATH - requests package (installed automatically with the package)
Installation
From PyPI
pip install leetcrate
NOTE: if you have installed Python through windows store, you need to do this extra step.
- After installing leetcrate, add package to your env variables PATH.
set PATH=%PATH%;C:\Users\YOUR_USER_NAME\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\Scripts
OR more generally (for those not using python 3.12)
set PATH=%PATH%;%USERPROFILE%\AppData\Local\Packages\PythonSoftwareFoundation.Python.<PYTHON_VERSION>_qbz5n2kfra8p0\LocalCache\local-packages\Python<MAJOR><MINOR>\Scripts
For some reason, Python is set up wrong when it is installed from windows store. Maybe theres a workaround for this, that I don't know about yet.
Configuration
Run leetcrate init in your workspace directory to create a settings.INI:
[LeetCode Problem Generator]
; Pick from [python, cpp, java, javascript, go]
language = python
[Framework]
; set these to true and run 'leetcrate update' to add other folders to your repo after the fact.
contests = false
courses = false
interview = false
Accepted language values (case-insensitive):
| Value | File extension |
|---|---|
python |
.py |
javascript / js |
.js |
go |
.go |
java |
.java |
c++ / cpp |
.cpp |
The file is re-read on every run — no restart needed after a language change.
Usage
init
First-time setup. Creates the workspace framework and settings.INI.
leetcrate init
You will be prompted to choose a full framework or a minimal install;
1. minimal install -> For when you already have a file system and only want to use the package.
2. framework -> For when you are starting fresh, installs the package and creates framework;
optionally enable the contests, courses, and interview folders.
generate | gen | get | create
Fetch a problem and write template files.
leetcrate generate two-sum
# or pass the full URL:
leetcrate generate https://leetcode.com/problems/two-sum/
# omit the slug to be prompted interactively:
leetcrate generate
or you can use the alternatives; gen|get|create
leetcrate `gen`|`get`|`create` two-sum
# or pass the full URL:
leetcrate `gen`|`get`|`create` https://leetcode.com/problems/two-sum/
# omit the slug to be prompted interactively:
leetcrate `gen`|`get`|`create`
What happens:
- Fetches problem data (title, difficulty, description, tags)
- Downloads the official code snippet for your configured language
- Parses function signatures and example test cases
- Creates
problems/incomplete/<id>_<Title>/ - Writes a language-specific file with a stub solution and a working test harness
If the folder already exists the script updates it without overwriting any
solution you have already written. Move a finished solution into
problems/completed/ to track progress.
update
Add any optional folders that are enabled in settings.INI but not yet
present on disk.
leetcrate update
commands overview / all commands
# tool commands
leetcrate init
leetcrate update
leetcrate generate _some_leetcode_slug_
# or
leetcrate gen _some_leetcode_slug_
leetcrate get _some_leetcode_slug_
leetcrate create _some_leetcode_slug_
# Basic commands
leetcrate --version
leetcrate --update
leetcrate --help
Folder Structure
Running leetcrate init with all optional folders enabled creates:
./_your_workspace_/
├── settings.INI
├── problems/
│ ├── completed/
│ └── incomplete/
[OPTIONAL]
├── contests/
│ ├── bi_weekly/
│ └── weekly/
├── courses/
└── interview/
├── mock_assessment/
└── online_interview/
└── [Name of workplace]/
A generated problem folder looks like:
problems/
incomplete/
1_Two_Sum/
description.txt # Cleaned plain-text problem statement
two_sum.py # Boilerplate stub + runnable test harness
Generated File Format
Each solution file contains:
- The official function/class stub from LeetCode
- A test harness that exercises every example case from the problem statement
- A git commit message template at the bottom (for copy-paste convenience)
Language Notes
| Language | Test runner style |
|---|---|
| Python | if __name__ == "__main__" with a for loop over cases |
| JavaScript | console.log for each case |
| Go | main() with typed slice literals and fmt.Println |
| Java | Object[][] cases, casted to parameter types, printed with Arrays.toString |
| C++ | std::vector<std::pair<...>> cases, printed via helper loops |
Linked-list problems automatically inject the ListNode class and a
build_linked_list helper into the generated file.
Dev Tools
Both scripts live in tests/ and are intended for local development only.
tests/generator_test.py
Bulk-generates a hardcoded list of problems using leetcrate generate or leetcrate gen.
Edit the slugs list inside the file to change which problems are scaffolded.
python tests/generator_test.py
tests/run_test.py
Discovers every problem folder under problems/ and runs the solution file
that matches the language in settings.INI.
python tests/run_test.py
Runtime requirements per language:
| Language | Required on PATH |
|---|---|
| python | python |
| javascript | node |
| go | go |
| java | javac + java |
| cpp / c++ | g++ |
Troubleshooting
| Issue | Fix |
|---|---|
No settings.INI found |
Run leetcrate init first |
Warning: Could not read settings.INI |
Ensure the file is UTF-8 encoded and contains a valid language = value line |
| Locked problem fetch fails | Log in to LeetCode in a browser first, or avoid locked problems |
| Wrong types in test harness | Check your language value in settings.INI matches the file you want to run |
| Need to re-generate after language change | Delete the folder and run leetcrate generate <slug> again |
leetcrate not recognized after install |
Run cmd as Administrator, then pip uninstall leetcrate -y and pip install leetcrate |
TODO:
-
Make generator for extra testcases
- Fix broken testcase generator
-
Make generator for git push description.
-
crate tests/run_test.py - will run the 4 generates files (according to set language in settings.ini) (NOTE: this is a dev tool).
- install c++, java, javascript and go in /.venv, so dev can run the codes locally and not rely on online compilers while building.
-
crate tests/generator_test.py - will generates cases for set language (settings.ini) for the leetcode projects set in generator_test (NOTE: this is a dev tool).
-
Update v0.2.0 - descr:
add clause for handling nodes, add Adjusted test runner(iterates over (vals, pos) pairs for linked list problems), dynamic type notations, add dynamic comments.- Update script: Python
- Update script: C++
- Update script: Java
- Update script: JavaScript
- Update script: Go
-
Add docs to python components
-
Turn project into package
- Add package directory structure (src/ if needed)
- Ensure all modules have init.py
- Update pyproject.toml with metadata
- Specify dependencies in pyproject.toml
- Add classifiers and license info
- Add README.md with usage
- Add LICENSE file
- Add MANIFEST.in if needed
- Test local install (pip install -e .)
- Verify import/usage from clean env
[OPTIONAL]
- (Optional) Add setup.cfg/setup.py
- (Optional) Add tests/ directory
- (Optional) Set up CI
- (Optional) Publish to PyPI
[ plans for 1.0 -> 2.0 ]
-
add abbreviation of command "generate" -> "gen" (also added some additional alternatives)
-
Add checker that checks /completed and /incomplete if you already have done it. if so you should get the prompt to; 'abort' (default), 'replace', or 'create-variant' (/1_two_sum[2])
-
Add Migration tool - for when users already have a repo for thier leetcode solutions and want to migrate them into the dataframe
-
add command; "leetcrate migrate Path_To_Solutions"
-
default - assuming the user's Path_To_Solutions is a regular folder;
Section Title
Content inside the expandable section goes here. ``` ./_Path_To_Solutions_/ ├── _leetcode_solution_1_ ├── _leetcode_solution_2_ ├── _leetcode_solution_3_ . . . └──_leetcode_solution_n_ ``` </details> -
variant - For when the user's repo has a more complex file structure - add a parser that takes a structure_description as a param, then let the user describe the structure somewhere.
Section Title
Content inside the expandable section goes here. ``` ./_Path_To_Solutions_/ ├── _leetcode_solution_1_ ├── _leetcode_solution_2_ ├── _leetcode_solution_3_ . . . └──_leetcode_solution_n_ ├── problems/ │ ├── completed/ │ └── incomplete/ [OPTIONAL] ├── contests/ │ ├── bi_weekly/ │ └── weekly/ ├── courses/ └── interview/ ├── mock_assessment/ └── online_interview/ └── [Name of workplace]/ ``` </details> -
options:
-
(safe but easy)Parse + iterates solution_files then; generates templates based on them.
read more..
1. This will require either that, the user _solution_files_ provides something uniqe and recognizable.
a. the _solution_file_ has the slug in its name,
b. the proper name function name in side of it i.e.: "... def twoSum...", ,
c. the user simply adds a list of solutions, but that sort of ruins the purpose.
1. The migration tool will then essentially run "leetcrate generate _slug_" for each _solution_file_.
2. Then the user will have to manually replace the templates with their own code, which is safer but more laborous for the user.
-
(less safe but proper) Parse + iterates solution_files then; automatically integrate content to template.
read more..
will generate template from it (require recognizable naming),
then make a copy _solution_files_ (for saftey),
then insert its content into the generated tempalte.
! might need a rollback failsafe since this could be destructive depending on how i make it, or issue a warning to make sure the user is backed up before continuing.
-
-
Add VCS tools:
- Add command - marking solution_folder as solved -> move to ./completed
- Add command - pushing completed file to repo w/ generated commit message
- Add command - pushing incomplete file to repo w/ generated commit message
- Add command - commit slug - commits solution_folder to repo w/ generated commit message, based on its location. (/completed, /incomplete)
-
Add more languages
- [1.1]
- Typescript
- C#
- C *gulp*
- Rust *gulp*
- [1.2]
- Kotlin
- Swift
- Dart
- PHP
- [1.3]
- Ruby
- Racket
- Scala
- Erlang
- Elixir
- [1.1]
-
Make compatible for other package-types; npm, NuGet, Apache Maven, etc [ MAYBE ]
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
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 leetcrate-1.2.2.tar.gz.
File metadata
- Download URL: leetcrate-1.2.2.tar.gz
- Upload date:
- Size: 34.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
739fa207aff2bffb62f271f7d3604a6eab2d8d67ba43491fa074144c8a333922
|
|
| MD5 |
305bae611375b58d9361439653e98229
|
|
| BLAKE2b-256 |
8757bae3999e8071746cc45115c354c7a1a39992cd72da472da34df6988053b2
|
File details
Details for the file leetcrate-1.2.2-py3-none-any.whl.
File metadata
- Download URL: leetcrate-1.2.2-py3-none-any.whl
- Upload date:
- Size: 35.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f126fd512047b0c7acc4a9b9ff2a988296d02774db7009fb6058e5334b9d8dec
|
|
| MD5 |
40b4c9d7bdac5bf4ba62f9d92ec0c501
|
|
| BLAKE2b-256 |
5f5370ffa3099efd56bc2a5105df6b4a6c1d6070b16aebecb2361c8e326cacfb
|