Backend Development 7 min read

Using Twine to Publish Python Packages: Installation, Features, Commands, and Configuration

This article explains how to install Twine, create source and wheel distributions, upload packages securely to PyPI or TestPyPI, use signing with GPG, configure authentication via .pypirc or environment variables, and provides examples of common Twine sub‑commands and a custom upload command.

Python Programming Learning Circle
Python Programming Learning Circle
Python Programming Learning Circle
Using Twine to Publish Python Packages: Installation, Features, Commands, and Configuration

Twine is a utility for publishing Python packages to PyPI, allowing you to build, upload, and manage distribution files securely via HTTPS.

Installation : Twine can be installed with pip using pip install twine .

Basic usage : After creating source and wheel distributions with python setup.py sdist bdist_wheel , you can upload them to TestPyPI or PyPI using twine upload -r testpypi dist/* or twine upload dist/* . Authentication credentials are supplied interactively or via environment variables.

Key features : Supports HTTPS transfer, uploading any package format, and signing uploads with GPG using .asc files ( twine upload myproject-1.0.1.tar.gz myproject-1.0.1.tar.gz.asc ).

Custom command example : A sample setup.py snippet defines an UploadCommand class that builds the distribution and runs twine upload dist/* , then pushes a git tag.

Available sub‑commands include twine upload (upload distributions), twine check (verify metadata rendering on PyPI), and twine register (legacy registration). The help output for each command is shown in the original article.

Configuration : Twine reads settings from a .pypirc file in the user’s home directory or from the --config-file option. Environment variables such as TWINE_USERNAME , TWINE_PASSWORD , TWINE_REPOSITORY , TWINE_REPOSITORY_URL , TWINE_CERT , and TWINE_NON_INTERACTIVE control authentication and connection details.

CLIpythonconfigurationpackagingpypiuploadtwinegpg
Python Programming Learning Circle
Written by

Python Programming Learning Circle

A global community of Chinese Python developers offering technical articles, columns, original video tutorials, and problem sets. Topics include web full‑stack development, web scraping, data analysis, natural language processing, image processing, machine learning, automated testing, DevOps automation, and big data.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.