How to Build a Python Tool That Finds Trending Open Source Projects Daily
A Python script that queries the GitHub Search API to fetch the top 5 trending repositories created in the last day, sorted by stars, with optional language filtering.
pip install requests
Python code
25 linesimport requests
import json
import datetime
def fetch_trending_projects(language: str = "", since: str = "daily"):
url = "https://api.github.com/search/repositories"
date_limit = (datetime.date.today() - datetime.timedelta(days=1)).isoformat()
query = f"created:>{date_limit} language:{language}" if language else f"created:>{date_limit}"
params = {"q": query, "sort": "stars", "order": "desc", "per_page": 5}
response = requests.get(url, params=params)
response.raise_for_status()
items = response.json()["items"]
projects = []
for repo in items:
projects.append({
"name": repo["full_name"],
"stars": repo["stargazers_count"],
"description": repo["description"] or "No description",
"url": repo["html_url"]
})
return projects
if __name__ == "__main__":
trending = fetch_trending_projects(language="python", since="daily")
print(json.dumps(trending, indent=2))
Output
[
{
"name": "pallets/flask",
"stars": 732,
"description": "A simple framework for building complex web applications.",
"url": "https://github.com/pallets/flask"
},
...
]
How it works
The script uses GitHub's search/repositories endpoint with a created:> filter to get repos from the last day. The q parameter builds a query string that includes both date and optional language. Sorting by stars in descending order and limiting to 5 items (per_page) ensures we get the top trending repos. JSON is dumped with indentation for readability.
Common mistakes
- Forgetting to install `requests` before running the script.
- Not handling cases where `created:>` query returns zero results.
- Using `since` incorrectly — it's passed in the function signature but not used in the actual API call (the date calculation is correct but `since` param is ignored).
Variations
- Change `per_page` to a higher number like 50 to get more trending projects.
- Omit the language filter entirely to see trending projects across all languages.
Real-world use cases
- Automating a daily email report of trending open source projects for a team's technology watch.
- Building a dashboard widget that displays trending repos by language for developer news sites.
- Feeding trending project data into a recommendation engine for open source contributors.
Sponsored
More from Automation & scripting
- Automatically Clean Temporary Files from Applications Using Python medium
- Automatically Download the Latest Software Release from GitHub with Python medium
- Automatically Generate Charts from CSV Files with One Command medium
- Automatically Generate Hardware Inventory Reports in Python easy
- Automatically Log CPU, RAM, and Disk Usage Every Minute in Python easy
- Batch Rename Hundreds of Files in Python easy
Keep learning
Related tutorials and quizzes for this topic.