{"id":17167615,"url":"https://github.com/1101-1/leetcode-rust-api","last_synced_at":"2025-04-13T15:34:49.848Z","repository":{"id":178948835,"uuid":"662632150","full_name":"1101-1/Leetcode-Rust-API","owner":"1101-1","description":"A full-featured Leetcode API on Rust language","archived":false,"fork":false,"pushed_at":"2024-04-24T08:50:56.000Z","size":65,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-04-24T13:56:23.479Z","etag":null,"topics":["api","api-wrapper","leetcode","leetcode-api","leetcode-rust","rust"],"latest_commit_sha":null,"homepage":"https://crates.io/crates/leetcoderustapi","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/1101-1.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-07-05T14:45:57.000Z","updated_at":"2024-04-24T08:51:00.000Z","dependencies_parsed_at":"2024-04-24T09:55:02.047Z","dependency_job_id":"adc86ff6-1881-4030-9f53-33ea6a4970b4","html_url":"https://github.com/1101-1/Leetcode-Rust-API","commit_stats":null,"previous_names":["1101-1/leetcoderustapi","1101-1/leetcode-rust-api"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/1101-1%2FLeetcode-Rust-API","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/1101-1%2FLeetcode-Rust-API/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/1101-1%2FLeetcode-Rust-API/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/1101-1%2FLeetcode-Rust-API/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/1101-1","download_url":"https://codeload.github.com/1101-1/Leetcode-Rust-API/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248736462,"owners_count":21153601,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","api-wrapper","leetcode","leetcode-api","leetcode-rust","rust"],"created_at":"2024-10-14T23:09:14.515Z","updated_at":"2025-04-13T15:34:49.828Z","avatar_url":"https://github.com/1101-1.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# LeetCode API Rust Library\nThis Rust library provides a convenient way to interact with the LeetCode API, allowing you to programmatically access LeetCode problems, submit solutions, and retrieve submission results.\n## Features\n* Retrieve a list of LeetCode problems.\n* Fetch problem details, including the problem description, constraints, and examples.\n* Submit solutions to LeetCode problems.\n* Check submission results, including status, runtime, and memory usage.\n\n## Installation\n\nAdd the following line to your `Cargo.toml` file:\n```toml\n[dependencies]\nleetcoderustapi = \"1.0.8\"\n```\n## Usage\n### Authentication\nTo use the LeetCode API, you need to obtain an authentication token. Follow the instructions provided by LeetCode to obtain your token.\n\n### Example: Action with problems\n```rust\nuse leetcoderustapi::{problem_build::{Tags, Category, Difficulty, Status}, UserApi, ProgrammingLanguage,};\n\n#[tokio::main]\nasync fn main() {\n    // Set cookie from leetcode\n    let token = std::env::var(\"COOKIE\").expect(\"cookie doesn't set\");\n\n    // Create a new LeetCode client\n    let api = UserApi::new(\u0026token).await.unwrap();\n\n    // Show found problems by keyword and show 5 notes\n    let show_problems = api.show_problm_list(\"sum\", 5).await.unwrap();\n\n    // Find problems by properties with creating problem builder\n    let problems_builder = api\n        .problem_builder()\n        .set_category(Category::Algorithms)\n        .set_difficulty(Difficulty::Easy)\n        .set_keyword(\"sum\")\n        //max show notes limit is 2763; default is 5\n        .set_note_limit(3)\n        .set_status(Status::Solved)\n        //max tags over 50+\n        .set_tags(vec![\n            Tags::Array,\n            Tags::BinarySearch,\n        ])\n        .build()\n        .await\n        .unwrap();\n\n    // Fetch the full data for a specific problem by it's name\n    let problem_info = api.set_problem(\"two sum\").await.unwrap();\n\n    // Fetch the full data for a specific problem by it's ID\n    let problem_info = api.set_problem_by_id(1).await.unwrap();\n\n    // Retrieve previous submissions to this problem\n    let my_submissions = problem_info.my_submissions().await.unwrap();\n\n    // Retrieve code snippets\n    let code_snippets = problem_info.code_snippets().unwrap();\n\n    // Retrieve solution info\n    let solution_info = problem_info.solution_info().unwrap();\n\n    // Retrieve related topics\n    let related_topics = problem_info.related_topics();\n\n    // Retrieve similar questions\n    let similar_questions = problem_info.similar_questions().unwrap();\n\n    // Retrieve stats\n    let stats = problem_info.stats().unwrap();\n\n    // Retrieve hints\n    let hints = problem_info.hints();\n\n    // Retrieve description\n    let description = problem_info.description().unwrap();\n\n    // Retrieve difficulty\n    let difficulty = problem_info.difficulty();\n\n    // Retrieve likes and dislikes\n    let likes = problem_info.rating().unwrap();\n\n    // Retrieve category\n    let category = problem_info.category();\n\n    // We also can send submissions and tests\n    // Need to specify a lang and provided code\n    let subm_response = problem_info\n        .send_subm(ProgrammingLanguage::Rust, \"impl Solution { fn two_sum() {}}\")\n        .await\n        .unwrap();\n    let test_response = problem_info\n        .send_test(ProgrammingLanguage::Rust, \"impl Solution { fn two_sum() {}}\")\n        .await\n        .unwrap();\n}\n```\n\n### Example: Actions with Self profile\n```rust\n#[tokio::main]\nasync fn main() {\n    // Set cookie from leetcode\n    let token = std::env::var(\"COOKIE\").expect(\"cookie doesn't set\");\n\n    // Create a new LeetCode client\n    let api = UserApi::new(\u0026token).await.unwrap();\n\n    // Create interaction with profile\n    let user_profile = api.my_profile().await.unwrap();\n\n    // Create empty list of the problems with provided name\n    user_profile\n        .create_list(\"my_new_favorite_list\")\n        .await\n        .unwrap();\n\n    // Rename list\n    user_profile\n        .rename_list(\"my_new_favorite_list\", \"hard_problems\")\n        .await\n        .unwrap();\n\n    // Set list puplic\n    user_profile.set_public(\"hard_problems\").await.unwrap();\n\n    // Set list private\n    user_profile.set_private(\"hard_problems\").await.unwrap();\n\n    // Get link to the list if it is a public\n    let share_list_url = user_profile.get_share_url(\"hard_problems\").await.unwrap();\n\n    // Show existing lists\n    let lists = user_profile.show_lists();\n\n    // Delete list with provided name\n    user_profile\n        .delete_list(\"hard_problems\")\n        .await\n        .unwrap();\n\n    // Show users last 10 notification\n    let notifications = user_profile.get_notifications().await.unwrap();\n\n    // Deactivate token(logout)\n    user_profile.deactivate_token().await.unwrap();\n}\n```\n### Example: Actions with Public user profile\n```rust\n#[tokio::main]\nasync fn main() {\n    // Set cookie from leetcode\n    let token = std::env::var(\"COOKIE\").expect(\"cookie doesn't set\");\n\n    // Create a new LeetCode client\n    let api = UserApi::new(\u0026token).await.unwrap();\n\n    // Find public user\n    let user = api\n        .find_profile(\"1101-1\")\n        .await;\n\n    // Check public user common stats\n    let user_stats = user.\n        user_stats()\n        .await\n        .unwrap();\n\n    // Check what langs used user\n    let lang_stats = user\n        .language_stats()\n        .await\n        .unwrap();\n    \n    // Check what problems (by tags) solve user\n    let skill_stats = user\n        .skill_stats()\n        .await\n        .unwrap();\n\n    // Show rating by beating problems\n    let beat_stats = ser\n        .problem_beat_stats()\n        .await\n        .unwrap();\n\n     // Show recent submissons of user\n    let beat_stats = ser\n        .recent_subm_list()\n        .await\n        .unwrap();\n}\n```\n\n\n#### Important\nReplace `\"COOKIE\"` with your actual LeetCode authentication cookie.\n\nFor example format in `.env` file:\n\n```env\nCOOKIE=\"csrftoken=gN3mmFEKoBFHLZuiHEvZYupqirq7brDmi845GhUK8xBa9u3SUVkgTPFTPsLFuAzR; _ga_CDRWKZTDEX=GS1.1.1688568040.1.1.1688568081.19.0.0; _ga=GA1.1.2048740381.1688568040; _dd_s=rum=0\u0026expire=1688568980299; NEW_PROBLEMLIST_PAGE=1\"\n```\n\n### License\nThis library is licensed under the `MIT License`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F1101-1%2Fleetcode-rust-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F1101-1%2Fleetcode-rust-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F1101-1%2Fleetcode-rust-api/lists"}