Internet Speed Test with Python

NeuralNine · Beginner ·💻 AI-Assisted Coding ·5y ago

Key Takeaways

The video demonstrates how to create a simple internet speed test using Python with the speedtest-cli library, allowing users to measure their download and upload speeds as well as ping times.

Full Transcript

[Music] what is going on guys welcome back in today's video we're going to do a simple internet speed test in python so let us get right into it all right so this is going to be quite simple it's not going to be a complicated project but we're going to need a library for this so we're going to open up cmd and we're going to do pip install speed test cli which is for command line which stands for command line uh now we're going to use this library because we need a speed test provider we're not just going to do some random stuff and download something we're going to use a professional speed test provider but we're going to access this provider using this library via python so we're going to install that in my case i already have that installed um this is what we're going to need however when we import it in python we're not going to import speedtest.cli or cli we're going to say import speed test by the way let me just scale up the font size because for the video you always want a larger font size there you go from 22 to 28 they go and let me also reposition my camera will real quick here there you go all right so we're going to use the speed test module and in order to perform a speed test we don't need to do a lot we just need to um create a speed test object so we're going to call this test equals speed test dot speed test like that and now we have this speed test object and we can do a download test we can do an upload test we can do uh we can evaluate the ping and so on uh but first of all we want to find some servers and want to find the best server so what we're going to do first we're going to say test dot get servers get underscore service this is going to get a list of servers so let me write that as a comment here get list of servers that are available for speed tests so once we have that we're going to choose the best server there is so we're going to say best equals test dot get best server there you go and we can also let me just add a comment here as well uh or choose best server by the way we're also going to print some messages here so we're going to say print uh loading server list for example and then print choosing best server and once we have found the server we're going to say print and we're going to use an string found and here now we can also include information about the server so before we write that string let's just go ahead and print best so you're going to see what we get as a result here i'm going to run this and you're going to see that this is a an object it has a lot of information inside of it uh first of all we have a problem doesn't have speed test oh yeah t here is lowercase come on lowercase t loading server list choosing best server and once it's done we're going to get i think it's a dictionary or adjacent object whatever it is which is actually the same thing uh but we can then access the individual fields so in this case it found the best server it has a url which is this one then it has coordinates and it has a location name vienna in this case country austria since i'm located in austria and a bunch of different other uh parameters so what we can do is we can go ahead and say okay once we found the best server we're going to print f string found and then we're going to say best and what we want to put in here is the host so the host is this one here in this case it's going to change every time we run the script probably so found host located in and then we can say oh it's not a string located in and now we can go and say best country there you go so this is just a setup now we can go to the actual speed test now in order to do a speed test we just need to run two commands uh the first one is going to be download and the second one is going to be upload so we're going to say okay print performing download test and then we're going to just say download result equals test dot download there you go now we can copy that and we can change downloads to upload so we have performing upload test upload result test upload and once we have that we can also get the ping result so we can say ping result equals test dot results dot ping so that's actually i think all we need to do now i'm going to print that and you're going to see why we have to format it a little bit more so i'm going to just print the download result i'm going to print the upload result upload result and the ping results there you go so if i run this now you can see again it's choosing the best server then we're going to see okay chose that host in that country uh and then we're going to do the test and then you're going to see the download speed and the upload speed speed but the problem is and i can tell you that right away we're going to get bits per second so bit per second is a very large number because usually you measure uh the download speed and the upload speed uh speed in m bit per second not in bit per second so now it's performing the tests and we should be done any second and then we should get the results take some time there you go so this is the bit per second this is also bit per second upload speed and this is the ping now this is in milliseconds so what we need to do now is we need to do some um some formatting and we can do that by just using an f string here and we can say okay download speed and then in those curly brackets we can say download result and now in order to get m bit from bit we need to divide by 1024 two times so uh what we need to do is we need to say divided by 1024 now if you want to have kilo bits um so k bit then this is enough and if you want to have um if you want to have mbit you just do it one more time like that and what's also important is that we format the floating point precision so we can just say uh colon.2f to just focus on two decimal places uh and that should actually be it all right so we can copy that uh we don't need that for the ping result though let's let's just see i'm going to replace download by upload upload result there you go and here we're just going to say ping and we're going to remove all of this here and we're going to add ms in the end and here we're going to add m bits per second m bit per second there you go so that should be it let's run this and then we should be done so again we're choosing the server list now while this is loading let's again talk about what we did we got all the servers we got the best server we chose it we printed the host we printed the country this is of course all optional you don't need to do it and once we had that we just called the download function the upload function we saved the results the ping is also saved in the results and then we just format it in a way that we get the m bits per second because usually this this thing here is just bits per second and you you're not really interested in those uh large numbers formatted as bits as you can see here download speed speed is 66.98 ambit per second upload speed 15.05 and the ping is the download result okay i'm not going to run this again but here we would have to say ping result obviously then we would get the ping off around 20 milliseconds so that's it for today's video hope you enjoyed it hope you'll learn something if so let me know by hitting the like button leaving a comment in the comment section down below and of course don't forget to subscribe to this channel and hit the notification bell to not miss a single future video for free other than that thank you very much for watching see you next video and bye [Music] you

