hashlib exposes a common interface to SHA-2, SHA-3, and other hash algorithms
Answer: hashlib gives one common interface across many hash algorithms. The always-documented set includes SHA224, SHA256, SHA384, SHA512, the SHA-3 series, plus the legacy SHA1 and MD5 algorithms. Use sha256() to create a SHA-256 hash object, then feed it bytes with update and read digest or hexdigest.
Which constructors are always present
Constructors that are always present include md5, sha1, sha224, sha256, sha384, sha512, the SHA-3 and SHAKE constructors, and blake2b and blake2s. These correspond to algorithms_guaranteed. Additional algorithms may be available through hashlib.new if the linked OpenSSL build provides them, but they are not guaranteed on every install.
Adler32 and CRC32 are not in this module; they live in zlib. Some algorithms, including MD5, have known collision weaknesses.
See also
Claims
- id: C1 claim: hashlib implements a common interface to many hash algorithms. source: S1 evidence: "This module implements a common interface to many different hash algorithms."
- id: C2 claim: sha256() creates a SHA-256 hash object. source: S1 evidence: "use sha256() to create a SHA-256 hash object"
- id: C3 claim: Always-present constructors correspond to algorithms_guaranteed. source: S2 evidence: "algorithms_guaranteed"
- id: C4 claim: You can read the digest so far with digest or hexdigest. source: S2 evidence: "hexdigest"
Sources
- [S1] hashlib — Secure hashes and message digests. Python docs. https://docs.python.org/3/library/hashlib.html . License: PSF-2.0. Accessed 2026-11-17.
- [S2] hashlib.rst (CPython docs). python/cpython (GitHub). https://github.com/python/cpython/blob/main/Doc/library/hashlib.rst . License: PSF-2.0. Accessed 2026-11-17.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Python docs, hashlib — Secure hashes and message digests, PSF-2.0 (https://docs.python.org/3/license.html); python/cpython (GitHub), hashlib.rst (CPython docs), PSF-2.0 (https://raw.githubusercontent.com/python/cpython/main/LICENSE). Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Python docs, hashlib — Secure hashes and message digests, PSF-2.0 (https://docs.python.org/3/license.html); python/cpython (GitHub), hashlib.rst (CPython docs), PSF-2.0 (https://raw.githubusercontent.com/python/cpython/main/LICENSE).
Cite this
iinventedlight. 2026. "hashlib exposes a common interface to SHA-2, SHA-3, and other hash algorithms." iinventedlight Library, iil:note:7kevbezb, version of 2026-11-17. https://iinventedlight.com/library/notes/python-hashlib/. License: CC-BY-4.0.
@misc{iil_note_7kevbezb,
author = {{iinventedlight}},
title = {{hashlib exposes a common interface to SHA-2, SHA-3, and other hash algorithms}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-17},
url = {https://iinventedlight.com/library/notes/python-hashlib/},
note = {Permanent ID iil:note:7kevbezb. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/python-hashlib.md.