How to package your Python programs

setup.py

This method is largely deprecated, but you can read about it here.

pyproject.toml

I have only just begun to do this, which is sad, because apparently this became a standard back in 2016 🤦

Helpful reading:

TLDR; basically the dict you passed into setuptools to specify everything from required python version to cli tooling, is now a prettier toml file. That toml file is then used by not just pip, but other tooling like poetry (poetry seems to be the most popular tool).

Also, I like this weird duck thing: Purple Packaging Platypus

Poetry

Poetry is

a tool for dependency management and packaging in Python. It allows you to declare the libraries your project depends on and it will manage (install/update) them for you. Poetry offers a lockfile to ensure repeatable installs, and can build your project for distribution.

Poetry’s basic guide is actually pretty good.

Here’s some basics about poetry.

# init a poetry project in a directory with a project already - interactive
poetry init

# installs your current project, and dependencies, in a virtual env
poetry install

# sources your python virtual env for you to test your package
poetry shell

# builds the project for publishing
poetry build

# publish to pypi, $PYPI_TOKEN must be exported as your current pypi api token
poetry publish --username __token__ --password $PYPI_TOKEN

Here’s a github action that does it for you: JRubics/poetry-publish

Check out more poetry docs at here.

What about brew?

Well, that’s a rabbit hole that I haven’t had a chance to go down yet, but you probably want to start here:


Table of contents