Publishing
Publishing to PyPI
Prerequisites
- Install build tools:
pip install build twine
-
Create accounts on:
-
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/
Publish to TestPyPI (recommended first)
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
- Create a git tag:
git tag v0.1.0
git push origin v0.1.0
-
Create a GitHub release with the changelog
-
Test installation:
pip install bloggy
Updating the Package
-
Update version in:
pyproject.tomlsettings.inibloggy/__init__.py
-
Update CHANGELOG.md
-
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/*