Skip to content

Commit

Permalink
doc: using keyring with API key
Browse files Browse the repository at this point in the history
Show how to use twine+keyring post 2024-01-01.

This is my attempt to prevent anyone else from being bitten by this change:

`auth.py`
```python
    def username(self) -> Optional[str]:
        if cast(str, self.config["repository"]).startswith(
            (utils.DEFAULT_REPOSITORY, utils.TEST_REPOSITORY)
        ):
            # As of 2024-01-01, PyPI requires API tokens for uploads, meaning
            # that the username is invariant.
            return "__token__"
```
  • Loading branch information
bukzor authored Jun 21, 2024
1 parent 6fbf880 commit 88a1e5c
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -192,20 +192,17 @@ require `additional installation steps`_.
Once Twine is installed, use the ``keyring`` program to set a username and
password to use for each repository to which you may upload.

For example, to set a username and password for PyPI:
For example, to set an API token for PyPI:

.. code-block:: bash
keyring set https://upload.pypi.org/legacy/ your-username
keyring set https://upload.pypi.org/legacy/ __token__
and enter the password when prompted.
and paste your API key when prompted.

For a different repository, replace the URL with the relevant repository
URL. For example, for Test PyPI, use ``https://test.pypi.org/legacy/``.

The next time you run ``twine``, it will prompt you for a username, and then
get the appropriate password from Keyring.

.. note::

If you are using Linux in a headless environment (such as on a
Expand Down

0 comments on commit 88a1e5c

Please sign in to comment.