speedtest module in python code example
Example 1: speedtest py
import speedtest
def get_final_speed():
rawspeed = speedtest.Speedtest().download()
roundedspeed = round(rawspeed)
finalspeed = roundedspeed / 1e+6
return finalspeed
def looped_av(y):
finalspeeds = 0
for i in range(y):
x = get_final_speed()
speeds = 0
count = 0
count += 1
speeds += x
print(f'{i+1}. {x}mb/s')
finalspeeds = speeds/count
return finalspeeds
while True:
repeat = input('1, 2, 3 or press {ENTER} to quit\n>>>')
if repeat == '1':
x = get_final_speed()
print(f'done, your download speed is {x}mb/s')
elif repeat == '2':
x = looped_av(2)
print(f'done, your average download speed is {x}mb/s')
elif repeat == '3':
times_through = int(input('how many times do you want the test to run?\n>>>'))
x = looped_av(times_through)
print(f'done, your average download speed is {x}mb/s')
else:
break
Example 2: how to test wifi speed py
$ pyspeedtest -h
usage: pyspeedtest [OPTION]...
Test your bandwidth speed using Speedtest.net servers.
optional arguments:
-d L, --debug L set http connection debug level (default is 0)
-m M, --mode M test mode: 1 - download
2 - upload
4 - ping
1 + 2 + 4 = 7 - all (default)
-r N, --runs N use N runs (default is 2)
-s H, --server H use specific server
-v, --verbose output additional information
--version show program's version number and exit
Example 3: how to test wifi speed py
sudo pip install pyspeedtest