Skip to content

Twine: Python Package Upload Tool

Twine is a command-line tool for uploading Python distribution files (sdists and wheels) to PyPI and compatible package indexes. It replaced the deprecated python setup.py upload command, which transmitted credentials over unencrypted connections.

When to use Twine

Use Twine when you build packages with build or setuptools and need a standalone upload step. Tools like uv, poetry, flit, hatch, and pdm have built-in publish commands that handle uploads directly. If you already use one of those tools, you don’t need Twine.

For new projects, uv publish is the recommended path. See Publishing Your First Python Package to PyPI for a walkthrough.

Usage

Build your package first, then upload the resulting files from dist/:

$ python -m build
$ twine upload dist/*

Twine prompts for your PyPI username and password (or API token). To avoid interactive prompts, set credentials via environment variables or a .pypirc file.

Upload to TestPyPI

Test uploads against TestPyPI before publishing to the real index:

$ twine upload --repository testpypi dist/*

Check packages before uploading

Validate that distribution files will be accepted by PyPI:

$ twine check dist/*

This catches metadata problems (missing description, invalid classifiers) before you attempt an upload.

Configure credentials with .pypirc

Create a ~/.pypirc file to store repository URLs and API tokens:

[pypi]
username = __token__
password = pypi-AgEI...

[testpypi]
repository = https://test.pypi.org/legacy/
username = __token__
password = pypi-AgEI...

Warning

API tokens stored in .pypirc are long-lived secrets. For CI pipelines, trusted publishing eliminates the need to store tokens entirely.

Installation

$ pip install twine

Or with pipx for an isolated install:

$ pipx install twine

Learn More

Handbook guides

Official documentation

Last updated on

Please submit corrections and feedback...