SyntaxStudy
Sign Up
Python Packaging and Distribution
Python Advanced 4 min read

Packaging and Distribution

Python Packaging

Package Python projects with pyproject.toml and build a wheel to publish to PyPI.

Example
# pyproject.toml
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "mypackage"
version = "1.0.0"
description = "A useful library"
requires-python = ">=3.10"
dependencies = ["requests>=2.28"]

[project.scripts]
mycli = "mypackage.cli:main"

# Build and publish
pip install build twine
python -m build
twine upload dist/*
Pro Tip

Use hatch or flit for zero-config packaging — setuptools is still valid but more verbose.