Test Internet Speed using Python

Prerequisites: Python Programming Language

Python is a high-level widely used general-purpose language. Python can be used for many tasks such as web development, machine learning, Gui applications. It can also be used for testing Internet speed. Python provides various libraries for doing the same. One such library is speedtest-cli. This library is a command-line interface for testing internet bandwidth using speedtest.net

Installation

This module does not come built-in with Python. To install it type the below command in the terminal.

pip install speedtest-cli

After installing the above package one can check if the package is installed correctly or not by doing the version check. The version of the package can be checked using the following command

speedtest-cli --version

Checking seedtest-cli version



Speedtest-cli Package

Speedtest-cli is a module that is used in the command-line interface for testing internet bandwidth using speedtest.net. To get the speed in the megabits type the below command in the terminal.

speedtest-cli

Speedtest-cli

The above command gives the speed test result is in Megabits. To get the result in Bytes we can use the following command.

speedtest-cli --bytes

speedtest-cli-bytes

The pictorial version of your speed test result can also be retrieved using this module. To do the same type the below command in the terminal.

speedtest-cli --share

pictoral version of internet speed

It returns a link on which we can visit on our browser and see the graphical representation of various kinds of our internet speed.

pictoral version of internet speed



To print a simpler version of the speed test result containing only Ping, Download & Upload results instead of detailed output.

speedtest-cli --simple

simple result of internet speed

Using Python script to check the internet speed

filter_none

edit
close

play_arrow

link
brightness_4
code

# Python program to test
# internet speed
  
import speedtest  
  
  
st = speedtest.Speedtest()
  
option = int(input('''What speed do you want to test:  
  
1) Download Speed  
  
2) Upload Speed  
  
3) Ping 
  
Your Choice: '''))
  
  
if option == 1:  
  
    print(st.download())  
  
elif option == 2
  
    print(st.upload())  
  
elif option == 3:  
  
    servernames =[]  
  
    st.get_servers(servernames)  
  
    print(st.results.ping)  
  
else:
  
    print("Please enter the correct choice !"

chevron_right


Output:

output
output

To get the list of all the available options, type the below command in the terminal.

  • speedtest-cli -h

    speedtest-cli --h

  • speedtest-cli --help

    speedtest-cli --help




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

1


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.