Developing Code That Performs Internet Speed Tests with Python
In this article, I will tell you how you can easily write the code that writes internet speed measurement using the Python programming language. For this I need to install a library on a linux system. The best option for this would be to install the speedtest-cli
library. You can complete the installation as follows. You can visit the github repo to get more information from speedtest-cli library.
pip install speedtest-cli
Let’s start now. Simple example that shows the download and upload speed in Megabits per second (Mbps):
import speedtest
st = speedtest.Speedtest()
download = st.download()
upload = st.upload()
print(f"Download speed: {download:.2f} Mbps")
print(f"Upload speed: {upload:.2f} Mbps")
To get the time-out value, you can use the .timed_out
attribute of the Speedtest
object. Here is an example:
import speedtest
st = speedtest.Speedtest()
timeout = st.timed_out
print(f"Timed out: {timeout}")
In this article, I have told you how you can calculate internet speed in detail using the python programming language. Take care and see you in my next post.