How to Check the Internet Speed using Python

Hello guys welcome back to our another article. In this article we are going to learn how can we check the internet speed using Python.

It means that we will be making a Python file by which we can know the Internet speed. So whenever we have to check our internet speed, we just have to run our file and it will tell us our internet speed.

First let’s see how our scripts will look when it is executed.

how can we check the internet speed using Pyton
Easiest way to check the internet speed using Python

Let’s Check Internet Speed using Python

So without wasting our time, let’s get started and make our file. So to start making our file we need the latest version of the Python installed on your device.

If you want to download Python, you can download from its official website, python.org, according to the operating system you are using. Here I am using Windows. So I have installed the Python for windows.

You will also need a good Text editor also known as IDE. So if you want to know that which is the best text editor for Python, we have already published an article on this topic.

Which is the Best Text Editor for Python

Check Internet Speed using Python

So after meeting all the requirement, lets come to our text editor and and start making our file.

So here I have created a Python file named speed.py. You can choose any name of your choice.

So will will be using here two famous modules of Python. They are speedtest and time module. The time module is optional module. You can install these modules by simply typing pip install and the module name in your terminal.

The speedtest module helps to check the internet speed. Whereas the time module is used to pause the interpretation for few seconds to make our scripts for dynamic.

So now I am giving the source code to check the internet speed using Python. Then we will understand it that how it is working.

import speedtest
import time
internet = speedtest.Speedtest()

def download():
      print("\nPlz wait we are checking your Download Speed\n")
      down = internet.download()
      down_speed = round(down / (10**6), 2)
      print(" Your downoad speed is : ", down_speed, " Mbps")

      return("")

def upload():
      print("\nPlz wait we are checking your Upload Speed\n")
      uploads = internet.upload()
      upload_speed = round(uploads / (10**6), 2)
      print("Your Upload speed is : ", upload_speed, " Mbps")

      return("")

def both():
      print("\nPlz wait we are checking your Download and Upload Speed\n")
      both_down = internet.download()
      both_upload = internet.upload()
      down_1 = round(both_down / (10**6), 2)
      upload_1 = round(both_upload / (10**6), 2)
      print("Your Download speed is : ", down_1, " Mbps")
      print("Your Upload Speed is : ", upload_1, " Mbps")
      return("")
      

print("\n\nPlease enter what you want to know. \n\n (1) Download Speed \n (2) Upload Speed \n (3) Both Downlad and Upload ")


options = int(input("\nEnter your choice\n\n"))

if options == 1 :
      print(download())


elif options == 2 :
      print(upload())

elif options == 3 :
      print(both())

else :
      print("Plz enter a correct option")






time.sleep(1)
print("\nThanks for using this script\n\n\n ")
time.sleep(2)

So here we have imported the both modules.

After that we have made stored the Speedtest function in a variable called internet.

After that we have made two function to know download and upload speed. The download function is to check the download speed whereas the upload function is used to check the upload speed.

We have also made a both function to check the both download and upload speed.

After that we have made a if else conditions to know that what the user want to check. At last we have used time module to pause our interpretation for 2 before exiting the script.

So I hope that you understood this script. If you have any doubt or you have not understood this script, don’t hesitate to ask it in our forum.

Also read these interesting articles:

How to clear the Terminal in Python

How to make Scripts for browsers using Python

How to make a calculator using Python

How to make rock paper scissors game using Python

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *