PyPI Publishing Setup Guide¶
This guide covers setting up the repository for automated publishing to PyPI via GitHub Actions.
Prerequisites¶
- PyPI Account: Create accounts on PyPI and Test PyPI
- GitHub Repository: Push the code to a GitHub repository
- API Tokens: Generate API tokens for both PyPI and Test PyPI
Step 1: Generate PyPI API Tokens¶
PyPI (Production)¶
- Go to PyPI Account Settings
- Click "Add API token"
- Set scope to "Entire account" (for initial setup)
- Copy the generated token (starts with
pypi-)
Test PyPI (Testing)¶
- Go to Test PyPI Account Settings
- Click "Add API token"
- Set scope to "Entire account"
- Copy the generated token (starts with
pypi-)
Step 2: Configure GitHub Secrets¶
In your GitHub repository settings:
-
Go to Settings → Secrets and variables → Actions
-
Add the following repository secrets:
Step 3: Set Up GitHub Environments¶
For additional security, create GitHub environments:
- Go to Settings → Environments
- Create two environments:
pypi(for production releases)test-pypi(for test releases)- Configure environment protection rules as needed
Step 4: Publishing Workflow¶
Test Release (Manual)¶
To test the publishing workflow:
- Go to Actions tab in GitHub
- Select Release workflow
- Click Run workflow
- Enter a test version (e.g.,
1.0.0-test.1) - This will publish to Test PyPI for verification
Production Release (Automatic)¶
For production releases:
-
Update version in
pyproject.toml -
Update
CHANGELOG.mdwith release notes -
Commit changes to main branch
-
Create and push a git tag:
-
GitHub Actions will automatically:
-
Run tests
- Build the package
- Publish to PyPI
- Create a GitHub Release
Step 5: Verify Installation¶
After publishing, test the package installation:
# Install from PyPI
pip install katana-openapi-client
# Test import
python -c "from katana_public_api_client import KatanaClient; print('✅ Package installed successfully')"
Version Management¶
This project uses Semantic Versioning:
- MAJOR version when you make incompatible API changes
- MINOR version when you add functionality in a backwards compatible manner
- PATCH version when you make backwards compatible bug fixes
Example version progression:
1.0.0→1.0.1(bug fix)1.0.1→1.1.0(new feature)1.1.0→2.0.0(breaking change)
Troubleshooting¶
Common Issues¶
- Token permissions: Ensure API tokens have correct scopes
- Package name conflicts: PyPI package names must be unique
- Version conflicts: Cannot upload same version twice to PyPI
Testing Locally¶
Test package building locally:
# Build package
uv build
# Check package
uv run twine check dist/*
# Test upload to Test PyPI (optional)
uv run twine upload --repository-url https://test.pypi.org/legacy/ dist/*
Security Best Practices¶
- Never commit API tokens to the repository
- Use environment protection rules for production releases
- Regularly rotate API tokens
- Review dependencies for security vulnerabilities
- Enable 2FA on PyPI accounts
Monitoring¶
After setup, monitor:
- Package downloads on PyPI stats
- Security alerts from GitHub
- Dependency updates from Dependabot
- CI/CD pipeline health
Support¶
For issues with:
- PyPI publishing: Check PyPI Help
- GitHub Actions: See GitHub Actions documentation
- Package building: Review uv documentation