Internet Speed Test using Python

Hello there,

Running a speed test can be very useful to verify the current state of an internet connection. In this blog article, we will learn how to Test Internet Speed. We will see the implementation in Python.

Check out the Repository for Ultimate Resource in python. Drop a star if you find it useful! Got anything to add? Open a PR on the same!

Let’s get started.

What will be covered in this Blog

Speedtest Introduction:

The internet connections in our homes and offices can differ by internet service providers (ISPs), allowable traffic limit, and most importantly speed. So what do you usually do when you want to test the speed of our connection? You google it, right? How about testing the internet speed using Python from your machine!

Speedtest CLI library provides Command-line interface for testing internet bandwidth using speedtest.net

If you wish to know more about it, you can refer to Speedtest Documentation. Use this link to navigate to the documentation.

Now that you are aware of Speedtest basics, we can move forward to the coding section. Let’s get started!

Time to Code!

You can find all the code in my GitHub Repository. Drop a star if you find it useful.

In order to access the Python library, you need to install it into your Python environment, use the following command to install Speedtest

Now, let’s import the package into our Python script.

Let’s create an instance of Speedtest and call it st

Let’s move forward and check for download speed. We will make use of download method to fetch the speed and store it in d_st

Similarly, to check for the upload speed, we will make use of upload method to fetch the speed and store it in u_st

Once done, let’s display the download and upload speed.

Let’s have a look at the output:

It will look something like this. Here’s the download and upload speed in bits.

BONUS:

Let’s check for ping. We can do so by making use of the following command.

Let’s fetch the ping and store it in ping, we will make use of results.ping for the same.

Let’s display the ping using print.

This is how you can test your Internet speed. That’s it!

Simple, isn’t it? Hope this tutorial has helped. You can play around with the Speedtest library and even explore more features. You can even make use of Python GUI using Tkinter.

You can find all the code in my GitHub Repository. Drop a star if you find it useful.

Thank you for reading, I would love to connect with you at Twitter | LinkedIn.

Do share your valuable suggestions, I appreciate your honest feedback!

You should definitely check out my other Blogs:

Resources:

See you in my next Blog article, Take care

A Software Developer and a YouTuber who likes to write Technical Blogs and contribute to Open Source.