Publishing to PyPI¶
This guide covers how to publish copa releases to the Python Package Index (PyPI).
Prerequisites¶
- PyPI Account: Create an account at pypi.org
- API Token: Generate an API token in your PyPI account settings
-
Configure Twine: Set up authentication by creating a
.pypircfile in your home directory or by using environment variables. For example: -
Using
.pypircfile:[pypi] username = __token__ password = your-api-token -
Using environment variables:
export TWINE_USERNAME="__token__" export TWINE_PASSWORD="your-api-token"
Development Dependencies¶
Install the required build and publishing tools:
pip install -e .[dev]
This installs:
- build - Package building tool
- twine - PyPI upload tool
- pytest - Testing framework
Release Process¶
1. Update Version¶
Edit pyproject.toml and bump the version number:
[project]
name = "copa"
version = "0.1.2" # Update this
2. Test Locally¶
Ensure everything works before publishing:
# Install in editable mode
pip install -e .
# Run tests
pytest
# Test the CLI
copa --help
3. Build Package¶
Create distribution files:
python -m build
This creates:
- dist/copa-X.X.X.tar.gz (source distribution)
- dist/copa-X.X.X-py3-none-any.whl (wheel)
4. Upload to PyPI¶
python -m twine upload dist/*
Enter your PyPI credentials when prompted, or use the configured API token.
Verification¶
After publishing, verify the release:
- Check pypi.org/project/copa
- Install from PyPI:
pipx install copa==X.X.X - Test basic functionality
Troubleshooting¶
Package Name Already Taken¶
If "copa" is already taken on PyPI, you may need to: - Use a different name (e.g., "copa-cli") - Contact PyPI support to request the name
Authentication Issues¶
- Ensure API token has upload permissions
- Verify token is configured correctly with
python -m twine configure - Check network connectivity and PyPI status
Build Errors¶
- Ensure all files are properly included in
pyproject.toml - Check that imports work correctly
- Verify package metadata is complete