A Dart package providing an unofficial API for interacting with LeetCode. This package allows you to fetch user details, language statistics, user badges, recent submissions, solved problem counts, and more.
Scrape problem data: Access problem titles, difficulties, categories, acceptance rates, and potentially other publicly available information (subject to LeetCode's website structure changes).
Retrieve user data: Fetch details like profile information, language-wise problem counts, badges earned, recent submissions, and solved problem count.
Get problem details: Obtain information about the daily challenge problem or a specific problem by its title slug.
Lightweight and flexible: Designed for ease of use in various programming environments.
Unofficial and community-driven: Continuously maintained and improved by the developer community.
Unofficial: This API is not affiliated with or endorsed by LeetCode.
Respectful usage: Use responsibly and ethically, adhering to LeetCode's terms of service and avoiding excessive scraping that could overload their servers.
Rate limiting: Be prepared to implement rate limiting mechanisms in your code to prevent overwhelming LeetCode's infrastructure. LeetCode may throttle requests or block IP addresses if usage patterns violate their guidelines.
To use this package, add leetcode_api
as a dependency in your pubspec.yaml
file:
dependencies:
leetcode_api: ^1.0.0
Then, run:
$ flutter pub get
import 'package:leetcode_api/leetcode_api.dart';
Initialize the API with your LeetCode username:
await LeetCodeAPI.initializeApp('your_username');
Now, you can use the provided methods to interact with the LeetCode API:
final UserData? userData = await LeetCodeAPI.instance.userData();
final LanguagesAndProblemCounts? = await LeetCodeAPI.instance.languageStats();
final LCBadges? userBadges = await LeetCodeAPI.instance.userBadges();
final LCBadge? userActiveBadge = await LeetCodeAPI.instance.userActiveBadge();
final Submissions? recentSubmissions = await LeetCodeAPI.instance.recentSubmissions();
final SubmitStats? solvedProblemCount = await LeetCodeAPI.instance.solvedProblemCount();
final Problem dailyProblem = await LeetCodeAPI.instance.dailyProblem();
final Problem selectedProblem = await LeetCodeAPI.instance.selectProblem(titleSlug: 'two-sum');
Initialize the LeetCode API with your username.
await LeetCodeAPI.initializeApp('your_username');
Fetch user details.
final UserData ?userData = await LeetCodeAPI.instance.userData();
Fetch language statistics.
final LanguagesAndProblemCounts? languageStats = await LeetCodeAPI.instance.languageStats();
Fetch user badges.
final LCBadges? userBadges = await LeetCodeAPI.instance.userBadges();
Fetch user's active badge.
final LCBadge? userActiveBadge = await LeetCodeAPI.instance.userActiveBadge();
Fetch recent submissions.
final Submissions? recentSubmissions = await LeetCodeAPI.instance.recentSubmissions();
Fetch the count of solved problems.
final SubmitStats? solvedProblemCount = await LeetCodeAPI.instance.solvedProblemCount();
Fetch the daily problem.
final Problem? dailyProblem = await LeetCodeAPI.instance.dailyProblem();
Fetch a specific problem by its title slug.
final Problem? selectedProblem = await LeetCodeAPI.instance.selectProblem(titleSlug: 'problem_title_slug');
The API methods may throw LeetCodeAPIException if not initialized or if the user does not exist.
try {
// API method calls
} on LeetCodeAPIException catch (e) {
print('LeetCode API Exception: ${e.errorCode}');
}
We welcome contributions from the community! Feel free to submit pull requests with enhancements, bug fixes, or additional features.