PyDocs

Nav

Cryptographic Services

file_digest

hashlib

function · Added in 3.11 (source)
  • file_digest(fileobj, digest, /)
Hash the contents of a file-like object. Returns a digest object.

*fileobj* must be a file-like object opened for reading in binary mode.
It accepts file objects from open(), io.BytesIO(), and SocketIO objects.
The function may bypass Python's I/O and use the file descriptor *fileno*
directly.

*digest* must either be a hash algorithm name as a *str*, a hash
constructor, or a callable that returns a hash object.
Changed in 3.14
  • 3.14: Now raises a BlockingIOError if the file is opened in non-blocking mode. Previously, spurious null bytes were added to the digest.
1 Example
>>> import io, hashlib, hmac
>>> with open("library/hashlib.rst", "rb") as f:
...     digest = hashlib.file_digest(f, "sha256")
...
>>> digest.hexdigest()
'...'
from the Python docs
See Also
No see-alsos for hashlib/file_digest
0 Notes
No notes for file_digest