How to Use TestPyPI for a Dry-Run Release Before PyPI
To test a release on TestPyPI, create a separate account at test.pypi.org, build your sdist and wheel as usual, upload them with twine upload --repository testpypi dist/* (or a CI publishing step pointed at TestPyPI), then install the package into a fresh virtual environment from TestPyPI and run a quick import and smoke test. TestPyPI is a separate instance of the Python Package Index meant for exactly this kind of practice. It catches metadata, rendering and packaging mistakes before they reach the real index, where a version number can never be reused.
Why bother with a dry run
PyPI does not let you upload the same filename twice, even if you delete a release. If 1.4.0 goes out with a broken README, missing files or the wrong requires-python, the fix has to be 1.4.1. A dry run on TestPyPI is the cheapest way to see what users will see: the project page, the rendered long description, the classifiers and the files pip actually downloads. It complements, rather than replaces, the local checks in our PyPI release checklist.
Step by step
- Register on TestPyPI. Accounts are separate from PyPI. The Python Packaging Authority notes that the TestPyPI database may be pruned from time to time, so do not rely on it for anything permanent.
- Create an API token or a trusted publisher. Tokens for TestPyPI are created on TestPyPI. If you publish from CI, you can register a trusted publisher there too; our guide to setting up PyPI trusted publishing from CI follows the same steps.
- Pick a throwaway version. Use a pre-release or development version such as
1.4.0rc1or1.4.0.dev3, so that the real1.4.0stays free and you can repeat the dry run. - Build cleanly. Remove old files from
dist/, then build withpython -m build. Runtwine check dist/*to catch long-description rendering problems. - Upload. Twine knows TestPyPI by the name
testpypi:python -m twine upload --repository testpypi dist/* - Install it back into a fresh environment. Use a new virtual environment so nothing from your working copy leaks in, then install and import it.
- Look at the project page. Check the description, links, licence, classifiers and the list of files.
Installing from TestPyPI without getting burned
Your package probably depends on others that are not on TestPyPI, so the usual command adds the real index as a second source:
python -m pip install \
--index-url https://test.pypi.org/simple/ \
--extra-index-url https://pypi.org/simple/ \
your-package==1.4.0rc1
That works, but be aware of one trap. With two indexes, pip treats them as equal and picks the best matching version from either. Anyone can upload to TestPyPI, so a dependency name there could belong to an unrelated or even malicious project. Two habits reduce the risk:
- Pin your own package to the exact version you just uploaded, as above.
- For a pure packaging check, install your package with
--no-depsfrom TestPyPI, then install its dependencies from the real PyPI in a separate command.
Do this only in a throwaway environment, never on a machine that holds credentials you care about.
What a TestPyPI run can and cannot tell you
| It can show | It cannot show |
|---|---|
| Whether the upload is accepted and metadata validates | Whether your code works for every supported Python version |
| How the README renders on the project page | How downstream projects react to an API change |
| Whether the wheel and sdist contain the files you expect | Whether the name is free on the real PyPI |
| Whether pip picks the wheel you intended for a platform | Anything about real download or usage patterns |
| Whether your CI publishing step authenticates correctly | Whether your production publishing credentials are set up |
The last row matters. A green TestPyPI job proves the workflow shape, but the real PyPI needs its own token or trusted publisher. Many release failures on the day come from that gap.
Putting it into CI
A common pattern is a two-stage workflow: every tag that looks like a release candidate publishes to TestPyPI, and only a final tag publishes to PyPI. Keep the two stages in separate jobs with separate permissions, so a mistake in the test stage cannot reach production credentials. After the TestPyPI job, add an install-and-import job in a clean runner. The same idea for npm, packing and installing the tarball locally, is covered in how to test your package tarball before publishing.
Common mistakes
- Reusing a version on TestPyPI and being surprised when the upload is rejected. Bump the pre-release number instead.
- Testing from the project directory, where Python imports your source tree instead of the installed package. The src layout prevents this class of mistake.
- Forgetting the sdist. Some users and tools build from source, so check it too.
- Treating TestPyPI as a staging mirror for users. It is a sandbox, not a distribution channel.
Frequently asked questions
Do I need a separate account for TestPyPI?
Yes. TestPyPI and PyPI are separate services with separate accounts, tokens and trusted publisher settings.
Can I upload the same version to TestPyPI twice?
No. Like PyPI, TestPyPI rejects a file that has already been uploaded. Use a new pre-release or development version for each dry run.
Is it safe to install dependencies from TestPyPI?
Be careful. Anyone can publish there, so pin your package version, prefer installing it with no dependencies, and fetch dependencies from the real PyPI.
For the rest of the release sequence, see post-release checks for the first hour or return to the Learn hub.