Automate Your PyPI Releases with This Simple Publishing Script
Discover a powerful, interactive script that automates version management, dependency checks, and uploading to PyPI, streamlining your entire release workflow.
Publishing a Python package to the Python Package Index (PyPI) is a rite of passage for many developers. But while twine
has made the upload process itself straightforward, the entire release workflow—from updating version numbers to building the package—can still be a manual and error-prone affair.
Did you remember to update the version in pyproject.toml
? Is the __init__.py
file in sync? Are all build dependencies installed? Forgetting one of these steps can lead to a broken release.
To solve this, I created publish-to-pypi-scripts
, a set of scripts that provides a comprehensive, interactive, and automated workflow for releasing your Python packages.
The Problem with Manual Releases
A typical release process involves a checklist of manual steps:
- Ensure
build
,twine
, andtoml
are installed. - Update the version number in
pyproject.toml
. - Propagate that version number to your package's
__init__.py
or a dedicatedversion.py
file. - Delete any old distribution files.
- Run the build process.
- Finally, run
twine upload
.
This workflow is ripe for automation.
A Better Way: The publish-to-pypi
Script
publish-to-pypi-scripts
consolidates this entire process into a single, interactive shell script. Just place publish_to_pypi.sh
in your project's root directory, make it executable, and run it.
chmod +x ./publish_to_pypi.sh
./publish_to_pypi.sh
The script guides you through the process with clear prompts, handling all the tedious steps along the way.
Key Features
- Interactive Interface: The script asks you what to do, from updating the version to publishing to TestPyPI or the real PyPI.
- Automatic Dependency Checks: It ensures
build
,twine
, andtoml
are installed before starting. - Centralized Version Management: It reads the version from
pyproject.toml
and automatically updates aversion.py
or__init__.py
file, ensuring your package's version is always in sync. - Secure Credential Management: It helps you create a local
.pypirc
file to store your PyPI API tokens securely, so you never have to type your credentials into the command line. - CI/CD Mode: For automated environments, you can run the script in a non-interactive mode, making it perfect for GitHub Actions or other CI/CD pipelines.
- Self-Updating: The script can even check for and download the latest version of itself, so your release tooling is always up to date.
How It Works
The publish_to_pypi.sh
script is a simple wrapper that downloads and runs the main Python script, publish_to_pypi.py
. This Python script contains all the logic for parsing your pyproject.toml
, managing files, and interacting with twine
.
This design keeps the tool self-contained and easy to add to any project without complex installation steps.
Get Started Today
Stop wasting time on manual releases and bring automation to your Python packaging workflow.
- Visit the publish-to-pypi-scripts GitHub repository.
- Grab the
publish_to_pypi.sh
script and add it to your project. - Run it and enjoy a smoother, more reliable release process.
By automating your releases, you can publish new versions with confidence, knowing that the tedious details are handled for you.