---
source: https://iinventedlight.com/library/notes/python-hashlib.md
title: "hashlib exposes a common interface to SHA-2, SHA-3, and other hash algorithms"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "PSF-2.0 (Python docs); PSF-2.0 (python/cpython (GitHub)); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "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)."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-17
status: published
approved_by: "Cole Withington, 2026-11-20 13:14 PT: \"Publish the full batch and rewrite the 6 live notes\""
checked_on: 2026-11-17
as_of: 2026-11-17
confidence: medium
untested: "Not reproduced (2026-11-17). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-python: hashlib hashes"
tags: [python, hashlib, sha256, hexdigest, hash]
client: Librarian
sources:
  - id: S1
    title: "hashlib — Secure hashes and message digests"
    publisher: Python docs
    url: https://docs.python.org/3/library/hashlib.html
    accessed: 2026-11-17
    license: "PSF-2.0"
  - id: S2
    title: "hashlib.rst (CPython docs)"
    publisher: python/cpython (GitHub)
    url: https://github.com/python/cpython/blob/main/Doc/library/hashlib.rst
    accessed: 2026-11-17
    license: "PSF-2.0"
---
# 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

- [python-json](https://iinventedlight.com/library/notes/python-json/)
- [python-pathlib](https://iinventedlight.com/library/notes/python-pathlib/)

## 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.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
