Skip to content

Mini-tutorial for python packaging, release and publish

Abstract

This mini-tutorial is a beginner's cheatsheet to python packaging. Check Python packaing user guide for an authoritative guidance on the topic.

Classical way

It is good practice to setup an isolated and clean environment e.g. with standard library venv. After that,

  • install packages for building wheels and source distributions:

    pip install wheel build
    
  • create setup.py where one can specify the requirements and meta-data:

    from setuptools import setup, find_packages
    
    setup(
        name='my_package',
        version='0.1.0',
        packages=find_packages(),
        install_requires=[
            'numpy',
            'pandas',
        ],
        # Optional: Add more metadata
    )
    
  • actually create wheels and source distribution:

    python -m build
    

Alternatively, with uv

uv is a modern python dev tool, see features and install guide.

It is compliant with PEP 517 1, PEP 518 2.

Use the project interface of uv to init project and add dependencies.

uv init
uv add DEPENDENCIES

then

uv build

Create a tag and release

git tag -a v0.1.0 -m 'release message'
git push --tags

This will create a tag named "v0.1.0" with the message "release message". The distribuion files will be displayed as assets for the tag.

Publish

Publish to pypi index requires the developer to setup an account and get the API token. Using uv, run this

uv publish --token TOKEN

with the dev's API token in place of TOKEN.


  1. why pyproject.toml? https://peps.python.org/pep-0518/ 

  2. understand build frontend, build backend. https://peps.python.org/pep-0517