[391] | 1 | .. index::
|
---|
| 2 | single: Python Package Index (PyPI)
|
---|
| 3 | single: PyPI; (see Python Package Index (PyPI))
|
---|
| 4 |
|
---|
[2] | 5 | .. _package-index:
|
---|
| 6 |
|
---|
[391] | 7 | *******************************
|
---|
| 8 | The Python Package Index (PyPI)
|
---|
| 9 | *******************************
|
---|
[2] | 10 |
|
---|
[391] | 11 | The `Python Package Index (PyPI)`_ holds :ref:`meta-data <meta-data>`
|
---|
| 12 | describing distributions packaged with distutils, as well as package data like
|
---|
| 13 | distribution files if the package author wishes.
|
---|
[2] | 14 |
|
---|
[391] | 15 | Distutils exposes two commands for submitting package data to PyPI: the
|
---|
| 16 | :ref:`register <package-register>` command for submitting meta-data to PyPI
|
---|
| 17 | and the :ref:`upload <package-upload>` command for submitting distribution
|
---|
| 18 | files. Both commands read configuration data from a special file called the
|
---|
| 19 | :ref:`.pypirc file <pypirc>`. PyPI :ref:`displays a home page
|
---|
| 20 | <package-display>` for each package created from the ``long_description``
|
---|
| 21 | submitted by the :command:`register` command.
|
---|
[2] | 22 |
|
---|
[391] | 23 |
|
---|
| 24 | .. _package-register:
|
---|
| 25 |
|
---|
| 26 | Registering Packages
|
---|
| 27 | ====================
|
---|
| 28 |
|
---|
| 29 | The distutils command :command:`register` is used to submit your distribution's
|
---|
| 30 | meta-data to the index. It is invoked as follows::
|
---|
| 31 |
|
---|
| 32 | python setup.py register
|
---|
| 33 |
|
---|
[2] | 34 | Distutils will respond with the following prompt::
|
---|
| 35 |
|
---|
[391] | 36 | running register
|
---|
| 37 | We need to know who you are, so please choose either:
|
---|
| 38 | 1. use your existing login,
|
---|
| 39 | 2. register as a new user,
|
---|
| 40 | 3. have the server generate a new password for you (and email it to you), or
|
---|
| 41 | 4. quit
|
---|
| 42 | Your selection [default 1]:
|
---|
[2] | 43 |
|
---|
| 44 | Note: if your username and password are saved locally, you will not see this
|
---|
| 45 | menu.
|
---|
| 46 |
|
---|
| 47 | If you have not registered with PyPI, then you will need to do so now. You
|
---|
| 48 | should choose option 2, and enter your details as required. Soon after
|
---|
| 49 | submitting your details, you will receive an email which will be used to confirm
|
---|
| 50 | your registration.
|
---|
| 51 |
|
---|
| 52 | Once you are registered, you may choose option 1 from the menu. You will be
|
---|
| 53 | prompted for your PyPI username and password, and :command:`register` will then
|
---|
| 54 | submit your meta-data to the index.
|
---|
| 55 |
|
---|
| 56 | You may submit any number of versions of your distribution to the index. If you
|
---|
| 57 | alter the meta-data for a particular version, you may submit it again and the
|
---|
| 58 | index will be updated.
|
---|
| 59 |
|
---|
| 60 | PyPI holds a record for each (name, version) combination submitted. The first
|
---|
| 61 | user to submit information for a given name is designated the Owner of that
|
---|
| 62 | name. They may submit changes through the :command:`register` command or through
|
---|
| 63 | the web interface. They may also designate other users as Owners or Maintainers.
|
---|
| 64 | Maintainers may edit the package information, but not designate other Owners or
|
---|
| 65 | Maintainers.
|
---|
| 66 |
|
---|
[391] | 67 | By default PyPI displays only the newest version of a given package. The web
|
---|
| 68 | interface lets one change this default behavior and manually select which
|
---|
| 69 | versions to display and hide.
|
---|
[2] | 70 |
|
---|
| 71 |
|
---|
[391] | 72 | .. _package-upload:
|
---|
| 73 |
|
---|
| 74 | Uploading Packages
|
---|
| 75 | ==================
|
---|
| 76 |
|
---|
| 77 | .. versionadded:: 2.5
|
---|
| 78 |
|
---|
| 79 | The distutils command :command:`upload` pushes the distribution files to PyPI.
|
---|
| 80 |
|
---|
| 81 | The command is invoked immediately after building one or more distribution
|
---|
| 82 | files. For example, the command ::
|
---|
| 83 |
|
---|
| 84 | python setup.py sdist bdist_wininst upload
|
---|
| 85 |
|
---|
| 86 | will cause the source distribution and the Windows installer to be uploaded to
|
---|
| 87 | PyPI. Note that these will be uploaded even if they are built using an earlier
|
---|
| 88 | invocation of :file:`setup.py`, but that only distributions named on the command
|
---|
| 89 | line for the invocation including the :command:`upload` command are uploaded.
|
---|
| 90 |
|
---|
| 91 | The :command:`upload` command uses the username, password, and repository URL
|
---|
| 92 | from the :file:`$HOME/.pypirc` file (see section :ref:`pypirc` for more on this
|
---|
| 93 | file). If a :command:`register` command was previously called in the same command,
|
---|
| 94 | and if the password was entered in the prompt, :command:`upload` will reuse the
|
---|
| 95 | entered password. This is useful if you do not want to store a clear text
|
---|
| 96 | password in the :file:`$HOME/.pypirc` file.
|
---|
| 97 |
|
---|
| 98 | You can specify another PyPI server with the ``--repository=url`` option::
|
---|
| 99 |
|
---|
| 100 | python setup.py sdist bdist_wininst upload -r http://example.com/pypi
|
---|
| 101 |
|
---|
| 102 | See section :ref:`pypirc` for more on defining several servers.
|
---|
| 103 |
|
---|
| 104 | You can use the ``--sign`` option to tell :command:`upload` to sign each
|
---|
| 105 | uploaded file using GPG (GNU Privacy Guard). The :program:`gpg` program must
|
---|
| 106 | be available for execution on the system :envvar:`PATH`. You can also specify
|
---|
| 107 | which key to use for signing using the ``--identity=name`` option.
|
---|
| 108 |
|
---|
| 109 | Other :command:`upload` options include ``--repository=url`` or
|
---|
| 110 | ``--repository=section`` where *url* is the url of the server and
|
---|
| 111 | *section* the name of the section in :file:`$HOME/.pypirc`, and
|
---|
| 112 | ``--show-response`` (which displays the full response text from the PyPI
|
---|
| 113 | server for help in debugging upload problems).
|
---|
| 114 |
|
---|
| 115 |
|
---|
| 116 | .. index::
|
---|
| 117 | single: .pypirc file
|
---|
| 118 | single: Python Package Index (PyPI); .pypirc file
|
---|
| 119 |
|
---|
[2] | 120 | .. _pypirc:
|
---|
| 121 |
|
---|
| 122 | The .pypirc file
|
---|
| 123 | ================
|
---|
| 124 |
|
---|
| 125 | The format of the :file:`.pypirc` file is as follows::
|
---|
| 126 |
|
---|
[391] | 127 | [distutils]
|
---|
| 128 | index-servers =
|
---|
| 129 | pypi
|
---|
[2] | 130 |
|
---|
[391] | 131 | [pypi]
|
---|
| 132 | repository: <repository-url>
|
---|
| 133 | username: <username>
|
---|
| 134 | password: <password>
|
---|
[2] | 135 |
|
---|
[391] | 136 | The *distutils* section defines a *index-servers* variable that lists the
|
---|
| 137 | name of all sections describing a repository.
|
---|
[2] | 138 |
|
---|
[391] | 139 | Each section describing a repository defines three variables:
|
---|
[2] | 140 |
|
---|
[391] | 141 | - *repository*, that defines the url of the PyPI server. Defaults to
|
---|
| 142 | ``http://www.python.org/pypi``.
|
---|
| 143 | - *username*, which is the registered username on the PyPI server.
|
---|
| 144 | - *password*, that will be used to authenticate. If omitted the user
|
---|
| 145 | will be prompt to type it when needed.
|
---|
[2] | 146 |
|
---|
[391] | 147 | If you want to define another server a new section can be created and
|
---|
| 148 | listed in the *index-servers* variable::
|
---|
[2] | 149 |
|
---|
[391] | 150 | [distutils]
|
---|
| 151 | index-servers =
|
---|
| 152 | pypi
|
---|
| 153 | other
|
---|
[2] | 154 |
|
---|
[391] | 155 | [pypi]
|
---|
| 156 | repository: <repository-url>
|
---|
| 157 | username: <username>
|
---|
| 158 | password: <password>
|
---|
[2] | 159 |
|
---|
[391] | 160 | [other]
|
---|
| 161 | repository: http://example.com/pypi
|
---|
| 162 | username: <username>
|
---|
| 163 | password: <password>
|
---|
[2] | 164 |
|
---|
[391] | 165 | :command:`register` can then be called with the -r option to point the
|
---|
| 166 | repository to work with::
|
---|
[2] | 167 |
|
---|
[391] | 168 | python setup.py register -r http://example.com/pypi
|
---|
[2] | 169 |
|
---|
[391] | 170 | For convenience, the name of the section that describes the repository
|
---|
| 171 | may also be used::
|
---|
| 172 |
|
---|
| 173 | python setup.py register -r other
|
---|
| 174 |
|
---|
| 175 |
|
---|
| 176 | .. _package-display:
|
---|
| 177 |
|
---|
| 178 | PyPI package display
|
---|
| 179 | ====================
|
---|
| 180 |
|
---|
| 181 | The ``long_description`` field plays a special role at PyPI. It is used by
|
---|
| 182 | the server to display a home page for the registered package.
|
---|
| 183 |
|
---|
| 184 | If you use the `reStructuredText <http://docutils.sourceforge.net/rst.html>`_
|
---|
| 185 | syntax for this field, PyPI will parse it and display an HTML output for
|
---|
| 186 | the package home page.
|
---|
| 187 |
|
---|
| 188 | The ``long_description`` field can be attached to a text file located
|
---|
| 189 | in the package::
|
---|
| 190 |
|
---|
| 191 | from distutils.core import setup
|
---|
| 192 |
|
---|
| 193 | with open('README.txt') as file:
|
---|
| 194 | long_description = file.read()
|
---|
| 195 |
|
---|
| 196 | setup(name='Distutils',
|
---|
| 197 | long_description=long_description)
|
---|
| 198 |
|
---|
| 199 | In that case, :file:`README.txt` is a regular reStructuredText text file located
|
---|
| 200 | in the root of the package besides :file:`setup.py`.
|
---|
| 201 |
|
---|
| 202 | To prevent registering broken reStructuredText content, you can use the
|
---|
| 203 | :program:`rst2html` program that is provided by the :mod:`docutils` package and
|
---|
| 204 | check the ``long_description`` from the command line::
|
---|
| 205 |
|
---|
| 206 | $ python setup.py --long-description | rst2html.py > output.html
|
---|
| 207 |
|
---|
| 208 | :mod:`docutils` will display a warning if there's something wrong with your
|
---|
| 209 | syntax. Because PyPI applies additional checks (e.g. by passing ``--no-raw``
|
---|
| 210 | to ``rst2html.py`` in the command above), being able to run the command above
|
---|
| 211 | without warnings does not guarantee that PyPI will convert the content
|
---|
| 212 | successfully.
|
---|
| 213 |
|
---|
| 214 |
|
---|
| 215 | .. _Python Package Index (PyPI): http://pypi.python.org/
|
---|