Check Your Internet Speed Using Python

Do you know you can check your internet speed with few lines of python code? In this article, you will learn how to perform an internet speed test using Python.

Photo by Marc-Olivier Jodoin on Unsplash

The internet connection can differ by internet service providers (ISPs), allowable traffic limit, and most importantly speed. You can easily test the speed of your internet connection using python from your own machine!

Required Installation

To calculate the speed of your internet connection first you have to install a Python library known as speedtest. Just write the below command & press enter to install it.

Speedtest-cli library provides command line interface for testing internet bandwidth using speedtest.net

Code

import speedtest
speed = speedtest.Speedtest()

print(f"Download speed of my Internet Connection is :{'{:.2f}'.format(speed.download()/1024/1024)} Mb/s")
print(f"Upload speed of my Internet Connection is : {'{:.2f}'.format(speed.upload()/1024/1024)} Mb/s")

First import the speedtest package. Then create an instance of speedtest and call it speed. Now check the download speed by using download() method to fetch the speed. Similarly to check the upload speed we will use upload() method. To get the speed in Mbps we divide the speed two times by 1024.

This is how you can check your Internet speed using python. I hope you find this article useful. If you have any question feel free to ask in the comment section below.