3 The anatomy of a minimal Python package

 

This chapter covers

  • The Python package build system
  • Building a package using Setuptools
  • The directory structure of a Python package
  • Building a package for multiple targets

Python package builds are the product of coordination between a few different tools driven by a standardized process. One of the biggest choices you have as a package author is which set of tools to use. It can be difficult to assess the nuances of each, especially if you’re new to packaging. Fortunately, tools are standardizing around the same core workflow, so once you learn it, you’ve got the agility to switch between tools with minimal effort. This chapter covers what each category of these tools accomplishes and how they work together to produce a package, as well as how package builds vary for different systems.

Important

Before reading on, visit appendix B to install the tools you’ll need for this chapter.

You can use the code companion (http://mng.bz/69A5) to check your work for the exercises in this chapter.

3.1 The Python build workflow

The following sections cover what happens when you build a package and what you need to do to build a package successfully. You first need to learn about the pieces of the Python build system itself.

3.1.1 Parts of the Python build system

In the root directory for your project, start by running build using the following command:

$ pyproject-build

Because your package has no content yet, you should see an error like the following:

3.2 Authoring package metadata

3.2.1 Required core metadata

3.2.2 Optional core metadata

3.2.3 Specifying a license

3.3 Controlling source code and file discovery

3.4 Including non-Python files in a package

sitemap