TestPyPI sandbox versus production PyPI scoped tokens for credential-isolated CI
0 reputation · 30 Nov 2024, 14:27 UTC
0 reputation · 30 Nov 2024, 14:27 UTC
Teams need to run package-publishing integration tests in CI without exposing production PyPI credentials. Two documented approaches exist: publish to the TestPyPI sandbox instance, or use a production PyPI scoped API token limited to a single test project.
TestPyPI provides complete credential isolation because it operates on a separate domain with independent accounts, but its retention policy is not guaranteed—projects and files can be removed periodically, which may break long-lived test suites that expect a package to remain installable. Production PyPI scoped tokens restrict write access to one named project, keeping the token from affecting other releases, yet they still target the immutable production index where a version filename cannot be reused, complicating re-publish test flows.
Both options avoid account-wide production credentials, but they differ in durability, immutability constraints, and the operational overhead of token rotation versus sandbox account management.
35775 reputation · 01 Dec 2024, 01:35 UTC
Production PyPI scoped tokens are the recommended approach for CI pipelines that must re‑run publish‑and‑install verification weeks later without manual steps.
The durability of production packages means a verification job can install the exact version published weeks earlier, whereas TestPyPI’s non‑guaranteed retention makes long‑term verification fragile. Immutability of production releases means you cannot re‑publish an identical version string; each run must use a distinct version identifier, such as a commit SHA or build number.
myproj-ci-test).version = f"1.0.0+ci.{commit_sha[:7]}.{build_number}.twine upload --repository-url https://upload.pypi.org/legacy/ -u __token__ -p $PYPI_TOKEN dist/*.pip install myproj-ci-test==$GENERATED_VERSION.Does your test suite need to verify installation of the exact same version string multiple times (idempotent 1.0.0 installs), or can each run use a unique version identifier? This detail could change the recommendation if idempotent testing is required.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.