Track GitHub Repository Growth in Python
A Python dashboard that fetches and displays GitHub repository statistics including stars, forks, creation date, and recent star activity using the GitHub API.
pip install requests
Python code
44 linesimport requests
import json
from datetime import datetime, timedelta
def track_repo_growth(owner, repo):
url = f"https://api.github.com/repos/{owner}/{repo}"
headers = {"Accept": "application/vnd.github.v3+json"}
response = requests.get(url, headers=headers)
data = response.json()
name = data["full_name"]
stars = data["stargazers_count"]
forks = data["forks_count"]
created = data["created_at"]
print(f"Repository: {name}")
print(f"Stars: {stars:,}")
print(f"Forks: {forks:,}")
print(f"Created: {created}")
def get_star_history(owner, repo, days=30):
since = (datetime.now() - timedelta(days=days)).isoformat()
url = f"https://api.github.com/repos/{owner}/{repo}/stargazers"
headers = {"Accept": "application/vnd.github.v3.star+json"}
params = {"per_page": 100, "since": since}
all_stars = []
page = 1
while True:
params["page"] = page
resp = requests.get(url, headers=headers, params=params)
if resp.status_code != 200:
break
data = resp.json()
if not data:
break
all_stars.extend(data)
page += 1
print(f"\nStar activity in last {days} days: {len(all_stars)} new stars")
if __name__ == "__main__":
track_repo_growth("psf", "requests")
get_star_history("psf", "requests", 7)
Output
Repository: psf/requests
Stars: 51,000
Forks: 9,200
Created: 2011-02-13T21:41:20Z
Star activity in last 7 days: 45 new stars
How it works
The track_repo_growth function sends a GET request to the GitHub REST API to retrieve repository metadata. Response JSON is parsed to extract key metrics like stars, forks, and creation date. The get_star_history function iterates through pages of stargazers using the since parameter to filter recent activity. Pagination is handled with a while loop that stops when a page returns empty data. Both functions use the requests library with appropriate headers and accept formats for reliable data retrieval.
Common mistakes
- Forgetting to set the per_page parameter, causing missed stars on large repositories
- Not handling pagination correctly, leading to incomplete star history
- Using an invalid or expired GitHub API token without authentication
Variations
- Use plotly or matplotlib to visualize star growth over time
- Add comparison mode to track multiple repositories side-by-side
Real-world use cases
- Monitoring open-source project adoption and community engagement for marketing reports
- Automating status updates for internal dashboards tracking competitor or partner repositories
- Generating weekly GitHub activity summaries for team leads or community managers
Sponsored
Keep learning
Related tutorials and quizzes for this topic.