Heading image

This is Day 23 of the #100DaysOfPython challenge.

This post will use GitHub actions to help automate the deploy of your Pip package to the PyPi registry.

We will work off the code repository written in yesterday’s post “Semantic Versioning In Python With Git Hooks”

The final code can be found here.


Getting started

We will clone the code from yesterday’s post as our starting place.

At this stage, we are ready to create our workflow.

Creating the workflow

We need to add our code to the workflow file .github/workflows/publish-to-pypi.yml.

Much of this file will get inspiration from .github/workflows/pytest.yml.

Add the following code to .github/workflows/publish-to-pypi.yml:

Our pipenv run build step comes from the script we added in a previous post.

We are now almost ready to test our workflow. The next step will be to ready the PYPI_API_TOKEN value on the final line.

Worth noting: There is also a test package index that you can use so you do not affect to main index. I am using the main index for my package.

Adding our PyPi token to GitHub

A prerequisite for this post was to setup a PyPi token to use.

With that token, we will use the GitHub CLI to post it up for use:

Testing our workflow

At this stage, all we need to do is push to remote:

Head to the link supplied to visit the repository and head to the actions tab and view the Publish Python 🐍 distributions 📦 to PyPI.

You should see your workflow succeed.

GitHub action success

The GitHub action also provides a link to your package on PyPi.

Update version on PyPi


Today’s post demonstrated how to automate your publish flow to PyPi on a push action.

Actions are a great way to automate your workflow. Today’s simple example enables a publish on each push, but you can improve on this to lock branches and even automate the versioning process.

Resources and further reading

Photo credit: worldsbetweenlines

Originally posted on my blog. To see new posts without delay, read the posts there and subscribe to my newsletter.

I write content for AWS, Kubernetes, Python, JavaScript and more. To view all the latest content, be sure to visit my blog and subscribe to my newsletter. Follow me on Twitter.



Senior Engineer @ Visibuild

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store