In this post, you will learn how to check internet speed using python with step by step example.
INTERNET SPEED TESTER
- Python provides various ways to display the internet speed.
- Here python provides a module like ‘speedtest-cli’ which is used to get the speed of internet
REQUIRED MODULE
- speedtest-cli
Important Class
- Speedtest
- It is a built-in class which is used to show the speed of network connection using its instance methods.
Important Methods
- Download()
- It is a built-in instance method of speedtest class
- It is used to display the downloading speed of current network connection in bits per second
- It does not take any arguments
- Return type : float
- Upload()
- It is a built-in instance method of speedtest class
- It is used to display the uploading speed of current network connection in bits per second
- It does not take any arguments
- Return type : float
I. INTERNET SPEED TESTER USING PYTHON
(NetSpeed.py)
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 mega bits per second
upload=sp.upload()/1048576
# format download speed to float 2 decimal places and retruns 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”)
2. INSTALLING THE MODULE “speedtest-cli”
3. OUTPUT
More Tutorials