python -m twine: Upload Packages to PyPI
Publish your built wheels and sdists to an index.
twine uploads distributions to PyPI (or a private index) over HTTPS. Run "python -m build" first, then "twine upload dist/*" to publish.
What it does
Uploads the files in dist/ to a package index, and can validate their metadata first with "twine check". CI authenticates with an API token, usually via environment variables.
Common usage
Terminal
python -m pip install twine
python -m twine check dist/*
python -m twine upload dist/*
python -m twine upload -r testpypi dist/*Common CI auth: token via env
Set the username to __token__ and pass the API token as the password. Using env vars keeps the secret out of the command line and logs.
Terminal
export TWINE_USERNAME=__token__
export TWINE_PASSWORD="${PYPI_API_TOKEN}"
python -m twine upload dist/*