Record Dependency and Artifact Provenance
Core idea
Reproducibility requires recorded versions, Python/platform constraints, build inputs and verified artifact hashes. A pinned requirement is more specific than a range but does not establish provenance. pip hash-checking mode requires pinned requirements and hashes for all dependencies. Use trusted indexes, review changes and keep build tools versioned. A digest from an untrusted source is not authentication.
from hashlib import sha256artifact = b'example build output'expected = sha256(artifact).hexdigest()print(len(expected))print(sha256(artifact).hexdigest() == expected)This teaching fixture uses a locally known expected digest; real expected hashes need a trusted channel.
Expected output:
64TrueRecord selected build inputs
import jsonrecord = {'python': '3.13', 'backend': 'setuptools', 'version': '1.0'}text = json.dumps(record, sort_keys=True)print(json.loads(text)['version'])print('backend' in json.loads(text))A manifest records inputs; this small manifest is not a complete lock or provenance attestation.
Expected output:
1.0TrueCommon mistake
Do not treat pip freeze, a version pin or a self-computed hash as proof of trust. A repeatable dependency selection also does not prove byte-identical builds.
Practice
For an approved local dependency set, record exact versions and trusted hashes, review all transitive dependencies, and rehearse pip install --require-hashes with a controlled wheelhouse. Do not use arbitrary example hashes.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Reproducibility and supply chain
Check your understanding of reproducibility and supply chain.
What is printed?
from hashlib import sha256print(len(sha256(b"demo").digest()))What is printed?
from hashlib import sha256print(sha256(b"a").digest()==sha256(b"b").digest())What establishes a meaningful expected digest?
What is needed in hash-checking mode?