How to test USB Drive speed with Python Code

Its amazing to test usb drive speed with python, a small script in python can check the removable disk’s speed. Just run the code in python and you will get your Removable USB Flash Drive(Pen Drive) Speed. Here is how you can test pendrive speed with python.

Code provided in 2nd method can test speed of usb device on all operating systems.

How to test Pen Drive speed with Python

1st Method to Run Speed Test (windows only)

  1. Plug -in your USB drive to the computer
  2. Open Python 2.7
  3. Run the code

Python Code For Quick Speed Test (

[alert style=”grey]

import time, os
path = raw_input("Enter the Path Drive Letter of Removale Drive. e.g I ")
pat= path.split(":")
testFile = path+":/crazyTest"
print "Checking your Removable Drive Speed......"
def test(sTime):
f = open(testFile,'a')
for i in range(0,160000):
f.write('we are testing write speed')
diff = time.clock() - sTime
speed = (os.stat(testFile).st_size/1048576)/diff
print "your Removable. drive speed is "+ str(100/int(diff)) +"% near above "+str(speed)+" mb/sec"
startTime = time.clock()


The above code will generate a file in your USB file system. This code is estimating the speed of your usb drive by getting the time difference before it start writing the file and when it is finished.

2nd Method to Run Speed Test (All operating systems)

You can download the above code from github repository: usb-speed-test-python

  1. Run file
  2. Type full and correct path
  3. Result would be an approx drive speed in mb/sec


Thanks for using the script !!