A robust RESTful API to fetch and display LeetCode statistics for users, built with FastAPI.
hosted at leetcode-stats.tashif.codes
The root URL (/) now features an interactive LeetCode Profile Analyzer dashboard. Enter any LeetCode username to instantly view:
- Profile Card: Avatar, real name, country, company, school, skills, about me, and social links (GitHub, Twitter, LinkedIn)
- Contribution Stats: Points, question count, testcase count
- Key Stats: Total solved, acceptance rate, ranking, contests attended, contest rating, badges count
- Modern, responsive UI for quick analysis
- Powered by the API endpoints below
- Retrieve user's solved problems count (easy, medium, hard)
- Get detailed submission statistics
- View contest ratings and historical rankings
- Track progress over time
- Easy integration with other applications
- Rate-limited endpoints to prevent abuse
GET /{username}
Retrieves the basic statistics for a LeetCode user.
username(path): LeetCode username
Returns user's LeetCode statistics including:
- Total solved problems (by difficulty)
- Acceptance rate
- Submission counts
- Ranking
- Contribution points
- Reputation
- Submission calendar
{
"status": "success",
"message": "retrieved",
"totalSolved": 100,
"totalQuestions": 2000,
"easySolved": 40,
"totalEasy": 500,
"mediumSolved": 40,
"totalMedium": 1000,
"hardSolved": 20,
"totalHard": 500,
"acceptanceRate": 65.5,
"ranking": 100000,
"contributionPoints": 50,
"reputation": 100,
"submissionCalendar": { "timestamp": "count" }
}GET /{username}/contests
Retrieves the user's contest history and rankings.
username(path): LeetCode username
Returns:
- Contest participation statistics
- Global ranking
- Contest history with details for each contest
{
"status": "success",
"message": "retrieved",
"attendedContestsCount": 10,
"rating": 1500,
"globalRanking": 5000,
"totalParticipants": 100000,
"topPercentage": 5.0,
"badge": {
"name": "Guardian"
},
"contestHistory": [
{
"attended": true,
"rating": 1500,
"ranking": 1000,
"trendDirection": "UP",
"problemsSolved": 3,
"totalProblems": 4,
"finishTimeInSeconds": 3600,
"contest": {
"title": "Weekly Contest 123",
"startTime": 1615694400
}
}
]
}GET /{username}/profile
Retrieves detailed profile information for a user. All fields are now rendered in the dashboard profile card.
username(path): LeetCode username
Returns:
- Personal profile information (avatar, real name, country, company, school, skills, about me, star rating)
- Social media links (GitHub, Twitter, LinkedIn)
- Contributions (points, question count, testcase count)
- Badges, upcoming badges, active badge
- Submission stats and calendar
- Recent submissions
{
"status": "success",
"message": "retrieved",
"username": "example_user",
"githubUrl": "https://github.com/example",
"twitterUrl": "https://twitter.com/example",
"linkedinUrl": "https://linkedin.com/in/example",
"contributions": {
"points": 100,
"questionCount": 5,
"testcaseCount": 10
},
"profile": {
"realName": "Example User",
"userAvatar": "https://assets.leetcode.com/avatar.jpg",
"birthday": "2000-01-01",
"ranking": 10000,
"reputation": 100,
"websites": ["https://example.com"],
"countryName": "United States",
"company": "Example Corp",
"school": "Example University",
"skillTags": ["Python", "Algorithms"],
"aboutMe": "LeetCode enthusiast",
"starRating": 4.5
},
"badges": [],
"upcomingBadges": [],
"activeBadge": {},
"submitStats": {},
"submissionCalendar": { "timestamp": "count" },
"recentSubmissions": []
}GET /{username}/heatmap
Retrieves normalized daily contribution data and summary metadata for building a heatmap UI.
username(path): LeetCode username
Returns:
- Daily contribution entries including zero-count days in the returned range
- Current streak and longest streak
- Per-year totals for quick aggregation
- Max daily submissions for color scaling
{
"status": "success",
"message": "retrieved",
"username": "example_user",
"startDate": "2024-01-01",
"endDate": "2024-12-31",
"firstActiveDate": "2024-01-03",
"lastActiveDate": "2024-12-29",
"totalSubmissions": 320,
"activeDays": 120,
"currentStreak": 5,
"longestStreak": 19,
"maxDailySubmissions": 12,
"dailyContributions": [
{
"date": "2024-01-01",
"timestamp": 1704067200,
"count": 0,
"level": 0
},
{
"date": "2024-01-02",
"timestamp": 1704153600,
"count": 3,
"level": 1
}
],
"yearlyContributions": [
{
"year": 2024,
"totalSubmissions": 320,
"activeDays": 120
}
]
}GET /{username}/badges
Retrieves badges earned by the user.
username(path): LeetCode username
Returns:
- List of earned badges
- Upcoming badges
- Current active badge
{
"status": "success",
"message": "retrieved",
"badges": [
{
"id": "1",
"displayName": "Problem Solver",
"icon": "badge-icon-url",
"creationDate": 1609459200
}
],
"upcomingBadges": [
{
"name": "Fast Coder",
"icon": "upcoming-badge-icon-url"
}
],
"activeBadge": {
"id": "1",
"displayName": "Problem Solver",
"icon": "badge-icon-url",
"creationDate": 1609459200
}
}Detailed API documentation is available when the server is running by visiting:
GET /docs
This provides an interactive documentation page with detailed information about all endpoints, parameters, and example responses.
The API returns appropriate HTTP status codes:
200 OK: Request successful404 Not Found: User not found429 Too Many Requests: Rate limit exceeded500 Internal Server Error: Server-side error
Error responses follow this format:
{
"status": "error",
"message": "error description"
}import requests
username = "leetcoder"
response = requests.get(f"https://leetcode-stats.tashif.codes/{username}")
data = response.json()
print(f"{username} has solved {data['totalSolved']} problems!")fetch(`https://leetcode-stats.tashif.codes/${username}`)
.then((response) => response.json())
.then((data) => console.log(data));-
Clone the repository
git clone https://github.com/tashifkhan/LeetCode-Stats-API.git cd LeetCode-Stats-API -
Install dependencies (managed with uv)
uv sync
-
Start the server
uv run uvicorn app:app --reload
The API will be available at http://localhost:58352 (or pass --port to
choose another). Interactive Swagger docs are at /docs, the custom dashboard at /.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Full API documentation is available at / endpoints when the server is running.
MIT License. See LICENSE for more information.