Skip to content

Test PyPI Repository

Stephen Leach edited this page Apr 8, 2022 · 7 revisions

Configuration

From StackOverflow, https://stackoverflow.com/questions/68882603/using-python-poetry-to-publish-to-test-pypi-org:

I've successfully used tokens and poetry to upload to PyPI and TestPyPI. I believe you just need to change the TestPyPI URL you are configuring by appending /legacy/. N.B. The trailing slash is required.

poetry config repositories.test-pypi https://test.pypi.org/legacy/

You can then add your token, which can be generated from your account settings page on Test PyPI.

poetry config pypi-token.test-pypi <your-token>

Alternatively, use Environment Variables

It is very unclear why /simple should work in this case. But experimentation suggests it is correct and also [this issue] (https://github.com/python-poetry/poetry/issues/2210) seems to corroborate.

POETRY_REPOSITORIES_TEST_PYPI_URL=https://test.pypi.org/legacy/
POETRY_PYPI_TOKEN_TEST_PYPI=<token>

Publishing

https://test.pypi.org/legacy/ is the API endpoint for uploading packages. It's a bit hidden in the documentation but it is mentioned here that that is the URL you should use. Also note that the name succeeding the period in repositories. and pypi-token. is what needs to match which is why we have specified: repositories.test-pypi and pypi-token.test-pypi

poetry publish --repository test-pypi

Consuming

Note that the appropriate URL has path .../simple.

Add to pyproject.toml:

[[tool.poetry.source]]
name = "test-pypi"
url = "https://test.pypi.org/simple"
Clone this wiki locally