Build & Deploy Python packages with ease

Niraj Kamdar
Code Dementia
Published in
2 min readJul 31, 2020

We all love python because there is a library in PyPI for almost every problem out there but distributing built wheel distribution for this libraries haven’t been an easy task especially for the Linux. There are many distro built on the GNU/Linux code base and each distro’s community makes its own choices about which library versions to include and how long to support them. This is a challenge for someone who just wants to distribute a Python library that contains native C/C++ code. It would be a lot of work to build separate binaries for Red Hat, SUSE, Ubuntu, and Debian — and even more work building separate binaries for each supported Python version!

Fortunately, PyPA’s manylinux project has come up with a solution that can make a built wheel compatible with most (though not all) Linux distros. They have been releasing docker images that can build this platform independent wheel. So, you can use manylinux docker image to build distro independent wheels but you need to have docker installed on your machine and every time you want to release a new version of your Python library you need to manually build and deploy it on PyPI. To make this process easier for developer, I have created a GitHub action called manylinux-wheel-builder which will build distro independent wheels and deploy it to PyPI on every push with version releases.

Basic Usage

If only want to build and publish wheels for Linux platform then below CD action will be enough. It will only build and publish package if pushed commit contains a version tag because this seems the most appropriate in this case but you can change it if you want.

The secret used in ${{ secrets.TWINE_USERNAME }} and ${{ secrets.TWINE_PASSWORD }} needs to be created on the settings page of your project on GitHub. See Creating & using secrets.

Pro tip: instead of using branch pointers, like master, pin versions of Actions that you use to tagged versions or SHA-1 commit identifiers. This will make your workflows more secure and better reproducible, saving you from sudden and unpleasant surprises.

Advanced Usage

If you also want to build and publish wheels for Windows and Mac OS in addition to Linux, you can append above action with following YAML snippet. This relies on setup-python action.

Don’t forget to see example CD actions from Examples.

I hope you like it and use it to build & deploy your python library to PyPI. If you like it, don’t forget to star my GitHub repository.

--

--

Niraj Kamdar
Code Dementia

GSoC’20 @PSF | Pythonista | Backend Web Developer | Blockchain Developer