10 Publish to PyPI
This page is a work in progress. You can see the current state of the project here.
10.1 note
- pyproject.toml to specify dependencies, python req, etc
10.2 PyPI (Python Package Index)
PyPI is the default online repository for Python packages. This is where packages are stored so that others can find and install them.
When you run:
pip install requests
You’re downloading the requests
package from PyPI. More specifically, you’re downloading the package’s distribution (which might be source code or precompiled binaries) to your local machine from PyPI servers.
10.3 pip (and friends)
pip
is the tool used to install packages from PyPI. It’s simple and widely supported.
Example:
pip install numpy
But when working with packages in Python, you need to take into account the package version. Maybe you need numpy
2.1.2
instead of 2.1.1
for your project.
You can read more about this in the handling dependencies article, but in summary, it’s important to control the version of the packages you use/distribute, to ensure reproducible workflows and avoid unexpected things.
Some newer tools are built around pip
to offer additional features such as dependency management and better performance.
One of the most important things these tools do is called dependency resolution, which involves calculating which versions of each package are compatible with each other based on version constraints. For example, you might be using a version of numpy that is incompatible (for whatever reason) with matplotlib, and since matplotlib relies on numpy, there’s a problem.
Since 2024, the best tool available is called uv. It’s super easy to use, super fast and does everything you need, in one place, with one tool. It’s more of a Python project manager than a simple package installer.