Python Tutorial 0/52 lessons ~6 min read Lesson 50

    Packaging & Distribution

    Ship Python code as a wheel on PyPI using pyproject.toml + build + twine (or modern uv publish, hatch publish).

    Course progress0%
    Focus
    8 guided sections
    Practice signal
    Examples included
    Career prep
    Foundation builder

    Introduction

    Ship Python code as a wheel on PyPI using pyproject.toml + build + twine (or modern uv publish, hatch publish).

    Understanding the topic

    Core concepts to understand:

    • pyproject.toml drives everything (PEP 621).
    • python -m build creates wheel + sdist.
    • twine upload dist/* publishes to PyPI.
    • Semver: 1.2.3 = major.minor.patch.

    Syntax reference

    Visual flow / code:

    toml
    [project]
    name = "my-lib"
    version = "0.1.0"
    description = "Cool stuff"
    requires-python = ">=3.10"
    dependencies = ["requests>=2.31"]
    [project.urls]
    Homepage = "https://github.com/me/my-lib"
    [build-system]
    requires = ["hatchling"]
    build-backend = "hatchling.build"
    # Build & publish
    $ python -m build
    $ twine upload dist/*

    Execution workflow

    1Packaging & Distribution Workflow
    1 / 4

    Step 1

    pyproject.toml drives everything (PEP 621).

    Apply this step while implementing packaging & distribution in real code.

    Real-world use

    Once published to PyPI, anyone can pip install my-lib. Major orgs run private indexes (Artifactory, AWS CodeArtifact) for internal libs.

    Best practices

    • Tag releases in git matching the version.
    • Use CI (GitHub Actions) to publish on tag.
    • Test on TestPyPI first.

    Hands-on exercise

    Interview preparation — practice these questions:

    • wheel vs sdist?
    • Semver — what changes when?
    • Why pyproject.toml?

    Summary

    In summary: pyproject.toml is the source of truth. build + twine (or uv) to publish.

    Ready to mark this lesson complete?Track your journey across the entire course.