In this tutorial, we will be building a python program to test internet speed including the upload and download speeds. To do this we will first need to install speedtest-cli.
To install speedtest-cli run the command below.
pip install speedtest-cli
Now create a file called speed-test.py and import the module as shown in the code below.
import speedtest as speed
Now we need to get closest servers to now run the speed test as shown below.
test = speed.Speedtest()
server = test.get_servers()
test.get_closest_servers()
Test the download speed.
downloadSpeed = test.download()
downloadSpeed = downloadSpeed / 1000000
print("Download speed : ",downloadSpeed,"Mbps")
Test the upload speed.
uploadSpeed = test.upload()
uploadSpeed = uploadSpeed / 1000000
print("Upload speed : ", uploadSpeed,"Mbps")
Test the ping .
ping = test.results.ping
print("Ping : ",ping ,"ms")
Now open your application and run the command python3 speed-test.py and here is are our speedtest results.
Download speed : 2.890524744263825 Mbps
Upload speed : 10.49906510506087 Mbps
Ping : 8.198 ms
Pingback: How To Build a Simple Interest Calculator Using Python - bytexplain