<< Back to posts

Publish Python Package on PyPI with Poetry

Posted on April 27, 2023 • Tags: python poetry packaging

How to package a Python library using Poetry and publish it on PyPI.

  1. Add all dependecies to your pyproject.toml (from requirements.txt)
poetry add $( cat requirements.txt )
  1. Build wheel
poetry build
  1. Publish to Test PyPI
# Optional - only run first time you push
# poetry config repositories.test-pypi https://test.pypi.org/legacy/

# Get an API token from here: https://test.pypi.org/manage/account/token/
export TEST_API_TOKEN='pypi-XXXXXXXXXXXXXX'

poetry publish -r test-pypi -u __token__ -p TEST_API_TOKEN
  1. Publish to PyPI
# Get an API token from here: https://pypi.org/help/#apitoken
export API_TOKEN='pypi-XXXXXXXXXXXXXX'

poetry publish -u __token__ -p API_TOKEN