Building with build
Create wheels and sdists.
Building with build is a free Python Academy lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Python Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
What Building Means
Your source code must be turned into distribution artifacts that pip can install. The modern tool for this is build, run as python -m build.
It produces two kinds of files: a source distribution and a wheel.
sdist vs wheel
Two artifact types:
- sdist (.tar.gz) a source archive; pip builds it on install
- wheel (.whl) a pre-built archive; pip just unpacks it
Wheels install faster and are preferred. The sdist is the fallback and the canonical source.
Installing the build tool
Install once with pip install build. It is a thin frontend: it reads your pyproject.toml, sets up an isolated environment, and invokes your build backend to create the artifacts.
You do not call the backend directly; build orchestrates it.
Running the Build
From the project root run python -m build. By default it makes both an sdist and a wheel and places them in a new dist/ directory.
Use --wheel or --sdist to build only one.
args = []
targets = []
if '--sdist' in args:
targets.append('sdist')
if '--wheel' in args:
targets.append('wheel')
if not targets:
targets = ['sdist', 'wheel']
print('Will build:', targets)Wheel Filenames
Wheel names encode metadata: mytool-0.1.0-py3-none-any.whl means name mytool, version 0.1.0, Python 3, no ABI requirement, any platform. Pure-Python packages get py3-none-any.
name = 'mytool'
version = '0.1.0'
wheel = name + '-' + version + '-py3-none-any.whl'
print(wheel)
print('Parts:', wheel[:-4].split('-'))Build Isolation
By default build creates a fresh virtual environment, installs the requires from your [build-system], and builds there. This guarantees the build does not accidentally depend on packages that only happen to be in your environment.
Inspecting the dist Folder
After a build, dist/ contains your artifacts. Listing it confirms what was produced before you upload. This is ordinary directory listing.
dist = ['mytool-0.1.0.tar.gz', 'mytool-0.1.0-py3-none-any.whl']
for f in dist:
kind = 'sdist' if f.endswith('.tar.gz') else 'wheel'
print(kind.ljust(6), f)Checking a Wheel
A wheel is just a ZIP archive. You can unzip it to verify your modules and data files are present and that nothing important was left out. If a file is missing here, it will be missing after install too.
Clean Builds
Stale files in build/ or dist/ can produce confusing results. Delete these directories before a release build so you publish exactly what the current source produces.
stale_dirs = ['build', 'dist', 'mytool.egg-info']
for d in stale_dirs:
print('Remove before clean build:', d)Reproducible Builds
The same source should always build the same artifacts. Pin your build backend versions in [build-system] requires and avoid pulling values from the live environment. Reproducibility means a teammate or CI server gets identical output.
Combined with clean builds, this removes works-on-my-machine surprises.
Building in CI
Most projects build on a continuous-integration server rather than a laptop. A CI job checks out the code, runs python -m build, and stores the artifacts. This guarantees releases come from a known, clean state every time.
The exact same command you run locally is what runs in CI.
Quick Check
Test your build knowledge.
Recap
You learned to build artifacts:
pip install build, thenpython -m build- Produces an sdist (.tar.gz) and a wheel (.whl) in
dist/ - Builds happen in an isolated environment using
[build-system]requires - Inspect the wheel and do clean builds before releasing
Frequently asked questions
Is the “Building with build” lesson free?
Yes — the full text of “Building with build” is free to read here on the web, and the Python Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Python Academy course, upgrade to CoddyKit PRO.
What will I learn in “Building with build”?
Create wheels and sdists. You practise Python Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Python Academy?
No prior experience is required. Python Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Building with build” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Python Academy lesson?
Yes. Every Python Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.