twine
twine is a Python command-line utility for uploading built packages and distribution archives to the Python Package Index (PyPI) and other package indexes that implement the same upload API.
Installation and Setup
Install it from PyPI into a virtual environment or system Python:
(venv) $ python -m pip install twine
Verify the installation:
(venv) $ twine --version
Key Features
- Uploads distribution files securely over verified HTTPS/TLS.
- Uploads PEP 740 attestations alongside each file with
twine upload --attestations. - Works with any build system that produces standard archives for sdists and wheels.
- Supports uploading multiple files at once.
- Validates distributions before upload with
twine checkto catch metadata or description rendering problems early. - Configures repositories and credentials via
.pypirc, environment variables, and keyring integration. - Authenticates to PyPI through Trusted Publishing, using an OpenID Connect (OIDC) token from a continuous integration provider such as GitHub Actions.
Credential-based uploads to PyPI and TestPyPI authenticate with an API token rather than an account password. The token is stored under the reserved username __token__, and the -u/--username flag has no effect on either index.
Usage
After you build the distribution files, check them before upload:
$ twine check dist/*
Upload to TestPyPI:
$ twine upload --repository testpypi dist/*
Upload to PyPI once satisfied with the test upload:
$ twine upload dist/*
Related Resources
Tutorial
How to Publish an Open-Source Python Package to PyPI
In this step-by-step tutorial, you’ll learn how to create a Python package for your project and how to publish it to PyPI, the Python Package Repository. Quickly get up to speed on everything from naming your package to configuring it using setup.cfg.
For additional information on related topics, take a look at the following resources:
By Leodanis Pozo Ramos • Updated Sept. 14, 2026