|
| 1 | +Making a PyPI-friendly README |
| 2 | +============================= |
| 3 | + |
| 4 | +README files can help your users understand your project and can be used to set your project's description on PyPI. |
| 5 | +This guide helps you create a README in a PyPI-friendly format and include your README in your package so it appears on PyPI. |
| 6 | + |
| 7 | + |
| 8 | +Creating a README file |
| 9 | +---------------------- |
| 10 | + |
| 11 | +README files for Python projects are often named ``README``, ``README.txt``, ``README.rst``, or ``README.md``. |
| 12 | + |
| 13 | +For your README to display properly on PyPI, choose a markup language supported by PyPI. |
| 14 | +Formats supported by `PyPI's README renderer <https://github.com/pypa/readme_renderer>`_ are: |
| 15 | + |
| 16 | +* plain text |
| 17 | +* `reStructuredText <http://docutils.sourceforge.net/rst.html>`_ |
| 18 | +* Markdown (`GitHub Flavored Markdown <https://github.github.com/gfm/>`_ by default, |
| 19 | + or `CommonMark <http://commonmark.org/>`_) |
| 20 | + |
| 21 | +It's customary to save your README file in the root of your project, in the same directory as your :file:`setup.py` file. |
| 22 | + |
| 23 | + |
| 24 | +Including your README in your package's metadata |
| 25 | +------------------------------------------------ |
| 26 | + |
| 27 | +To include your README's contents as your package description, |
| 28 | +set your project's ``Description`` and ``Description-Content-Type`` metadata, |
| 29 | +typically in your project's :file:`setup.py` file. |
| 30 | + |
| 31 | +.. seealso:: |
| 32 | + |
| 33 | + * :any:`metadata_description` |
| 34 | + * :any:`metadata_description_content_type` |
| 35 | + |
| 36 | +For example, to set these values in a package's :file:`setup.py` file, |
| 37 | +use ``setup()``'s ``long_description`` and ``long_description_content_type``. |
| 38 | + |
| 39 | +Set the value of ``long_description`` to the contents (not the path) of the README file itself. |
| 40 | +Set the ``long_description_content_type`` to an accepted ``Content-Type``-style value for your README file's markup, |
| 41 | +such as ``text/plain``, ``text/x-rst`` (for reStructuredText), or ``text/markdown``. |
| 42 | + |
| 43 | +For example, see this :file:`setup.py` file, |
| 44 | +which reads the contents of :file:`README.md` as ``long_description`` |
| 45 | +and identifies the markup as GitHub-flavored Markdown: |
| 46 | + |
| 47 | +.. code-block:: python |
| 48 | +
|
| 49 | + from setuptools import setup |
| 50 | +
|
| 51 | + # read the contents of your README file |
| 52 | + from os import path |
| 53 | + this_directory = path.abspath(path.dirname(__file__)) |
| 54 | + with open(path.join(this_directory, 'README.md'), encoding='utf-8') as f: |
| 55 | + long_description = f.read() |
| 56 | +
|
| 57 | + setup( |
| 58 | + name='an_example_package', |
| 59 | + # other arguments omitted |
| 60 | + long_description=long_description, |
| 61 | + long_description_content_type='text/markdown' |
| 62 | + ) |
0 commit comments