This guide walks you through publishing the agentcoach package to PyPI.
- Python 3.9+ installed
- PyPI account at https://pypi.org
- TestPyPI account (recommended) at https://test.pypi.org
- API tokens from both PyPI and TestPyPI
# Install build tools
pip install --upgrade build twine
# Build the package
python -m build
# Upload to TestPyPI (test first!)
twine upload --repository testpypi dist/*
# Upload to PyPI (production)
twine upload dist/*Before publishing, ensure:
# ✅ All tests pass
pytest
# ✅ No uncommitted changes
git status
# ✅ Version is bumped (if not first release)
# Edit pyproject.toml version field
# ✅ CHANGELOG is updated
# Add entry to CHANGELOG.md
# ✅ Clean previous builds
rm -rf dist/ build/ *.egg-infoEdit pyproject.toml:
[project]
name = "agentcoach"
version = "0.1.1" # Bump thisFollow Semantic Versioning:
- MAJOR (1.0.0): Breaking changes
- MINOR (0.1.0): New features, backwards compatible
- PATCH (0.0.1): Bug fixes
Add entry to CHANGELOG.md:
## [0.1.1] - 2024-12-30
### Added
- New feature X
### Fixed
- Bug Y
### Changed
- Improved Z# Clean previous builds
rm -rf dist/ build/ *.egg-info agentcoach.egg-info/
# Build source distribution and wheel
python -m buildThis creates:
dist/agentcoach-0.1.0.tar.gz(source distribution)dist/agentcoach-0.1.0-py3-none-any.whl(wheel)
Create API token:
- Go to https://test.pypi.org/manage/account/token/
- Create token with scope "Entire account"
- Save token securely
Upload:
twine upload --repository testpypi dist/*When prompted:
- Username:
__token__ - Password:
pypi-...(your TestPyPI token)
Test installation:
# Create test environment
python -m venv test_env
source test_env/bin/activate
# Install from TestPyPI
pip install --index-url https://test.pypi.org/simple/ \
--extra-index-url https://pypi.org/simple/ \
agentcoach
# Test it works
agentcoach --help
python -c "from agentcoach import analyze_trace; print('✅ Import works')"
# Clean up
deactivate
rm -rf test_envCreate API token:
- Go to https://pypi.org/manage/account/token/
- Create token with scope "Entire account" (or project-specific after first upload)
- Save token securely
Upload:
twine upload dist/*When prompted:
- Username:
__token__ - Password:
pypi-...(your PyPI token)
# Install from PyPI
pip install agentcoach
# Verify
agentcoach --version
python -c "import agentcoach; print(agentcoach.__version__)"Check package page: https://pypi.org/project/agentcoach/
git add .
git commit -m "Release v0.1.0"
git tag -a v0.1.0 -m "Release version 0.1.0"
git push origin main --tagsCreate ~/.pypirc to store repository configs:
[distutils]
index-servers =
pypi
testpypi
[pypi]
username = __token__
password = pypi-YOUR_PYPI_TOKEN_HERE
[testpypi]
repository = https://test.pypi.org/legacy/
username = __token__
password = pypi-YOUR_TESTPYPI_TOKEN_HEREThen upload with:
twine upload --repository testpypi dist/* # TestPyPI
twine upload dist/* # PyPISee .github/workflows/publish.yml for automated publishing on git tags.
To trigger:
git tag v0.1.0
git push origin v0.1.0You cannot re-upload the same version. Bump the version number.
# Check package contents
tar -tzf dist/agentcoach-0.1.0.tar.gz
# Verify metadata
twine check dist/*Ensure all dependencies are listed in pyproject.toml.
Check package structure:
# Should show agentcoach/ directory
unzip -l dist/agentcoach-0.1.0-py3-none-any.whl- Always test on TestPyPI first
- Use API tokens, not passwords
- Keep tokens secure (use environment variables or secrets manager)
- Version bump before each release
- Update CHANGELOG
- Tag releases in git
- Test installation in clean environment
- Check package page on PyPI after upload
Edit pyproject.toml:
version = "0.1.1"# Install
pip install bump2version
# Create .bumpversion.cfg
cat > .bumpversion.cfg << EOF
[bumpversion]
current_version = 0.1.0
commit = True
tag = True
[bumpversion:file:pyproject.toml]
search = version = "{current_version}"
replace = version = "{new_version}"
[bumpversion:file:agentcoach/__init__.py]
search = __version__ = "{current_version}"
replace = __version__ = "{new_version}"
EOF
# Bump version
bumpversion patch # 0.1.0 -> 0.1.1
bumpversion minor # 0.1.1 -> 0.2.0
bumpversion major # 0.2.0 -> 1.0.0- Never commit API tokens to git
- Use project-scoped tokens after first upload
- Rotate tokens periodically
- Use 2FA on PyPI account
- Store tokens in environment variables or secrets manager
# Build
python -m build
# Check
twine check dist/*
# Upload to TestPyPI
twine upload --repository testpypi dist/*
# Upload to PyPI
twine upload dist/*
# Install from TestPyPI
pip install --index-url https://test.pypi.org/simple/ agentcoach
# Install from PyPI
pip install agentcoach