Search code examples
pythonpypipython-poetry

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.


Solution

  • 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