SHA-256 hashes versus wheelhouse for repeatable Python server deployments
Use SHA-256 hash-checking when servers can still reach an index but you need tamper resistance beyond version pinning; use a wheelhouse when the server is offline or must avoid recompilation. Choose the repeatability level by environment: pinning for a cross-platform baseline, hashes for automated tamper protection, and wheelhouse for full offline isolation with portability limits.
On this page
Key idea
SHA-256 hash-checking is the right choice when you need to protect against package tampering on PyPI or in the HTTPS chain while still allowing pip to fetch packages from an index, and when you want a lighter-weight alternative to a private index or vendored library. Use a wheelhouse when the target server has no internet access at all, when you want to avoid recompilation, or when you must guarantee that the exact same compiled artifacts are installed. For server deployments, move up the repeatability ladder deliberately: start with pinned versions in requirements.txt, add SHA-256 hashes when you need tamper resistance for automated installs, and reserve wheelhouse bundles for fully offline or air-gapped environments. The key trade-off is that hashes do not remove the need for network access and do not make wheels portable across operating systems or architectures, while wheelhouse bundles are portable only within the same OS and architecture family and require ongoing archive maintenance.
When SHA-256 hash-checking is enough instead of a wheelhouse
SHA-256 hash-checking is useful when your server deployment still has network access to PyPI or an internal index, but you want stronger guarantees than version pinning alone. Pinning versions protects you from newly released incompatible versions, but it still trusts the package source and the certificate authority chain. Adding hashes goes further: it verifies that the downloaded package matches the expected artifact, which helps when you are concerned about a compromised index or a weakened HTTPS chain. It also guards against a package changing without its version number changing on indexes that allow that behavior (PyPI itself protects against this).
This approach is a good fit for automated server deployments because it is lighter than standing up a private index of approved packages. You do not need to upload approved packages, maintain access control lists, or run a separate approval workflow. The requirements file itself becomes the auditable record, and version control gives you history for free. Hash-checking can also substitute for a vendored library, since upgrades are easier and the repository does not fill with copied source trees.
Generating the hashes is a separate step from pinning versions. pip freeze records the installed distributions and their version numbers, but it does not record artifact hashes, so a freeze output alone cannot enable hash-checking. The pip-tools package builds on pip and provides a workflow for this: running pip-compile with the --generate-hashes option produces a compiled requirements file that contains pinned versions together with --hash=sha256:... entries for each allowed artifact. The compiled file only pins and hashes the dependencies; it does not by itself download or install anything. Run pip-compile where the index is reachable, for example on a build machine or CI runner with network access to PyPI or an internal mirror, and write the result with the --output-file option rather than a shell redirect, since pip-compile already writes its default output to requirements.txt and redirecting stdout to the same file can truncate or conflict with the generated file. At install time, pip enforces the checks when the requirements file is used with the --require-hashes option; when a requirements file contains any hash, pip requires that every dependency be pinned and hashed, and it verifies every downloaded artifact against the listed hashes, refusing any package that is not pinned and hashed.
The important boundary is that hash-checking does not give you offline availability. If the server cannot reach an index at install time, hashes alone will not help, because pip still needs to fetch the package. In that case, a wheelhouse or vendored dependency is the more appropriate mechanism. Hash-checking is therefore best seen as a tamper-resistance layer for environments that still allow network access, not as a replacement for offline bundles.
pip-compile --generate-hashes --output-file requirements.txt requirements.inChoosing a repeatability level for server deployments
Repeatability is best treated as a ladder rather than a single setting. At the lowest strictness, pinning package versions in requirements.txt protects you from bugs or incompatibilities in newly released versions. This is easy to implement and works across operating systems and architectures, because it only constrains version numbers, not the installation source or artifact integrity. A requirements file with pinned package versions can be generated with pip freeze, which pins not only the top-level packages but also all of their transitive dependencies. Installing with --no-deps adds extra insurance against installing anything not explicitly listed. This level still trusts the locations you fetch packages from, such as PyPI, and the certificate authority chain.
The next level adds hash-checking. This is stricter because it verifies the downloaded artifact against a known hash. It is appropriate when automated server deployments need more protection than version pinning alone, especially when the deployment pipeline should not blindly trust the package source. It is also a practical middle ground when a full private index would be too heavy to maintain. Note that the tooling differs from the pinning level: pip freeze records installed versions but not hashes, so producing a hashed requirements file requires a compiler such as pip-compile with --generate-hashes, and pip enforces the hashes at install time with --require-hashes.
The strictest level for offline needs is a wheelhouse, also called an installation bundle. pip wheel can build all dependencies into a single directory with all compilation already performed, and that directory can be converted into a single archive. This archive then allows installation when index servers are unavailable and avoids time-consuming recompilation. The cost is portability: such a wheelhouse contains compiled packages, which are typically OS and architecture-specific, so these archives are not necessarily portable across machines.
For server deployments, the choice should follow the environment, not the other way around. If the server can reach an index and you mainly need tamper resistance, hash-checking is usually the better fit. If the server is offline or you must avoid recompilation, a wheelhouse is the better fit. If you need both, you can use hash-checking together with the wheelhouse method, because the bundle is still built from a requirements file and hash-checking mode can be used along with this method to ensure that future archives are built with identical packages.
# Creating the bundle, on a modern Unix system (run on a machine with network access and a platform matching the target server): tempdir=$(mktemp -d /tmp/wheelhouse-XXXXX) python -m pip wheel -r requirements.txt --wheel-dir=$tempdir cwd=`pwd` (cd $tempdir; tar -cjvf $cwd/bundled.tar.bz2 *) # Installing from the bundle, on a modern Unix system: tempdir=$(mktemp -d /tmp/wheelhouse-XXXXX) (cd $tempdir; tar -xvf /path/to/bundled.tar.bz2) python -m pip install --force-reinstall --no-index --no-deps $tempdir/*SHA-256 hashes as an alternative to wheelhouse for artifact integrity
SHA-256 hashes are best understood as an integrity and authenticity check on the packages pip downloads, not as an offline delivery mechanism. In a corporate server deployment with limited internet access, this distinction matters. If the server can still reach PyPI or an internal mirror during installation, hashes let you verify that the artifacts have not been altered in transit or at the source. That is valuable when the deployment pipeline is automated and you want a strong guarantee without building a private package repository.
The practical appeal is operational simplicity. Hash-checking removes the need to upload packages to a private index, maintain ACLs, and keep a separate audit trail, because version control already tracks the requirements file. It can also substitute for a vendored library in some cases, giving easier upgrades and less VCS noise. For many server deployments, that trade-off is attractive because it keeps the dependency contract explicit while avoiding a heavier infrastructure change.
Producing a hashed requirements file is a distinct workflow from producing a pinned one. pip freeze captures the versions of what is currently installed in an environment, which is useful for pinning but carries no artifact hashes. To get hashes, use a requirements compiler such as pip-compile from pip-tools with the --generate-hashes flag, which writes --hash=sha256:... entries for every dependency into the compiled file. The hashes then take effect only when pip installs with --require-hashes, so both the generation flag and the enforcement flag are needed; one without the other gives you either an ordinary pinned file or an error about unpinned requirements.
The limitation is that this strategy still depends on being able to fetch packages. It does not solve availability problems the way a private index or vendored library can. If your concern is mainly that the server might be isolated from the network during deployment, hash-checking is not the primary tool; a wheelhouse or vendored dependency is. A reasonable middle path is to use hashes for integrity and treat the requirements file as the controlled artifact, while separately deciding whether you need offline availability.
Applicability limits and trade-offs for hashes and wheelhouse
Hash-checking has clear advantages for automated server deployments: it protects against a compromise of PyPI or the HTTPS certificate chain, it guards against packages changing without a version increase on indexes that allow that, and it is a labour-saving alternative to a private index of approved packages. It also removes the need to upload packages, maintain ACLs, and keep a separate audit trail, since version control already tracks the requirements file. At the same time, it does not provide the availability benefits of a private index or vendored library, and it still relies on being able to fetch packages from somewhere.
Wheelhouse bundles have a different strength profile. They allow installation when index servers are unavailable and avoid time-consuming recompilation by shipping prebuilt wheels. That makes them useful for air-gapped or restricted servers. Their main drawback is portability: compiled packages are typically OS and architecture-specific, so the same archive is not necessarily portable across machines. They also require operational effort to create, archive, transfer, and refresh.
The compatibility constraint is especially important in corporate environments. If the build machine and the target server differ in operating system or architecture, a wheelhouse built on one may not be usable on the other without rebuilding. Hash-checking does not have that portability problem in the same way, because it does not ship compiled artifacts; it only constrains what pip fetches. However, hash-checking does require you to keep hashes current when versions change, so it is not a set-and-forget solution either.
In practice, the decision often comes down to which risk you are trying to reduce. If the main risk is tampering or unexpected artifact changes during download, hash-checking is the more direct control. If the main risk is network unavailability or long compile times on the target server, a wheelhouse is the more direct control. If both risks matter, combine the approaches and use a requirements file as the shared contract for both.
Applicability
- Confirm whether the target server can reach PyPI or an internal index during installation; if it cannot, hash-checking alone is not enough and a wheelhouse or vendored dependency is required.
- Confirm whether the deployment cares more about tamper resistance or about eliminating network dependence; hashes address the former, wheelhouse addresses the latter.
- Confirm whether the build and target machines share the same OS and architecture; wheelhouse archives are compiled and are not reliably portable across different platforms.
- Confirm whether your workflow can regenerate hashes when dependency versions change; hash-checking requires updating the requirements file when packages are upgraded.
- Confirm whether you need availability guarantees during index outages; neither hash-checking nor wheelhouse fully replaces a private index or vendored library for availability.
- Confirm whether you are willing to maintain an archive and transfer process; wheelhouse adds operational work for creating, storing, and moving bundles.
Where this applies
Hash-checking protects against a compromised PyPI or HTTPS certificate chain and against packages that change without a version increase on indexes that allow that behavior, but it does not remove network access and it does not protect against version changes when versions are bumped normally. It is also not a substitute for availability guarantees from a private index or vendored library. A wheelhouse avoids network access and recompilation, but compiled wheels are typically OS and architecture-specific, so the same archive is not necessarily portable across machines. Wheelhouse maintenance also adds cost: you must build the bundle on a machine with network access, archive it, transfer it, and keep it aligned with dependency changes. In air-gapped or strictly controlled server environments, these operational constraints often matter more than the simplicity of hash-checking. The repeatability levels are cumulative in strictness, not interchangeable: pinning versions is the easiest cross-platform baseline, hash-checking adds tamper resistance, and wheelhouse adds offline availability with portability limits.