Skip to content

Commit e10c01b

Browse files
author
Jon Wayne Parrott
authored
Add a guide on how to use TestPyPI (pypa#366)
1 parent 91b8d6f commit e10c01b

File tree

2 files changed

+79
-0
lines changed

2 files changed

+79
-0
lines changed

source/guides/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ introduction to packaging, see :doc:`/tutorials/index`.
2121
index-mirrors-and-caches
2222
hosting-your-own-index
2323
migrating-to-pypi-org
24+
using-testpypi

source/guides/using-testpypi.rst

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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

Comments
 (0)