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 Anaconda.org, 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.