Automate TestPYPI upload of python packages with GitHub workflow

Github workflow can be used for building and Testing packages on Github repositories. For Python package repository, workflow/ GitHub action can be used to automate TestPYPI upload.

(TestPYPI is a separate instance of the Python Package Index that allows you to try distribution tools and processes without affecting the real index).

Prepare You Python Package

First up all you have to prepare your Python package . Make sure package consist of

  • file

Here is a sample code of

import os

with open("", "r") as fh:
    long_description =

    name="PACAKGE-NAME-USERNAME",  # Replace with your own username
    author="author name",
    description="short description",
        "Programming Language :: Python :: 3",
        "License :: OSI Approved :: MIT License",
        "Operating System :: OS Independent",

Read me file consist of

  • Repository/package details
  • Requirements
  • How to use the repo etc

Use a markdown page for serving the readme file

Github Repository and Action

Now it is time for setup workflow for the python repository you have uploaded to the

Get a TestPYPI account

As prerequisite for this tutorial you need to register an account in

Repository secret

Go to you repository settings-Secrets and add the following secrets



GitHub Secret

Add a workflow for upload a Python Package

Add a action , use manual method and copy following Upload TestPYPI workflow file also name file as UploadTestPYPI.yml

# This workflows will upload a Python Package using Twine when a release is created
# For more information see:

name: Upload PYPI

    types: [created]


    runs-on: ubuntu-latest

    - uses: actions/checkout@v2
    - name: Set up Python
      uses: actions/setup-python@v2
        python-version: '3.x'
    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip
        pip install setuptools wheel twine
    - name: Build and publish
        TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
        TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
      run: |
        python sdist bdist_wheel
        twine upload --repository testpypi dist/*

The above workflow will install dependencies on a Ubuntu cloud machine, then build the package, then upload the package to testpypi repository using twine and secret you have added to your repository, namely PYPI_USERNAME and PYPI_PASSWORD.

As we specified on the on section of the workflow, will execute the action whenever you create a new release.

You can check for result of the workflow at the actions link of your repository, also on the top of repo a notification will shown if the workflow is executed.

How to host webpages on github for free

GitHub is my favorite place to host my personal web apps. It is one of the finest places to host your web-based [ Python, Javascript, Django etc ] static websites.

Features I love

  • You can keep source code on the web
  • Discuss with others
  • Initially, you can host a static web page [can make static dynamic apps, with Python, we will discuss it later]
  • Make changes from your computer and commit and push changes to the repository you made, changes will go online

How to host a website on GitHub?

  • The first thing you need to do the GitHub software.Download and Install
  • Prepare your website on your PC
  • Create a repository with the following format on

  • The username and subdomain should match to host the website completely, otherwise the page not go live. You can try additional website by creating another Organization and then repository
  • Click the clone download the button on GitHub Pages


  • Open GitHub on the PC, File-Clone Repository
  1. Choose the Repository Folder first, say D:/Github [ where your source code will reside ]
  2. Paste the clone link and it will create a folder
  3. Copy all of your web pages and folders to the new folder.


  • Now you need to made first commit to the master[only master branch commit will affects the website]
  • Finally Push all changes back the GitHub and your site will go online.

Check mine