Leon Webster
Leon Webster

Reputation: 253

using python-poetry to publish to test.pypi.org

I have been investigating the use of Poetry to publish Python projects. I wanted to test the publishing process using a trivial project similar to the Python Packaging Authority tutorial. Since this is a trivial project, I want to publish it to the test instance of pypi rather than the real instance. Test.pypi requires a token to publish, but I can't figure out how to make Poetry use my test pypi token. All the documentation I can find uses HTTP basic authentication for test-pypi which no longer works.

I added the repository using this command:

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

I have tried creating tokens using both the following commands:

poetry config pypi-token.test-pypi my-token
poetry config test-pypi-token.test-pypi my-token

I don't find a good explanation of the syntax for adding tokens in the poetry documentation, so any help will be appreciated.

Upvotes: 25

Views: 8091

Answers (2)

Jos Verlinde
Jos Verlinde

Reputation: 1697

One time setup ( per host / environment)

PYPI test

  • add repository to poetry config
    poetry config repositories.test-pypi https://test.pypi.org/legacy/

  • get token from https://test.pypi.org/manage/account/token/

  • store token using poetry config pypi-token.test-pypi pypi-YYYYYYYY

Note: 'test-pypi' is the name of the 'repository' aka 'index' to publish to.

PYPI Production

Each time you need to publish

Bump version

  • poetry version prerelease or
  • poetry version patch

Poetry Publish

To TestPyPi

  • poetry publish -r test-pypi

To PyPi

  • poetry publish

Upvotes: 33

Tomas Beuzen
Tomas Beuzen

Reputation: 386

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/:

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

You can then create your token as you were doing previously:

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

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

Upvotes: 37

Related Questions