|
| 1 | +============== |
| 2 | +Using TestPyPI |
| 3 | +============== |
| 4 | + |
| 5 | +`TestPyPI` is a separate instance of the :term:`Python Package Index (PyPI)` |
| 6 | +that allows you to try out the distribution tools and process without worrying |
| 7 | +about affecting the real index. TestPyPI is hosted at |
| 8 | +`test.pypi.org <https://test.pypi.org>`_ |
| 9 | + |
| 10 | +Registering your account |
| 11 | +------------------------ |
| 12 | + |
| 13 | +Because TestPyPI has a separate database from the live PyPI, you'll need a |
| 14 | +separate user account for specifically for TestPyPI. Go to |
| 15 | +https://test.pypi.org/account/register/ to register your account. |
| 16 | + |
| 17 | +.. Note:: The database for TestPyPI may be periodically pruned, so it is not |
| 18 | + unusual for user accounts to be deleted. |
| 19 | + |
| 20 | + |
| 21 | +Using TestPyPI with Twine |
| 22 | +------------------------- |
| 23 | + |
| 24 | +You can upload your distributions to TestPyPI using :ref:`twine` by passing |
| 25 | +in the ``--repository-url`` flag |
| 26 | + |
| 27 | +.. code:: |
| 28 | +
|
| 29 | + $ twine upload --repository-url https://test.pypi.org/legacy/ dist/* |
| 30 | +
|
| 31 | +Using TestPyPI with pip |
| 32 | +----------------------- |
| 33 | + |
| 34 | +You can tell pip to download packages from TestPyPI instead of PyPI by |
| 35 | +specifying the ``--index-url`` flag |
| 36 | + |
| 37 | +.. code:: |
| 38 | +
|
| 39 | + $ pip install --index-url https://test.pypi.org/simple/ your-package |
| 40 | +
|
| 41 | +If you want to allow pip to also pull other packages from PyPI you can |
| 42 | +specify ``--extra-index-url`` to point to PyPI. This useful when the package |
| 43 | +you're testing has dependencies: |
| 44 | + |
| 45 | +.. code:: |
| 46 | +
|
| 47 | + pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple your-package |
| 48 | +
|
| 49 | +Setting up TestPyPI in pypirc |
| 50 | +----------------------------- |
| 51 | + |
| 52 | +If you want to avoid entering the TestPyPI url and your username and password |
| 53 | +you can configure TestPyPI in your ``~/.pypirc``. |
| 54 | + |
| 55 | +Create or modify ``~/.pypirc`` with the following: |
| 56 | + |
| 57 | +.. code:: |
| 58 | +
|
| 59 | + [distutils] |
| 60 | + index-servers= |
| 61 | + pypi |
| 62 | + testpypi |
| 63 | +
|
| 64 | + [testpypi] |
| 65 | + repository: https://test.pypi.org/legacy/ |
| 66 | + username: your testpypi username |
| 67 | + password: your testpypi password |
| 68 | +
|
| 69 | +
|
| 70 | +.. Warning:: This stores your password in plaintext. It's recommended to set |
| 71 | + narrow permissions on this file. |
| 72 | + |
| 73 | +You can then tell :ref:`twine` to upload to TestPyPI by specifying the |
| 74 | +``--repository`` flag: |
| 75 | + |
| 76 | +.. code:: |
| 77 | +
|
| 78 | + $ twine upload --repository testpypi dist/* |
0 commit comments