Counts the total number of commits made by a GitHub user in a specified year using the GitHub GraphQL API.
- Asks for a GitHub username, a year, and a personal access token
- Uses GitHub's GraphQL API for fast and reliable data retrieval
- Displays the total number of commits for the specified year
git clone https://github.com/FelineFantasy/GitHub-Commit-Counter
cd GitHub-Commit-Counter
pip install -r requirements.txt
python main.py- Python 3.6+
requestslibrary- GitHub Personal Access Token (see setup below)
Run the script without arguments to answer the prompts:
python main.pyPass the username and year to skip them:
python main.py FelineFantasy 2026Add --json to get machine-readable output for scripts:
python main.py FelineFantasy 2026 --json
# {"username": "FelineFantasy", "year": 2026, "commits": 161}The script exits with status 0 on success and 1 when the arguments are invalid or the data cannot be fetched.
- Go to GitHub Settings → Developer settings → Personal access tokens → Tokens (classic)
- Click "Generate new token (classic)"
- Give it a name and select the
reposcope (orpublic_repofor public repositories only) - Generate and copy your token
If you leave out the username or the year, the script will prompt you for the missing value:
- GitHub username - The user whose commits you want to count
- Year - The year to check (e.g., 2026)
- GitHub token - Your personal access token (input will be hidden for security)
Введите GitHub username: FelineFantasy
Введите год (например, 2026): 2026
Введите GitHub токен: ghp_xxxxxxxxxxxxxxxxxxxx
Всего коммитов за 2026: 161
- A GitHub token is required to use the GitHub GraphQL API
- Rate limits apply based on your token type:
- Unauthenticated: 60 requests/hour (not used in this script)
- Authenticated: 5,000 requests/hour
- The token does not need to be stored in the code; it's entered at runtime
- Uses GitHub's official GraphQL API endpoint
- Queries
contributionsCollectionfor accurate commit counting - Handles date ranges automatically for the full year
- Invalid token: Ensure your token has the correct permissions
- Rate limiting: If you hit the limit, wait an hour and try again
- User not found: Verify the username is spelled correctly
The test suite uses only the standard library's unittest:
python -m unittest discover -s tests -t . -vIf you enjoy GitHub-Commit-Counter and want to help keep the project alive, you can support me here:
Your support helps me:
- 🐱 Keep developing new tools
- 🛠️ Fix bugs and improve accuracy
- ☕ Stay awake while coding at 4 AM
Every little bit is appreciated! ❤️
- FelineFantasy
- License: MIT