Speed Tester Using Python

Speed Tester Using Python

Let's build an Internet Performance and Network Speed Tester

As internet users, we usually rely on fast.com and speedtest.net for most of our internet performance and network speed tests. Although this is not bad in terms of utilities, it would be great if we could integrate these tools in our own applications to run all these tests inside the core of our project, without the need of going back and forth in between our app and these tools, wouldn't be great if we could do so??

Well, we certainly can and we will focus on speedtest.net to give you guys an example on how to proceed with this in this article, are you ready to start this journey, buddy?

Requirements:

We will need three modules, or packages, or libraries or whatever you want to call it in order for us to run this project. We can install them using pip or downloading the files. Most of these packages have their own descriptive section in the the Python Package Index(PyPI) repository.? Let's add a summary of some of these:

SPEEDTEST?|?https://pypi.org/project/speedtest/

  • Description | Speed test module for Python
  • Version | speedtest==0.0.1
  • Command | pip install speedtest
  • Requires | Python >=3.7

COLORAMA?|?https://pypi.org/project/colorama/

  • Description | Cross-platform colored terminal text.
  • Version | colorama==0.4.4
  • PIP Command | pip install colorama
  • Requires | Python >=2.7, !=3.0.*,

TQDM?|?https://pypi.org/project/tqdm/

  • Description | Fast, Extensible Progress Meter
  • Version | tqdm==4.62.3
  • PIP Command | pip install speedtest
  • Requires | Python !=3.0.*, !=3.1.* to !=3.3.*, >=2.7

Now that we have all these modules installed, let's create a speed_test_pjt.py file and start our first lines of code by adding the necessary imports in this file as follows:

No alt text provided for this image

Next, we need to initialize our colorama module, passing the autoreset parameter as True, that way, the console colors will automatically reset to default after the last colorama command has been invoked. I am pretty sure you will love this amazing package, buddy!

No alt text provided for this image

Once we have added this, we proceed to create an instance of the Speed Test class using the SpeedTest() function, get the most optimal server available for our test using get_best_server() in our instance, calling the download() and upload() functions to get downloading and uploading speed information, and save all this data in a dictionary called res_dict that will contain all the returning results of these functions.?

We will use tqdm() method of our installed progress bar to display in the screen a fake progress of the speed test events so that way something is being shown in the screen while these events are taking place. Let's see the code below, young coders:

No alt text provided for this image

Next, let's retrieve the information from res_dict and assign to variables with a specific format. This will come handy is terms of displaying more readable data:

No alt text provided for this image

Last but not least, let's give that nice looking table effect to our results combining the power of colorama, along with some lines, used as dividers, to make it look smooth, shall we?

No alt text provided for this image

Ready, tigers!! We can now say that our code has been completed: Congrats! You guys did a great job!

Final Code for this Project in my Gist Profile:

No alt text provided for this image

Thanks for reading this article, I hope you enjoyed it as much as I did writing it. Until next time, dear readers!

?? Enjoyed the article? Your support inspires more content!

?? Share your thoughts in the comments.

?? Found it helpful? Pass it on!

Jose B.

Front-End Developer / Cybersecurity Analyst

3 年

That's awesome. Thank you for sharing

Carlos Jarquin

Software Engineer @ 3S Silicon Tech., Inc | MEng, C# / WPF / Python

3 年

Outstanding Alvison Hunter ????

要查看或添加评论,请登录

社区洞察

其他会员也浏览了