Speed Tester Using Python
Alvison Hunter - Sr Web Developer at Udemy
Tech Lead & Mentor @ CodeCrafters Labs | Empowering Developers Through JavaScript, Python & Emerging Tech | React & Vue Advocate
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/
COLORAMA?|?https://pypi.org/project/colorama/
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:
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!
领英推荐
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:
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:
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?
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:
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!
Front-End Developer / Cybersecurity Analyst
3 年That's awesome. Thank you for sharing
Software Engineer @ 3S Silicon Tech., Inc | MEng, C# / WPF / Python
3 年Outstanding Alvison Hunter ????