Recognize Wheels and Source Distributions
Core idea
A wheel (.whl) is a built distribution, stored as a ZIP archive with metadata and compatibility tags. A source distribution (.tar.gz under the current specification) contains source and build metadata for building. A wheel can be platform-specific or universal; a source install may invoke build code. Inspect artifacts without executing their contents.
from packaging.utils import parse_wheel_filenamename, version, build, tags = parse_wheel_filename('example_parcel-1.0-py3-none-any.whl')print(name, version)print(str(next(iter(tags))))The synthetic filename declares Python 3, no ABI restriction and any platform. It does not prove the contents are valid.
Expected output:
example-parcel 1.0py3-none-anyRecognize a source filename
from packaging.utils import parse_sdist_filenamename, version = parse_sdist_filename('example_parcel-1.0.tar.gz')print(name, version)The parser reads the normalized distribution name and version, without unpacking anything.
Expected output:
example-parcel 1.0Common mistake
Do not rename a source archive to .whl or assume filename tags guarantee safe or compatible contents. Verify metadata and provenance. These examples require packaging.
Practice
Inspect the filenames and metadata of artifacts built from your own project; compare the wheel tags with the interpreter environment.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Wheels and source distributions
Check your understanding of wheels and source distributions.
What is printed?
from packaging.utils import parse_wheel_filenameprint(parse_wheel_filename("demo-2.0-py3-none-any.whl")[1])What is printed?
from packaging.utils import parse_sdist_filenameprint(parse_sdist_filename("demo-1.0.tar.gz")[0])Which artifact is already built?
What does a platform-specific tag describe?