From script to package: publishing on PyPI

Posted 2026-01-20 on the pythondeck.com blog

You have a working script. Turning it into a pip install-able package takes about an hour the first time and ten minutes every time after that.

Project layout

mytool/
  src/
    mytool/
      __init__.py
      cli.py
  tests/
  pyproject.toml
  README.md
  LICENSE

pyproject.toml

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "mytool"
version = "0.1.0"
description = "Does one thing well."
readme = "README.md"
requires-python = ">=3.9"
dependencies = ["requests"]

[project.scripts]
mytool = "mytool.cli:main"

Build and test locally

python -m pip install --upgrade build twine
python -m build
pip install dist/mytool-0.1.0-py3-none-any.whl
mytool --help

Publish

# Get an API token from https://pypi.org/manage/account/token/
twine upload dist/*

Things to do before you publish

« all blog posts Browse tutorials