twine upload: Publish to PyPI Command Reference
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.
Common flags / usage
- twine upload dist/* -- upload everything in dist/
- -r, --repository NAME -- upload to a configured repository
- --repository-url URL -- upload to an explicit index URL
- --skip-existing -- do not fail if a version already exists
- auth via TWINE_USERNAME=__token__ and TWINE_PASSWORD env vars
Example
shell
- run: python -m pip install twine
- env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
run: |
python -m twine check dist/*
python -m twine upload --skip-existing dist/*In CI
Authenticate with an API token: username __token__ and the token as the password, passed via env vars so the secret stays out of logs. Run twine check first to catch metadata errors before the upload.
Key takeaways
- twine upload publishes dist/ artifacts to PyPI or a private index.
- Authenticate with __token__ and an API token through env vars.
- Run twine check before uploading to catch metadata problems.
Related guides
twine check: Validate Distributions Command ReferenceReference for twine check in CI: validating built distribution metadata and long-description rendering before…
python -m build: Build Distributions Command ReferenceReference for python -m build in CI: producing an sdist and wheel in an isolated environment from pyproject.t…
poetry publish: Publish to PyPI Command ReferenceReference for poetry publish in CI: uploading built artifacts to PyPI or a private repository, --build and --…