- In this tutorial, you will learn how to display your internet speed through python code with step by step example.
Internet Speed Test in Python
- It is possible to display the internet speed through python code.
- This is done by using the special module named speedtest which provides both download speed and upload speed
Download Speed
- It refers to how your internet connection will download the data from the internet.
Upload Speed
- It refers to how your internet connection will upload the data to the internet.
Required Module
- In order to test the internet via python code, the library named speedtest needs to be installed on your machine.
- Open the CMD or VSC editor and then type the command below
- pip install speedtest-cli
Steps for Installing SpeedTest Library in Visual Studio Code (VSC) Editor in Windows
EXAMPLE CODE TO DISPLAY THE INTERNET SPEED
1. SOURCE CODE
from speedtest import *
# create an object for Speedtest class
sp=Speedtest()
print(“—————————————“)
print(“\tInternet Speed Tester”)
print(“—————————————“)
# find download speed by calling download() method which returns speed in bits / per second and convert it to megabits per second
down=sp.download()/1048576
# find upload speed by calling upload() method which returns speed in bits / per second and convert it to megabits per second
upload=sp.upload()/1048576
# format download speed to float 2 decimal places and returns the result in string
ds=”{:.2f}”.format(down)
# format upload speed to float 2 decimal places and returns the result in string
us=”{:.2f}”.format(upload)
print(“Download Speed\t:”,ds,” MBPS”)
print(“Upload Speed\t:”,us,” MBPS”)
NOTE
- Once run your code then wait few minutes for the result
2. OUTPUT