In this final episode of season 2 of byte-sized RSE, we’ll be looking at Python packaging from both the user and package creator perspective. There are different package infrastructures in Python and we’ll focus here on the core packaging ecosystem maintained by the Python Packaging Authority (PyPA) and the pip package installer tool.
We’ll begin by looking at the use of pip to install packages and what actually happens when you install a package. Then we’ll look at the anatomy of a Python package and create a simple package ourselves, to see how one is structured and built.
Prerequisites: In order to be able to participate in the practical/interactive part of this session, you’ll need a computer with a regular CPython installation (i.e. not Anaconda) and pip available. You’ll also need some basic familiarity with working on the command line and be familiar with a command line-based editor such as nano, vi or emacs to enable you to easily edit files. The tutorial may also work using pip via Anaconda but this is not a supported setup for this session.
We also invite you to sign up for a Test PyPI account in advance of the session since there are a couple of steps required to set up multi-factor authentication. Doing this in advance will ensure that we have the time available during the session to also include publishing of packages as part of the interactive activity. You can sign up for the test PyPI account as follows:
2) Enter the required details - you’ll then be asked to verify your email address via a link emailed to you.
3) Now sign in to your account and set up two-factor authentication (2FA). If you’re not prompted to do this by default when you sign in, you can find the option under "Account settings”.
4) You now need to:
4a) Select "Generate recovery codes" and store them safely. You'll be asked to enter one of these codes to verify that you have them.
4b) Set up 2FA, e.g. using an authenticator app like LastPass Authenticator, or Microsoft Authenticator.
4c) With your chosen app, you’ll first need to scan a QR code, and then you'll enter a generated code to verify you've set things up correctly.
5) Verify that your 2FA configuration is correctly set up by logging out and the back in again using 2FA.