LinuxCommandLibrary

twine

Upload Python packages to PyPI

TLDR

Upload package to PyPI

$ twine upload dist/*
copy
Upload to TestPyPI
$ twine upload --repository testpypi dist/*
copy
Upload with credentials
$ twine upload -u [username] -p [password] dist/*
copy
Check package before upload
$ twine check dist/*
copy
Upload specific files
$ twine upload [dist/package-1.0.tar.gz]
copy
Upload with verbose output
$ twine upload --verbose dist/*
copy

SYNOPSIS

twine [upload] [check] [-r repository] [-u user] [options] files

DESCRIPTION

twine uploads Python packages to PyPI and other package indexes. It's the recommended tool for publishing Python packages.
Package files (.tar.gz and .whl) in the dist directory are uploaded. These are created by build tools like build or setuptools.
Check mode validates package metadata before upload. It catches common issues that would cause upload failure.
TestPyPI allows testing the upload process without affecting the real PyPI. Packages can be installed from TestPyPI to verify.
Authentication uses username/password, API tokens, or keyring integration. API tokens are recommended for security.
HTTPS is always used for uploads. Previous tools allowed insecure uploads, which twine explicitly prevents.

PARAMETERS

upload FILES

Upload packages.
check FILES
Check package metadata.
-r REPO, --repository REPO
Target repository (pypi, testpypi, or URL).
--repository-url URL
Repository URL.
-u USER, --username USER
Username.
-p PASS, --password PASS
Password.
--non-interactive
Don't prompt for credentials.
-s, --sign
Sign files with GPG.
-c FILE, --config-file FILE
Config file.
--skip-existing
Skip already-uploaded files.
--verbose
Verbose output.

CONFIGURATION

~/.pypirc

Repository credentials and URLs for PyPI, TestPyPI, and custom indexes.
TWINE_USERNAME
Environment variable for authentication username.
TWINE_PASSWORD
Environment variable for authentication password or API token.

CAVEATS

Package names are permanent on PyPI. Version numbers can't be reused. Credentials need secure handling. Package must pass validation.

HISTORY

Twine was created by the Python Packaging Authority around 2013 to replace the insecure upload mechanism in setuptools. It ensures all uploads use HTTPS.

SEE ALSO

pip(1), build(1), setuptools(1), flit(1)

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard