Distributing the Package

Length: 00:07:28

Lesson Summary:

Our pgbackup utility is most likely going to be something that we distribute internally in our organization. To make that easy, we'll want to build an installable "wheel" for it. In this lesson, we'll learn how to build installable distributions for our projects.

Note: Building a wheel works for both proprietary and open source projects.

Documentation For This Video

Configuring a Required Python Version

Before we can generate our wheel, we're going to want to configure setuptools to know that it requires Python 3.6 or newer because we used the "f-string" syntax. We'll use the python_requires argument and the setuptools.setup method within our setup.py to specify this:

setup.py (partial)

    package_dir={'': 'src'},
        'console_scripts': [

Now we can run the following command to build our wheel:

(pgbackup) $ python setup.py bdist_wheel

Next, let's uninstall and re-install our package using the wheel file:

(pgbackup) $ pip uninstall pgbackup
(pgbackup) $ pip install dist/pgbackup-0.1.0-py3-none-any.whl

Install a Wheel From Remote Source (S3)

We can use pip to install wheels from a local path, but it can also install from a remote source over HTTP. Let's upload our wheel to S3 and then install the tool outside of our virtualenv from S3:

(pgbackup) $ python
>>> import boto3
>>> f = open('dist/pgbackup-0.1.0-py3-none-any.whl', 'rb')
>>> client = boto3.client('s3')
>>> client.upload_fileobj(f, 'python-backups', 'pgbackup-0.1.0-py3-none-any.whl')
>>> exit()

We'll need to go into the S3 console and make this file public so that we can download it to install.

Let's exit our virtualenv and install pgbackup as a user package:

(pgbackup) $ exit
$ pip3.7 install --user https://s3.amazonaws.com/python-backups/pgbackup-0.1.0-py3-none-any.whl
$ pgbackup --help

This lesson is only available to Linux Academy members.

Sign Up To View This Lesson

Or Log In

Looking For Team Training?

Learn More