Maintenance

Site is under maintenance — quizzes are still available.

Go to quizzes
Sponsored Reserved space — layout preview until AdSense is connected

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.

Medium Python 3.9+ Jun 28, 2026 AI & LLM integration patterns 3 views 0 copies

Requires third-party packages — install first
pip install requests

Python code

44 lines
Python 3.9+
import 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

stdout
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

  1. Use plotly or matplotlib to visualize star growth over time
  2. 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

Sponsored Reserved space — layout preview until AdSense is connected

Run locally

This sample needs third-party packages, so it cannot run in the browser IDE. Copy the code above, install the packages shown at the top, then run it in your own Python environment.

Related tutorials and quizzes for this topic.