blob: daf93452648718aa27abda4b86e9ac417b87b23d [file] [log] [blame]
Chris Jerdonek13fb9792013-02-27 10:00:20 -08001.. index::
2 single: Python Package Index (PyPI)
3 single: PyPI; (see Python Package Index (PyPI))
4
Georg Brandl116aa622007-08-15 14:28:22 +00005.. _package-index:
6
Chris Jerdonek13fb9792013-02-27 10:00:20 -08007*******************************
8The Python Package Index (PyPI)
9*******************************
Georg Brandl116aa622007-08-15 14:28:22 +000010
R David Murray2ac7a892014-10-12 13:14:12 -040011The `Python Package Index (PyPI)`_ stores :ref:`meta-data <meta-data>`
Chris Jerdonek13fb9792013-02-27 10:00:20 -080012describing distributions packaged with distutils, as well as package data like
R David Murray2ac7a892014-10-12 13:14:12 -040013distribution files if a package author wishes.
14
15Distutils provides the :command:`register` and :command:`upload` commands for
16pushing meta-data and distribution files to PyPI, respectively. See
17:ref:`package-commands` for information on these commands.
18
19
20PyPI overview
21=============
22
23PyPI lets you submit any number of versions of your distribution to the index.
24If you alter the meta-data for a particular version, you can submit it again
25and the index will be updated.
26
27PyPI holds a record for each (name, version) combination submitted. The first
28user to submit information for a given name is designated the Owner of that
29name. Changes can be submitted through the :command:`register` command or
30through the web interface. Owners can designate other users as Owners or
31Maintainers. Maintainers can edit the package information, but not designate
32new Owners or Maintainers.
33
34By default PyPI displays only the newest version of a given package. The web
35interface lets one change this default behavior and manually select which
36versions to display and hide.
37
38For each version, PyPI displays a home page. The home page is created from
39the ``long_description`` which can be submitted via the :command:`register`
40command. See :ref:`package-display` for more information.
41
42
43.. _package-commands:
44
45Distutils commands
46==================
Chris Jerdonek13fb9792013-02-27 10:00:20 -080047
48Distutils exposes two commands for submitting package data to PyPI: the
49:ref:`register <package-register>` command for submitting meta-data to PyPI
50and the :ref:`upload <package-upload>` command for submitting distribution
R David Murray2ac7a892014-10-12 13:14:12 -040051files. Both commands read configuration data from a special file called a
52:ref:`.pypirc file <pypirc>`.
Chris Jerdonek13fb9792013-02-27 10:00:20 -080053
54
55.. _package-register:
56
R David Murray2ac7a892014-10-12 13:14:12 -040057The ``register`` command
58------------------------
Chris Jerdonek13fb9792013-02-27 10:00:20 -080059
60The distutils command :command:`register` is used to submit your distribution's
R David Murray2ac7a892014-10-12 13:14:12 -040061meta-data to an index server. It is invoked as follows::
Georg Brandl116aa622007-08-15 14:28:22 +000062
Tarek Ziadé13f7c3b2009-01-09 00:15:45 +000063 python setup.py register
Georg Brandl116aa622007-08-15 14:28:22 +000064
65Distutils will respond with the following prompt::
66
Tarek Ziadé13f7c3b2009-01-09 00:15:45 +000067 running register
68 We need to know who you are, so please choose either:
69 1. use your existing login,
70 2. register as a new user,
71 3. have the server generate a new password for you (and email it to you), or
72 4. quit
73 Your selection [default 1]:
Georg Brandl116aa622007-08-15 14:28:22 +000074
75Note: if your username and password are saved locally, you will not see this
R David Murray2ac7a892014-10-12 13:14:12 -040076menu. Also, refer to :ref:`pypirc` for how to store your credentials in a
77:file:`.pypirc` file.
Georg Brandl116aa622007-08-15 14:28:22 +000078
79If you have not registered with PyPI, then you will need to do so now. You
80should choose option 2, and enter your details as required. Soon after
81submitting your details, you will receive an email which will be used to confirm
82your registration.
83
84Once you are registered, you may choose option 1 from the menu. You will be
85prompted for your PyPI username and password, and :command:`register` will then
86submit your meta-data to the index.
87
R David Murray2ac7a892014-10-12 13:14:12 -040088See :ref:`package-cmdoptions` for options to the :command:`register` command.
Georg Brandl116aa622007-08-15 14:28:22 +000089
90
Chris Jerdonek13fb9792013-02-27 10:00:20 -080091.. _package-upload:
92
R David Murray2ac7a892014-10-12 13:14:12 -040093The ``upload`` command
94----------------------
Chris Jerdonek13fb9792013-02-27 10:00:20 -080095
96The distutils command :command:`upload` pushes the distribution files to PyPI.
97
98The command is invoked immediately after building one or more distribution
99files. For example, the command ::
100
101 python setup.py sdist bdist_wininst upload
102
103will cause the source distribution and the Windows installer to be uploaded to
104PyPI. Note that these will be uploaded even if they are built using an earlier
105invocation of :file:`setup.py`, but that only distributions named on the command
106line for the invocation including the :command:`upload` command are uploaded.
107
R David Murray2ac7a892014-10-12 13:14:12 -0400108If a :command:`register` command was previously called in the same command,
Chris Jerdonek13fb9792013-02-27 10:00:20 -0800109and if the password was entered in the prompt, :command:`upload` will reuse the
R David Murray2ac7a892014-10-12 13:14:12 -0400110entered password. This is useful if you do not want to store a password in
111clear text in a :file:`.pypirc` file.
Chris Jerdonek13fb9792013-02-27 10:00:20 -0800112
113You can use the ``--sign`` option to tell :command:`upload` to sign each
114uploaded file using GPG (GNU Privacy Guard). The :program:`gpg` program must
115be available for execution on the system :envvar:`PATH`. You can also specify
116which key to use for signing using the ``--identity=name`` option.
117
R David Murray2ac7a892014-10-12 13:14:12 -0400118See :ref:`package-cmdoptions` for additional options to the :command:`upload`
119command.
120
121
122.. _package-cmdoptions:
123
124Additional command options
125--------------------------
126
127This section describes options common to both the :command:`register` and
128:command:`upload` commands.
129
130The ``--repository`` or ``-r`` option lets you specify a PyPI server
131different from the default. For example::
132
133 python setup.py sdist bdist_wininst upload -r https://example.com/pypi
134
135For convenience, a name can be used in place of the URL when the
136:file:`.pypirc` file is configured to do so. For example::
137
138 python setup.py register -r other
139
140See :ref:`pypirc` for more information on defining alternate servers.
141
142The ``--show-response`` option displays the full response text from the PyPI
143server, which is useful when debugging problems with registering and uploading.
Chris Jerdonek13fb9792013-02-27 10:00:20 -0800144
145
146.. index::
147 single: .pypirc file
148 single: Python Package Index (PyPI); .pypirc file
149
Georg Brandl116aa622007-08-15 14:28:22 +0000150.. _pypirc:
151
R David Murray2ac7a892014-10-12 13:14:12 -0400152The ``.pypirc`` file
153--------------------
Georg Brandl116aa622007-08-15 14:28:22 +0000154
R David Murray2ac7a892014-10-12 13:14:12 -0400155The :command:`register` and :command:`upload` commands both check for the
156existence of a :file:`.pypirc` file at the location :file:`$HOME/.pypirc`.
157If this file exists, the command uses the username, password, and repository
158URL configured in the file. The format of a :file:`.pypirc` file is as
159follows::
Georg Brandl116aa622007-08-15 14:28:22 +0000160
Tarek Ziadé13f7c3b2009-01-09 00:15:45 +0000161 [distutils]
162 index-servers =
163 pypi
Alexandre Vassalotti5f8ced22008-05-16 00:03:33 +0000164
Tarek Ziadé13f7c3b2009-01-09 00:15:45 +0000165 [pypi]
166 repository: <repository-url>
167 username: <username>
168 password: <password>
Georg Brandl116aa622007-08-15 14:28:22 +0000169
Tarek Ziadé13f7c3b2009-01-09 00:15:45 +0000170The *distutils* section defines a *index-servers* variable that lists the
171name of all sections describing a repository.
Georg Brandl116aa622007-08-15 14:28:22 +0000172
Tarek Ziadé13f7c3b2009-01-09 00:15:45 +0000173Each section describing a repository defines three variables:
Georg Brandl116aa622007-08-15 14:28:22 +0000174
Tarek Ziadé13f7c3b2009-01-09 00:15:45 +0000175- *repository*, that defines the url of the PyPI server. Defaults to
R David Murray2ac7a892014-10-12 13:14:12 -0400176 ``https://www.python.org/pypi``.
Tarek Ziadé13f7c3b2009-01-09 00:15:45 +0000177- *username*, which is the registered username on the PyPI server.
178- *password*, that will be used to authenticate. If omitted the user
179 will be prompt to type it when needed.
Georg Brandl48310cd2009-01-03 21:18:54 +0000180
Tarek Ziadé13f7c3b2009-01-09 00:15:45 +0000181If you want to define another server a new section can be created and
182listed in the *index-servers* variable::
Alexandre Vassalotti5f8ced22008-05-16 00:03:33 +0000183
Tarek Ziadé13f7c3b2009-01-09 00:15:45 +0000184 [distutils]
185 index-servers =
186 pypi
187 other
Alexandre Vassalotti5f8ced22008-05-16 00:03:33 +0000188
Tarek Ziadé13f7c3b2009-01-09 00:15:45 +0000189 [pypi]
190 repository: <repository-url>
191 username: <username>
192 password: <password>
Alexandre Vassalotti5f8ced22008-05-16 00:03:33 +0000193
Tarek Ziadé13f7c3b2009-01-09 00:15:45 +0000194 [other]
R David Murray2ac7a892014-10-12 13:14:12 -0400195 repository: https://example.com/pypi
Tarek Ziadé13f7c3b2009-01-09 00:15:45 +0000196 username: <username>
197 password: <password>
Alexandre Vassalotti5f8ced22008-05-16 00:03:33 +0000198
R David Murray2ac7a892014-10-12 13:14:12 -0400199This allows the :command:`register` and :command:`upload` commands to be
200called with the ``--repository`` option as described in
201:ref:`package-cmdoptions`.
Alexandre Vassalotti5f8ced22008-05-16 00:03:33 +0000202
R David Murray2ac7a892014-10-12 13:14:12 -0400203Specifically, you might want to add the `PyPI Test Repository
204<https://wiki.python.org/moin/TestPyPI>`_ to your ``.pypirc`` to facilitate
205testing before doing your first upload to ``PyPI`` itself.
Chris Jerdonek13fb9792013-02-27 10:00:20 -0800206
207
208.. _package-display:
209
210PyPI package display
211====================
212
213The ``long_description`` field plays a special role at PyPI. It is used by
214the server to display a home page for the registered package.
215
216If you use the `reStructuredText <http://docutils.sourceforge.net/rst.html>`_
217syntax for this field, PyPI will parse it and display an HTML output for
218the package home page.
219
220The ``long_description`` field can be attached to a text file located
221in the package::
222
223 from distutils.core import setup
224
225 with open('README.txt') as file:
226 long_description = file.read()
227
228 setup(name='Distutils',
229 long_description=long_description)
230
231In that case, :file:`README.txt` is a regular reStructuredText text file located
232in the root of the package besides :file:`setup.py`.
233
234To prevent registering broken reStructuredText content, you can use the
235:program:`rst2html` program that is provided by the :mod:`docutils` package and
236check the ``long_description`` from the command line::
237
238 $ python setup.py --long-description | rst2html.py > output.html
239
240:mod:`docutils` will display a warning if there's something wrong with your
241syntax. Because PyPI applies additional checks (e.g. by passing ``--no-raw``
242to ``rst2html.py`` in the command above), being able to run the command above
243without warnings does not guarantee that PyPI will convert the content
244successfully.
245
246
Georg Brandl77fe77d2014-10-29 09:24:54 +0100247.. _Python Package Index (PyPI): https://pypi.python.org/pypi