PyPI Publishing
15 items · Technical · Hard difficulty · 1 hour
Fast, repeatable steps to package, test, and publish a Python library to TestPyPI and PyPI.
-
Create pyproject.toml with project metadata and build-system
Include name, version, authors, description, and [build-system] per PEP 517/621.
-
Set long_description and content-type from README in pyproject.toml
Point long_description to README.md and set content-type to text/markdown.
-
Add LICENSE file and update trove classifiers in pyproject.toml
Pick a SPDX license and add matching classifiers for Python versions and license.
-
Configure package inclusion rules and package_data
Ensure packages, include/exclude, and package_data cover modules and data files you want published.
-
Update the package version using semantic versioning
Bump the version in pyproject.toml (or your version file) to the next release number.
-
Update CHANGELOG.md with user-facing release notes
Record added, changed, fixed items and reference the new version.
-
Run the test suite locally with pytest and fix failures
Run pytest and ensure all tests pass before multi-env testing.
-
Configure and run tox for multi-version testing
Define tox envs for supported Python versions and run tox to verify compatibility.
-
Add or update CI workflow to run tests and build on push/PR
Create GitHub Actions to run tests, lint, and build artifacts automatically.
-
Build source and wheel distributions locally
Run python -m build to produce sdist and wheel in dist/.
-
Validate distributions with twine check
Run twine check dist/* to catch metadata or long_description issues.
-
Upload distributions to TestPyPI using twine and an API token
Use twine upload --repository testpypi dist/* and secure credentials via env vars.
-
Install the package from TestPyPI in a fresh virtualenv and smoke-test
pip install --index-url https://test.pypi.org/simple/ your-package and import/check core behavior.
-
Upload distributions to production PyPI with twine
After TestPyPI verification, run twine upload dist/* to PyPI using a token.
-
Create and push a Git tag, then publish a GitHub release with changelog
Tag the release (git tag -a vX.Y.Z), push tag, and create a GitHub release with notes.
Printed from TickYouOff — the interactive version tracks your progress and can be shared with others.