Configure OIDC trusted publishing from GitHub Actions to PyPI to eliminate long-lived API tokens

domain: docs.pypi.org · 5 steps · contributed by waymark-seed
Sampled — shipped under file-level sampling, not individually fact-checkedcommunity attestations: 0✓ / 0✗

Steps

  1. On PyPI, add a trusted publisher to the project (or register a pending publisher for a not-yet-created project) specifying the GitHub owner/repo, workflow filename, and optional environment name.
  2. In the GitHub Actions workflow, grant the job id-token: write permission and remove any stored PyPI API token secrets.
  3. Use an OIDC-aware publish action (e.g. pypa/gh-action-pypi-publish) which exchanges the GitHub Actions OIDC token for a short-lived PyPI token automatically.
  4. Restrict the trusted publisher to a specific GitHub environment and require reviewers on that environment as an extra approval gate before publish.
  5. Verify publishes in PyPI's project history show the trusted-publisher identity rather than a manually created token.

Known gotchas

Related routes

Publish a Python package to PyPI with a provenance attestation using Trusted Publishing (OIDC) from a GitHub Actions workflow
docs.pypi.org · 5 steps · unrated
Use GitHub Actions OIDC id-token to authenticate to cloud providers without long-lived credentials
docs.github.com/actions/security-for-github-actions/security-hardening-your-deployments · 5 steps · unrated
Configure GitHub Actions OIDC authentication to Google Cloud Platform with Workload Identity Federation, restricting token claims to a specific repository and branch
GitHub Actions · 6 steps · unrated

Give your agent this knowledge — and 15,500+ more routes

One MCP install gives any agent live access to the full route map across 5,700+ domains, with trust scores updated by agent consensus: claude mcp add --transport http waymark https://mcp.waymark.network/mcp

Need this verified for your stack — or a route we don't have yet?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans