TExcelTAD
Home › Python Packaging: pip, venv, Poetry & uv › Building & Inspecting Wheels

Building & Inspecting Wheels

python -m build (the build package from PyPA) is the reference PEP 517 front end: it builds an sdist and a wheel the same way pip would, but keeps them in dist/ instead of installing. Learning to open what you built is the single most useful packaging habit: most "works on my machine, broken on PyPI" bugs are a missing file that a quick unzip -l would have shown.

Build both distributions

bash · try it yourself
python3 -m venv .venv && . .venv/bin/activate
pip install -q build
mkdir -p greet/src/greet && cd greet
cat > pyproject.toml <<'TOML'
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "greet"
version = "0.1.0"
description = "Friendly greetings"
requires-python = ">=3.13"
dependencies = ["rich>=13"]
TOML
cat > src/greet/__init__.py <<'PY'
def hello(name: str) -> str:
    return f"Hello, {name}!"
PY
echo '{"default": "world"}' > src/greet/defaults.json
python -m build
ls dist
* Creating isolated environment: venv+pip...
* Installing packages in isolated environment:
  - hatchling
* Getting build dependencies for sdist...
* Installed build dependency versions:
  - hatchling==1.32.4
* Building sdist...
* Building wheel from sdist
* Creating isolated environment: venv+pip...
* Installing packages in isolated environment:
  - hatchling
* Getting build dependencies for wheel...
* Installed build dependency versions:
  - hatchling==1.32.4
* Building wheel...
Successfully built greet-0.1.0.tar.gz and greet-0.1.0-py3-none-any.whl
greet-0.1.0-py3-none-any.whl
greet-0.1.0.tar.gz

By default build makes the sdist first and then builds the wheel from the unpacked sdist ("Building wheel from sdist"). That's deliberate: if a file is missing from the sdist, the wheel build fails right here instead of on a user's machine months later. Each step runs in a fresh isolated environment with only [build-system] requires installed. python -m build --wheel or --sdist builds just one.

Look inside the wheel

A wheel is a zip file, so the usual zip tools work:

bash · try it yourself
python3 -m venv .venv && . .venv/bin/activate
pip install -q build
mkdir -p greet/src/greet && cd greet
printf '[build-system]\nrequires = ["hatchling"]\nbuild-backend = "hatchling.build"\n\n[project]\nname = "greet"\nversion = "0.1.0"\nrequires-python = ">=3.13"\ndependencies = ["rich>=13"]\n' > pyproject.toml
echo 'def hello(name): return f"Hello, {name}!"' > src/greet/__init__.py
echo '{"default": "world"}' > src/greet/defaults.json
python -m build -q --wheel > /dev/null 2>&1
unzip -l dist/greet-0.1.0-py3-none-any.whl
echo "--- WHEEL"
unzip -p dist/greet-0.1.0-py3-none-any.whl greet-0.1.0.dist-info/WHEEL
echo "--- RECORD"
unzip -p dist/greet-0.1.0-py3-none-any.whl greet-0.1.0.dist-info/RECORD
Archive:  dist/greet-0.1.0-py3-none-any.whl
  Length      Date    Time    Name
---------  ---------- -----   ----
       42  2026-01-01 00:00   greet/__init__.py
       21  2026-01-01 00:00   greet/defaults.json
       97  2026-01-01 00:00   greet-0.1.0.dist-info/METADATA
       87  2026-01-01 00:00   greet-0.1.0.dist-info/WHEEL
      344  2026-01-01 00:00   greet-0.1.0.dist-info/RECORD
---------                     -------
      591                     5 files
--- WHEEL
Wheel-Version: 1.0
Generator: hatchling 1.32.4
Root-Is-Purelib: true
Tag: py3-none-any
--- RECORD
greet/__init__.py,sha256=oY3XzpGTbiyBzEN9xA_1j4nuHSn3BwRJz5ddzTUQ-es,42
greet/defaults.json,sha256=bSpos65Av_PjAE8BA_nYjmsLf_qOCgB98ggW4TYXw-Q,21
greet-0.1.0.dist-info/METADATA,sha256=tPAT5Tf3r77j-EWI3zYKzNMy_CtCdJV8r3-7KHd3rfo,97
greet-0.1.0.dist-info/WHEEL,sha256=W3fkpkm7-wf9vBI5Z-7s0eWkeM-spu78I8Neb98DeEg,87
greet-0.1.0.dist-info/RECORD,,

The .dist-info folder is the wheel's metadata, and it's copied into site-packages on install:

File Contents
METADATA name, version, dependencies (Requires-Dist), description: what pip resolves with
WHEEL wheel format version, the backend that made it, Root-Is-Purelib, the tags
RECORD every file with its SHA-256 (urlsafe base64) and size; pip uses it to uninstall, and to verify
entry_points.txt console scripts and plugin registrations (next lesson)
licenses/ license files (PEP 639)

Note the timestamps: every file is dated 2026-01-01 00:00. Backends honour SOURCE_DATE_EPOCH, which this container sets, so the same source produces a byte-identical wheel on every run. That's a reproducible build, and it's what lets you compare a wheel on PyPI with one you build yourself.

Look inside the sdist

bash · try it yourself
python3 -m venv .venv && . .venv/bin/activate
pip install -q build
mkdir -p greet/src/greet greet/docs && cd greet
printf '[build-system]\nrequires = ["hatchling"]\nbuild-backend = "hatchling.build"\n\n[project]\nname = "greet"\nversion = "0.1.0"\nrequires-python = ">=3.13"\n' > pyproject.toml
echo 'def hello(name): return f"Hello, {name}!"' > src/greet/__init__.py
echo 'notes' > docs/design.md
echo 'secret=1' > .env
printf '.env\n' > .gitignore
python -m build -q --sdist > /dev/null 2>&1
tar tzf dist/greet-0.1.0.tar.gz
greet-0.1.0/docs/design.md
greet-0.1.0/src/greet/__init__.py
greet-0.1.0/.gitignore
greet-0.1.0/pyproject.toml
greet-0.1.0/PKG-INFO

Hatchling respects .gitignore, so .env stayed out while docs/ went in. Other backends have other rules (setuptools uses MANIFEST.in and, with a plugin, Git), which is why the check is worth a few seconds before every first release.

Other front ends, same result

build is not the only way to call a backend:

Command Notes
python -m build the reference; sdist then wheel from sdist
uv build same behaviour, much faster environment setup; --wheel, --sdist, --package in workspaces
poetry build builds the current Poetry project with poetry-core
hatch build hatchling projects
pip wheel . builds a wheel and wheels for every dependency into the current folder; handy for a wheelhouse, not for releases
bash · try it yourself
mkdir -p greet/src/greet && cd greet
printf '[build-system]\nrequires = ["hatchling"]\nbuild-backend = "hatchling.build"\n\n[project]\nname = "greet"\nversion = "0.1.0"\nrequires-python = ">=3.13"\n' > pyproject.toml
echo 'def hello(name): return f"Hello, {name}!"' > src/greet/__init__.py
uv build 2>&1
python3 -m venv /tmp/v && /tmp/v/bin/pip install -q build && /tmp/v/bin/python -m build -q -o dist2 > /dev/null 2>&1
cmp dist/greet-0.1.0-py3-none-any.whl dist2/greet-0.1.0-py3-none-any.whl && echo "uv build and python -m build made identical wheels"
Building source distribution...
Building wheel from source distribution...
Successfully built dist/greet-0.1.0.tar.gz
Successfully built dist/greet-0.1.0-py3-none-any.whl
uv build and python -m build made identical wheels

Both front ends called the same hatchling hooks with the same fixed timestamp, so the wheels are byte for byte the same.

Test yourself

Why does python -m build build the wheel from the sdist rather than from your source tree?

  1. It's faster
  2. To prove the sdist contains everything needed to build; a missing file fails now instead of on a user's machine
  3. Wheels can't be built from source trees
  4. To compress better

Which file in a wheel lists every installed file with its hash?

  1. METADATA
  2. WHEEL
  3. RECORD
  4. top_level.txt

What makes two builds of the same source produce byte-identical wheels here?

  1. Compression level 0
  2. SOURCE_DATE_EPOCH fixes the timestamps of the files in the archive
  3. Using uv
  4. The --reproducible flag