Table of Contents
Releasing a package on PyPI is not as difficult as it used to be. The tooling has evolved significantly since I uploaded my first package many years ago. Most of the steps can now be automated using github actions. In this blog I describe my typical workflow for releasing a package on PyPI.
Authentication on PyPI #
So, first things first, we must set up authentication:
- Go to https://pypi.org/manage/account/token/
- Generate a new token, scope it to Entire account (all projects)
- Copy the token and create a new file:
It looks something like this:
- Enjoy publishing to PyPI without every typing your password again
First release #
Although I have automated releases of my packages, the first release has to be manual.
- Decide on a package name on PyPI that is still available
- Make a manual upload to PyPI. You can do this with
- Celebrate first release on pypi 🥳
(I recommend using testpypi if this is the first time.)
Automating the next releases #
The following releases can be completely automated using github actions.
- Go to your PyPI settings and register an API token scoped to your package.
- Add the token to this repo’s secrets named
Afterwards, this github action will take care of the rest:
Place this action in
.github/workflows/publish.yaml of your project.
New releases #
The workflow then becomes as follows:
- Bump the version (
patchas needed). I use
bumpversionto help with this.
- Make a new release on github. The upload to PyPI is triggered when a release is published. Make sure the tag matches the version.
If you use the standard github workflow (create branch->PR->merge->delete branch), it’s really easy to make changelogs this way too.