Publishing

Publishing to PyPI

Prerequisites

  1. Install build tools:
pip install build twine
  1. Create accounts on:

  2. Create API tokens:

    • PyPI: https://pypi.org/manage/account/token/
    • TestPyPI: https://test.pypi.org/manage/account/token/

Build the Package

# Clean previous builds
rm -rf dist/ build/ *.egg-info

# Build the package
python -m build

This creates:

  • dist/bloggy-0.1.0-py3-none-any.whl (wheel)
  • dist/bloggy-0.1.0.tar.gz (source distribution)

Test Locally

# Install from the wheel
pip install dist/bloggy-0.1.0-py3-none-any.whl

# Test the CLI
bloggy demo/
python -m twine upload --repository testpypi dist/*

Test installation from TestPyPI:

pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ bloggy

Publish to PyPI

python -m twine upload dist/*

Post-Publication

  1. Create a git tag:
git tag v0.1.0
git push origin v0.1.0
  1. Create a GitHub release with the changelog

  2. Test installation:

pip install bloggy

Updating the Package

  1. Update version in:

    • pyproject.toml
    • settings.ini
    • bloggy/__init__.py
  2. Update CHANGELOG.md

  3. Rebuild and republish:

rm -rf dist/ build/ *.egg-info
python -m build
python -m twine upload dist/*

Using PyPI API Tokens

Store your tokens in ~/.pypirc:

[distutils]
index-servers =
    pypi
    testpypi

[pypi]
username = __token__
password = pypi-YOUR-API-TOKEN-HERE

[testpypi]
username = __token__
password = pypi-YOUR-TESTPYPI-TOKEN-HERE

Then you can upload without entering credentials:

python -m twine upload dist/*