Chapter 6. Shipping Great Code

This chapter focuses on best practices for packaging and distributing Python code. You’ll either want to create a Python library to be imported and used by other developers, or create a standalone application for others to use, like pytest.

The ecosystem around Python packaging has become a lot more straightforward in the past few years, thanks to the work of the Python Packaging Authority (PyPA)1—the people who maintain pip, the Python Package Index (PyPI), and much of the infrastructure relevant to Python packaging. Their packaging documentation is stellar, so we won’t reinvent the wheel in “Packaging Your Code”, but we will briefly show two ways to host packages from a private site, and talk about how to upload code to, the commercial analogue to PyPI run by Continuum Analytics.

The downside of distributing code through PyPI or other package repositories is that the recipient must understand how to install the required version of Python and be able and willing to use tools such as pip to install your code’s other dependencies. This is fine when distributing to other developers but makes the method unsuitable for distributing applications to end users who aren’t coders. For that, use one of the tools in “Freezing Your Code”.

Those making Python packages for Linux may also consider a Linux distro package (e.g., a .deb file on Debian/Ubuntu; called “build distributions” in Python documentation). That route is a ...

Get The Hitchhiker's Guide to Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.