Original Description

Today we learn how to make a simple Internet speed test in Python. ◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾ 📚 Programming Books & Merch 📚 💻 The Algorithm Bible Book: https://www.neuralnine.com/books/ 🐍 The Python Bible Book: https://www.neuralnine.com/books/ 👕 Programming Merch: https://www.neuralnine.com/shop 🌐 Social Media & Contact 🌐 📱 Website: https://www.neuralnine.com/ 📷 Instagram: https://www.instagram.com/neuralnine 🐦 Twitter: https://twitter.com/neuralnine 🤵 LinkedIn: https://www.linkedin.com/company/neuralnine/ 📁 GitHub: https://github.com/NeuralNine 🎙 Discord: https://discord.gg/JU4xr8U3dm 🎵 Outro Music From: https://www.bensound.com/
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from NeuralNine · NeuralNine · 0 of 60

← Previous Next →
1 Visualizing Stock Data With Candlestick Charts in Python
Visualizing Stock Data With Candlestick Charts in Python
NeuralNine
2 Python Beginner Tutorial #1 - Installation and First Program
Python Beginner Tutorial #1 - Installation and First Program
NeuralNine
3 Python Beginner Tutorial #2 - Variables and Data Types
Python Beginner Tutorial #2 - Variables and Data Types
NeuralNine
4 Python Beginner Tutorial #3 - Operators and User Input
Python Beginner Tutorial #3 - Operators and User Input
NeuralNine
5 Python Beginner Tutorial #4 - If Statements and Conditions
Python Beginner Tutorial #4 - If Statements and Conditions
NeuralNine
6 Python Beginner Tutorial #5 - Loops
Python Beginner Tutorial #5 - Loops
NeuralNine
7 Python Beginner Tutorial #6 - Sequences and Collections
Python Beginner Tutorial #6 - Sequences and Collections
NeuralNine
8 Python Beginner Tutorial #7 - Functions
Python Beginner Tutorial #7 - Functions
NeuralNine
9 Python Beginner Tutorial #8 - Exception Handling
Python Beginner Tutorial #8 - Exception Handling
NeuralNine
10 Python Beginner Tutorial #9 - File Operations
Python Beginner Tutorial #9 - File Operations
NeuralNine
11 Python Beginner Tutorial #10 - String Functions
Python Beginner Tutorial #10 - String Functions
NeuralNine
12 Python Intermediate Tutorial #1 - Classes and Objects
Python Intermediate Tutorial #1 - Classes and Objects
NeuralNine
13 Python Intermediate Tutorial #2 - Inheritance
Python Intermediate Tutorial #2 - Inheritance
NeuralNine
14 Python Intermediate Tutorial #3 - Multithreading
Python Intermediate Tutorial #3 - Multithreading
NeuralNine
15 Python Intermediate Tutorial #4 - Synchronizing Threads
Python Intermediate Tutorial #4 - Synchronizing Threads
NeuralNine
16 Python Intermediate Tutorial #5 - Events and Daemon Threads
Python Intermediate Tutorial #5 - Events and Daemon Threads
NeuralNine
17 Python Intermediate Tutorial #6 - Queues
Python Intermediate Tutorial #6 - Queues
NeuralNine
18 Python Intermediate Tutorial #7 - Sockets and Network Programming
Python Intermediate Tutorial #7 - Sockets and Network Programming
NeuralNine
19 Python Intermediate Tutorial #8 - Database Programming
Python Intermediate Tutorial #8 - Database Programming
NeuralNine
20 Python Intermediate Tutorial #9 - Recursion
Python Intermediate Tutorial #9 - Recursion
NeuralNine
21 Python Intermediate Tutorial #10 - XML Processing
Python Intermediate Tutorial #10 - XML Processing
NeuralNine
22 Python Intermediate Tutorial #11 - Logging
Python Intermediate Tutorial #11 - Logging
NeuralNine
23 Python Data Science Tutorial #1 - Anaconda and PyCharm Setup
Python Data Science Tutorial #1 - Anaconda and PyCharm Setup
NeuralNine
24 Python Data Science Tutorial #2 - NumPy Arrays
Python Data Science Tutorial #2 - NumPy Arrays
NeuralNine
25 Python Data Science Tutorial #3 - Numpy Functions
Python Data Science Tutorial #3 - Numpy Functions
NeuralNine
26 Python Data Science Tutorial #4 - Plotting Functions With Matplotlib
Python Data Science Tutorial #4 - Plotting Functions With Matplotlib
NeuralNine
27 Python Data Science Tutorial #5 - Subplots and Multiple Windows
Python Data Science Tutorial #5 - Subplots and Multiple Windows
NeuralNine
28 Python Data Science Tutorial #6 - Matplotlib Styling
Python Data Science Tutorial #6 - Matplotlib Styling
NeuralNine
29 Python Data Science Tutorial #7 - Bar Charts with Matplotlib
Python Data Science Tutorial #7 - Bar Charts with Matplotlib
NeuralNine
30 Python Data Science Tutorial #8 - Pie Charts with Matplotlib
Python Data Science Tutorial #8 - Pie Charts with Matplotlib
NeuralNine
31 Python Data Science Tutorial #9 - Plotting Histograms with Matplotlib
Python Data Science Tutorial #9 - Plotting Histograms with Matplotlib
NeuralNine
32 Python Data Science Tutorial #10 - Scatter Plots with Matplotlib
Python Data Science Tutorial #10 - Scatter Plots with Matplotlib
NeuralNine
33 Python Data Science Tutorial #11 - 3D Plotting with Matplotlib
Python Data Science Tutorial #11 - 3D Plotting with Matplotlib
NeuralNine
34 Python Data Science Tutorial #12 - Pandas Series
Python Data Science Tutorial #12 - Pandas Series
NeuralNine
35 Python Data Science Tutorial #13 - Pandas Data Frames
Python Data Science Tutorial #13 - Pandas Data Frames
NeuralNine
36 Python Data Science Tutorial #14 - Pandas Statistics
Python Data Science Tutorial #14 - Pandas Statistics
NeuralNine
37 Python Data Science Tutorial #15 - Pandas Sorting and Functions
Python Data Science Tutorial #15 - Pandas Sorting and Functions
NeuralNine
38 Python Data Science Tutorial #16 - Pandas Merging Data Frames
Python Data Science Tutorial #16 - Pandas Merging Data Frames
NeuralNine
39 Python Data Science Tutorial #17 - Pandas Queries
Python Data Science Tutorial #17 - Pandas Queries
NeuralNine
40 Python Machine Learning Tutorial #1 - What is Machine Learning?
Python Machine Learning Tutorial #1 - What is Machine Learning?
NeuralNine
41 Python Machine Learning Tutorial #2 - Linear Regression
Python Machine Learning Tutorial #2 - Linear Regression
NeuralNine
42 Python Machine Learning Tutorial #3 - K-Nearest Neighbors Classification
Python Machine Learning Tutorial #3 - K-Nearest Neighbors Classification
NeuralNine
43 Python Machine Learning #4 - Support Vector Machines
Python Machine Learning #4 - Support Vector Machines
NeuralNine
44 Python Machine Learning Tutorial #5 - Decision Trees and Random Forest Classification
Python Machine Learning Tutorial #5 - Decision Trees and Random Forest Classification
NeuralNine
45 Python Machine Learning Tutorial #6 - K-Means Clustering
Python Machine Learning Tutorial #6 - K-Means Clustering
NeuralNine
46 Python Machine Learning Tutorial #7 - Neural Networks
Python Machine Learning Tutorial #7 - Neural Networks
NeuralNine
47 Python Machine Learning Tutorial #8 - Handwritten Digit Recognition with Tensorflow
Python Machine Learning Tutorial #8 - Handwritten Digit Recognition with Tensorflow
NeuralNine
48 Generating Poetic Texts with Recurrent Neural Networks in Python
Generating Poetic Texts with Recurrent Neural Networks in Python
NeuralNine
49 Stock Portfolio Visualization with Matplotlib in Python
Stock Portfolio Visualization with Matplotlib in Python
NeuralNine
50 Analyzing Coronavirus with Python (COVID-19)
Analyzing Coronavirus with Python (COVID-19)
NeuralNine
51 Making Text Images Readable Again with Python and OpenCV
Making Text Images Readable Again with Python and OpenCV
NeuralNine
52 Neural Networks Simply Explained (Theory)
Neural Networks Simply Explained (Theory)
NeuralNine
53 Motion Filtering with OpenCV in Python
Motion Filtering with OpenCV in Python
NeuralNine
54 Top 5 Programming Languages To Learn in 2020
Top 5 Programming Languages To Learn in 2020
NeuralNine
55 Simple TCP Chat Room in Python
Simple TCP Chat Room in Python
NeuralNine
56 Image Classification with Neural Networks in Python
Image Classification with Neural Networks in Python
NeuralNine
57 Edge Detection with OpenCV in Python
Edge Detection with OpenCV in Python
NeuralNine
58 S&P 500 Web Scraping with Python
S&P 500 Web Scraping with Python
NeuralNine
59 Simple Sentiment Text Analysis in Python
Simple Sentiment Text Analysis in Python
NeuralNine
60 Introduction - Algorithms & Data Structures #1
Introduction - Algorithms & Data Structures #1
NeuralNine

