overview
FastAPI service that turns a public GitHub username into stats, language splits, contribution history, repos, PRs, and embeddable cards. Live at github-stats.tashif.codes. Source is tashifkhan/GitHub-Stats-API.
Callers do not send a GitHub token. The server uses GITHUB_TOKEN and talks to GitHub’s REST and GraphQL APIs. Redis, either REDIS_URL or Upstash REST, caches successful GETs and stores own-commit attribution so later requests do not start from zero.
CodeTrace consumes the canonical card routes. Sibling APIs for the other platforms: LeetCode, Codeforces, GFG, CodeChef, HackerRank, TUF, GitHost. Dashboard: CodeTrace.
Docs map#
- Overview
- Interactive dashboard
- API endpoints, general
- Envelope and schemas
- User analytics
- Pull requests and organizations
- Dashboard details
- Error handling
- Architecture
- Own-commit attribution
- Cache and limiter
- Canonical vs extras
- HTML scrapes
What it returns#
Type a username and the service pulls several GitHub surfaces into JSON, plus one SVG card.
- Canonical card. Shared envelope used by CodeTrace: summary, profile, stats, heatmap, badges.
- Language mix. Own-commit attribution by default, so forks count the patches the user wrote, not the upstream tree.
- Contribution history. Calendar, streaks, and a per-repo breakdown of additions and deletions.
- Repository metadata. README, topics, optional releases, stars, pins, starred lists, commits.
- PRs. Owned-repo pulls, external pulls, and orgs where a merged PR landed.
Request flow#
The HTML docs and playground are FastAPI routes on the same app. JSON routes go through cache and rate-limit middleware, then services, then GitHub.
flowchart LR Browser["Browser"] Docs["GET / and /playground"] API["FastAPI routes"] MW["Cache and rate-limit middleware"] Redis["Redis or Upstash"] Services["Analytics, PR, attribution"] GitHub["GitHub REST and GraphQL"] Browser --> Docs Browser --> API Docs --> API API --> MW MW -->|"cache hit"| Browser MW -->|"cache miss"| Services MW --> Redis Services --> GitHub Services --> Redis Services --> Browser
/ and /docs skip the Redis cache. Username GETs hash method, path, and query into cache:github:.... A 404 for a missing user is stored separately as invalid:github:{handle} so the app does not keep asking GitHub for ghosts.
Live access#
- Site: github-stats.tashif.codes
- Playground: playground
- OpenAPI: docs
- ReDoc: redoc
- Sample JSON: tashifkhan/profile
- Repo: tashifkhan/GitHub-Stats-API
Run it locally#
Needs Python, a GitHub token, and preferably Redis if you care about attribution.
- Clone tashifkhan/GitHub-Stats-API.
- Install from
requirements.txt. - Set
GITHUB_TOKENin.env. - Optionally set
REDIS_URL, orUPSTASH_REDIS_REST_URLplusUPSTASH_REDIS_REST_TOKEN. python main.pyserveshttp://localhost:8989. Override withHOSTandPORT.
Vercel maps every path to main.py.