Coding: GitHub Public API Application using Python (Part-3)

Welcome back! In this part, we are going to code the application using Python. If you have not read the other two parts, I would highly recommend you to go through both of them as they are prerequisite to this part.
Part-1 laid the foundation of application, and in Part-2, I have described the structure and fields of GitHub API.

Tools to need

I am going to use only one tool in this article, which is: “Python 3.6 IDLE.” If you do not know anything about it, and you have not found anywhere in your computer this software, then follow the Part-1. Alright! I would assume that you would have this IDLE in your start panel. The tool will look like this:


Step 1:

Go to the file and choose new file. Save it as“”(as shown below).

Left window is for the outputs, whereas the right window will be used to write the code for GitHub API and logic.

Step 2:

Import the “requests” package, which you have installed in the Part-1. The code line would be:

import requests

Step 3:

Let us take the username/channel name/GitHub page name from the user at run time. The code line would be:

entry = input(“Enter the GitHub Channel name: ”)

Step 4:

As I have explained in the Part-2 that the following GitHub’s API link is used to access the public information of the users:{channel-name}

Now the code line would be:

raw_data = requests.get(“”+entry)

The entry should be the valid channel name. In this part I am not going to do the exception handling.

Now the raw_data holds the whole details of the entry, but I am interested in the JSON of the GitHub Public API of a user.

Step 5:

In order to get the JSON out of the raw data above, you need to write the following line of code:

user_json = raw_data.json()

If you print the user_json, you would get the following result:

Here is the copy of above code:

import requests

entry = input("Enter the GitHub Channel name: ")

raw_data = requests.get(""+entry)

user_json = raw_data.json()


Step 6:

What if you want to know just the bio field of the user? Well, it is really simple. Take the “user_json” and write the following line of code:

bio = user_json[“bio”]

And if you print the code, you would see the following output:

Likewise, if you want to get other fields, we can use the above method to get all the individual data.

The final code and output would look like this:

Final Code:

# Here we are going to write code

import requests
def options():
    option = input()
    if option=="1":
        print("Bio:" + user_json["bio"])
    elif option=="2":
    elif option=="3":
    elif option=="4":
    elif option=="5":
        print("Public Repositories{0}".format(user_json["public_repos"]))
    elif option=="q":
        print("Wrong Option. Enter Again!\n")



    entry = input("Enter the GitHub Channel name: ")

    raw_data = requests.get(""+entry)

    user_json = raw_data.json()

    print("Enter 1 for Bio\nEnter 2 for ID\nEnter 3 for Followers\nEnter 4 for Followings\nEnter 5 for Public Repositories\nEnter q to Quit\n")


In this part, we have used Python to use GitHub API in order to get the public data of any User. We have also learned how to use any API in general using Python. That’s it for this tutorial!

Related article



Boostlog is an online community for developers
who want to share ideas and grow each other.

Delete an article

Deleted articles are gone forever. Are you sure?