This video teaches how to create a simple internet speed test in Python using the speedtest-cli library, covering topics such as installing the library, creating a speed test object, and formatting the results for better readability.

Key Takeaways
  1. Install the speedtest-cli library using pip
  2. Import the speedtest module in Python
  3. Create a speed test object using speedtest.Speedtest()
  4. Get a list of available servers using test.get_servers()
  5. Choose the best server using test.get_best_server()
  6. Perform a download test using test.download()
  7. Perform an upload test using test.upload()
  8. Get the ping result using test.results.ping
  9. Format the results for better readability
💡 The speedtest-cli library provides a simple way to measure internet speeds in Python, and formatting the results is necessary to make them more readable.

Related Reads

📰
AI CLI Tools Are Eating Each Other's Lunch
AI CLI tools are becoming increasingly similar, making it difficult to choose between them, and their failure patterns are identical, highlighting the need for more transparency and accountability in AI development
Dev.to · Tracepilot
📰
Loop Engineering: The Skill That Just Made Your AI Workflow Obsolete
Learn how loop engineering can automate AI workflows, making traditional prompting methods obsolete
Medium · Machine Learning
📰
We built a real-time Pokémon TCG AR overlay for live streams and open-sourced everything
Learn how to build a real-time Pokémon TCG AR overlay using a webcam, gaming PC, and open-source AI
Medium · Deep Learning
📰
I tested the new Claude Desktop on Linux - here's how it compares to rival apps
Learn how Claude Desktop on Linux compares to rival apps and its limitations with local AI
ZDNet
Up next
Copilot Cowork: Setup, Skills, Plugins & Pricing
Matt Tutorials
Watch →