This guide walks you through setting up automated PyPI publishing for pytest-agents using GitHub's trusted publishing feature.
GitHub's trusted publishing uses OpenID Connect (OIDC) instead of long-lived API tokens:
- More Secure: No secrets to manage or rotate
- Automatic: Works seamlessly with GitHub Actions
- Recommended: PyPI's preferred authentication method
- GitHub repository with release workflow (✅ already configured)
- PyPI account
If you don't have a PyPI account yet:
- Go to https://pypi.org
- Click Register in the top right
- Fill in the registration form:
- Username
- Email address (you'll need to verify this)
- Password
- Check your email and click the verification link
- Log in to PyPI
Optional but Recommended:
- Enable two-factor authentication (2FA)
- Account Settings → Two factor authentication
- Use an authenticator app (Google Authenticator, Authy, etc.)
Important: Do this BEFORE the first release.
-
Log in to PyPI at https://pypi.org
-
Navigate to Publishing settings:
- Click your username (top right) → Account settings
- Click Publishing in the left sidebar
- Or go directly to: https://pypi.org/manage/account/publishing/
-
Scroll to "Add a new pending publisher"
-
Fill in the form with these EXACT values:
PyPI Project Name: pytest-agents Owner: kmcallorum Repository name: claudelife Workflow name: release.yml Environment name: (leave blank) -
Click Add
-
You should see the pending publisher listed:
pytest-agents (pending) Owner: kmcallorum Repository: claudelife Workflow: release.yml
The trusted publisher is now registered. On the next release:
- The GitHub Action will publish to PyPI
- PyPI will automatically create the
pytest-agentsproject - The "pending" status will change to "active"
Check current configuration:
# View pending publishers
# Go to: https://pypi.org/manage/account/publishing/Trigger a test release to verify everything works:
Option A: Push a feature commit
git commit -m "feat: test PyPI publishing setup"
git pushOption B: Manual workflow trigger
# Trigger release workflow manually
gh workflow run release.ymlMonitor the release:
# Watch the workflow
gh run watch
# Check if published to PyPI
# Visit: https://pypi.org/project/pytest-agents/Once published, verify the package can be installed:
# Create test environment
python -m venv test-env
source test-env/bin/activate # On Windows: test-env\Scripts\activate
# Install from PyPI
pip install pytest-agents
# Verify installation
pytest-agents version
# Test basic functionality
pytest-agents verify
# Cleanup
deactivate
rm -rf test-envIssue: Someone else has already claimed the pytest-agents name on PyPI.
Solution:
- Choose a different name (e.g.,
pytest-agents-ai,pytest-agents-framework) - Update
pyproject.toml:[project] name = "pytest-agents-ai" # Change this
- Update the trusted publisher configuration on PyPI
- Commit and push the change
Issue: The workflow can't authenticate with PyPI.
Check:
- Verify the PyPI project name matches exactly
- Confirm owner/repo/workflow names are correct
- Ensure workflow has
id-token: writepermission (✅ already configured)
Fix:
- Go to https://pypi.org/manage/account/publishing/
- Delete the pending publisher
- Re-add with correct values
Issue: Trying to re-publish the same version.
Solution: Versions are immutable on PyPI. Create a new release:
git commit -m "fix: update package metadata"
git pushThis will trigger a new version (e.g., 0.2.1).
Issue: The first publish might fail if there's a race condition.
Solution:
- Check the workflow logs:
gh run view --log-failed - If it's a timeout or temporary error, re-run:
gh run rerun <run-id>
# Via pip
pip index versions pytest-agents
# Via PyPI website
# Visit: https://pypi.org/project/pytest-agents/#historyView package download stats:
- PyPI Stats: https://pypistats.org/packages/pytest-agents
- Libraries.io: https://libraries.io/pypi/pytest-agents
If you need to remove a bad release:
- Go to https://pypi.org/project/pytest-agents/
- Select the version
- Click Options → Yank release
- Provide a reason (e.g., "Critical security issue")
Note: Yanked releases are still installable with explicit version but won't be installed by default.
You cannot delete releases from PyPI once published. You can only yank them.
If you absolutely need to remove something:
- Contact PyPI support: https://pypi.org/help/
- Be prepared to explain why (usually only for legal/security reasons)
Two-factor authentication adds an extra security layer:
- Account Settings → Two factor authentication
- Scan QR code with authenticator app
- Save recovery codes in a secure location
PyPI will email you when:
- A new version is published
- Account settings change
- New publishers are added
Review these emails to detect unauthorized activity.
The release workflow has minimal permissions:
permissions:
contents: write # For git commits/tags
packages: write # For Docker images
id-token: write # For PyPI publishingNever add additional permissions unless absolutely necessary.
Regularly review configured publishers:
- Go to https://pypi.org/manage/account/publishing/
- Remove any publishers you don't recognize
- Update if you rename repos or change workflows
If publishing multiple packages from one repo:
pyproject.toml:
[project]
name = "pytest-agents-core"
[project.optional-dependencies]
cli = [...]
agents = [...]PyPI Setup: Add separate trusted publishers for each package.
Publish pre-releases (alpha, beta, rc):
# In pyproject.toml
version = "0.3.0a1" # Alpha
version = "0.3.0b1" # Beta
version = "0.3.0rc1" # Release candidatePyPI will mark these as pre-releases automatically.
Install pre-releases:
pip install --pre pytest-agentsTest publishing before going to production:
- Register on Test PyPI: https://test.pypi.org
- Configure separate trusted publisher
- Update workflow to publish to Test PyPI first
- Verify, then publish to production PyPI
If trusted publishing doesn't work for your setup:
- Go to https://pypi.org/manage/account/token/
- Click Add API token
- Name: "GitHub Actions - pytest-agents"
- Scope: "Entire account" or specific project
- Copy the token (starts with
pypi-)
# Via GitHub web UI:
# Repository → Settings → Secrets → Actions → New secret
# Name: PYPI_API_TOKEN
# Value: pypi-...
# Or via gh CLI:
gh secret set PYPI_API_TOKEN
# Paste token when promptedModify .github/workflows/release.yml:
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
skip-existing: trueNote: This is less secure than trusted publishing.
- Help Center: https://pypi.org/help/
- Support: https://github.com/pypi/support
- Status: https://status.python.org/
- Workflow logs:
gh run view --log-failed - Re-run failed jobs:
gh run rerun <run-id>
Open an issue if you encounter problems:
gh issue create --title "PyPI publishing issue" --body "Description"Last Updated: 2026-01-05