Skip to content

Publishing a Python Package

Joey Shi edited this page May 7, 2022 · 2 revisions

Project Structure

src
- package1
- package2
- ...
pyproject.toml
setup.cfg

PyPI Registration

Register an account on https://pypi.org/ and create an API token in account settings. Create a pypi config file in the home directory $HOME/.pypirc with the following content:

[pypi]
  username = __token__
  password = pypi-<your-api-token>

Build and Deploy

Build the package by running pip install . in the same directory as setup.cfg. Running the command with the -e indicates the package will be installed in editable mode, so changes in the main project code will always be reflected in the installed package (useful for developing).

A minimal distributable build zip file can be made using python -m build --sdist. This can be installed with pip install build if missing.

Upload your package with twine upload dist/*. This can be installed with pip install twine if missing.

Note: once a package is uploaded, it cannot be reuploaded until the version number is updated in setup.cfg.

Clone this wiki locally