About Checking Internet Bandwidth

You can check your Internet bandwidth using speedtest-cli, as follows:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
import speedtest

def sizeof_fmt(num, suffix="B"):
    for unit in ["", "K", "M", "G", "T", "P", "E", "Z"]:
        if abs(num) < 1024.0:
            return f"{num:3.1f} {unit}{suffix}"
        num /= 1024.0
    return f"{num:.1f} Y{suffix}"

if __name__ == "__main__":
    s = speedtest.Speedtest()
    download = s.download()
    upload = s.upload()
    print(f"Download: {sizeof_fmt(download)}/s")
    print(f"Upload: {sizeof_fmt(upload)}/s")

Tips and Tricks Programming Dev Ops Development Python 3