Hint: You can adjust the default video playback speed in your account settings.
Hint: You can set the default subtitles language in your account settings.
Sorry! Looks like there’s an issue with video playback 🙁 This might be due to a temporary outage or because of a configuration issue with your browser. Please see our video player troubleshooting guide to resolve the issue.

Everyday Project Packaging With pyproject.toml (Overview)

Packaging is often associated with publishing a project on PyPI, which can make you bypass packaging as something you don’t need to worry about at the start of your project. Python packaging has also had a long history and can be overwhelming for all levels of programmers. But it doesn’t have to be a scary process!

In this Code Conversation, you’ll follow a chat between Ian and Geir Arne demonstrating the relatively new, officially sanctioned way of setting up your Python projects using a pyproject.toml file and installing your package with pip. This offers nice benefits, such as:

  • Being able to call your project from anywhere
  • Playing on the same team as the import system
  • Allowing for consistent imports
  • Having one file that’ll work for many build systems

Along the way, you’ll:

  • Structure files and folders in your project
  • Understand different ways to run your script
  • Explore how the import system works
  • Explore the Python packaging world
  • Write a pyproject.toml file to configure your package
  • Install your pacakge with pip

You’ll also dive into various rabbit holes along the way as Ian and Geir Arne talk about all the aspects of the process.

To get the most out of this Code Conversation, you should have a handle on Python basics, be able to create a virtual environment and install packages, and have some exposure to the import system. Ideally, you have some experience fighting against the import system and thinking that there must be a better way.

Download

Sample Code (.zip)

2.2 KB

Download

Course Slides (.pdf)

2.0 MB

00:00 Welcome to another Code Conversation. In this chat, I’m talking with Geir Arne Hjelle about one of those topics that I’ve always had some niggling confusion about: how to set up your Python project when that little script you’ve been working on turns into something a bit larger.

00:17 As it turns out, this has implications for how you call your Python modules from the command line, how you structure your imports, how easy it is to configure tools like a code formatter, and—when the time comes—how to package it for distribution.

00:34 One of the pain points I’ve had when working with Python is that sometimes you end up having to do a lot of navigating on the command line to call Python from the right place, or else your imports won’t work. Also, being able to call a Python utility project from anywhere with a simple command can end up being a bit of a rabbit hole.

00:54 Most of the time, these tasks end up being a bit more complicated than you might expect because there’s seemingly many ways to go about it.

01:04 In this Code Conversation, Geir Arne will be taking me through the Python-sanctioned way to achieve all these things easily by setting up a pyproject.toml file and creating an editable install of my package for me to use and develop my project pain-free.

01:21 Using a pyproject.toml file and creating an editable install may sound like something you might only need when distributing your package. However, it’s something that will make developing anything larger than a single-file script much easier and less headache-prone.

Become a Member to join the conversation.