Search code examples
sortinggithub-api

Sort github API list repos by created_at date


I am using the github developer API link to list all the repositories with given search term and I want to sort it by created_at date in descending order. How can I do that?


Solution

  • I found the solution myself: Listing repos with given search term (eg. oauth):

    response = https://api.github.com/search/repositories?q=oauth&order=desc
    

    Now sort it as

    # Sort based on created_at date 
    data = sorted(response.json()['items'], key=lambda x: x['created_at'], reverse = True)
    

    Thanks to similar post