import hashlib with open(fr'filename', 'rb') as f: md5 = hashlib.md5(f.read()).hexdigest() print(md5)