Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 1 | :mod:`pprint` --- Data pretty printer |
| 2 | ===================================== |
| 3 | |
| 4 | .. module:: pprint |
| 5 | :synopsis: Data pretty printer. |
Terry Jan Reedy | fa089b9 | 2016-06-11 15:02:54 -0400 | [diff] [blame] | 6 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 7 | .. moduleauthor:: Fred L. Drake, Jr. <fdrake@acm.org> |
| 8 | .. sectionauthor:: Fred L. Drake, Jr. <fdrake@acm.org> |
| 9 | |
Raymond Hettinger | 1048094 | 2011-01-10 03:26:08 +0000 | [diff] [blame] | 10 | **Source code:** :source:`Lib/pprint.py` |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 11 | |
Raymond Hettinger | 4f707fd | 2011-01-10 19:54:11 +0000 | [diff] [blame] | 12 | -------------- |
| 13 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 14 | The :mod:`pprint` module provides a capability to "pretty-print" arbitrary |
| 15 | Python data structures in a form which can be used as input to the interpreter. |
| 16 | If the formatted structures include objects which are not fundamental Python |
| 17 | types, the representation may not be loadable. This may be the case if objects |
Antoine Pitrou | 64c16c3 | 2013-03-23 20:30:39 +0100 | [diff] [blame] | 18 | such as files, sockets or classes are included, as well as many other |
| 19 | objects which are not representable as Python literals. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 20 | |
| 21 | The formatted representation keeps objects on a single line if it can, and |
| 22 | breaks them onto multiple lines if they don't fit within the allowed width. |
| 23 | Construct :class:`PrettyPrinter` objects explicitly if you need to adjust the |
| 24 | width constraint. |
| 25 | |
Georg Brandl | 55ac8f0 | 2007-09-01 13:51:09 +0000 | [diff] [blame] | 26 | Dictionaries are sorted by key before the display is computed. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 27 | |
Carl Bordum Hansen | 06a8916 | 2019-06-27 01:13:18 +0200 | [diff] [blame^] | 28 | .. versionchanged:: 3.9 |
| 29 | Added support for pretty-printing :class:`types.SimpleNamespace`. |
| 30 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 31 | The :mod:`pprint` module defines one class: |
| 32 | |
Christian Heimes | 5b5e81c | 2007-12-31 16:14:33 +0000 | [diff] [blame] | 33 | .. First the implementation class: |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 34 | |
| 35 | |
Serhiy Storchaka | 6c48bf2 | 2018-11-20 19:26:09 +0200 | [diff] [blame] | 36 | .. index:: single: ...; placeholder |
| 37 | |
Serhiy Storchaka | 7c411a4 | 2013-10-02 11:56:18 +0300 | [diff] [blame] | 38 | .. class:: PrettyPrinter(indent=1, width=80, depth=None, stream=None, *, \ |
Rémi Lapeyre | 96831c7 | 2019-03-22 18:22:20 +0100 | [diff] [blame] | 39 | compact=False, sort_dicts=True) |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 40 | |
| 41 | Construct a :class:`PrettyPrinter` instance. This constructor understands |
| 42 | several keyword parameters. An output stream may be set using the *stream* |
| 43 | keyword; the only method used on the stream object is the file protocol's |
| 44 | :meth:`write` method. If not specified, the :class:`PrettyPrinter` adopts |
Serhiy Storchaka | 7c411a4 | 2013-10-02 11:56:18 +0300 | [diff] [blame] | 45 | ``sys.stdout``. The |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 46 | amount of indentation added for each recursive level is specified by *indent*; |
| 47 | the default is one. Other values can cause output to look a little odd, but can |
| 48 | make nesting easier to spot. The number of levels which may be printed is |
| 49 | controlled by *depth*; if the data structure being printed is too deep, the next |
| 50 | contained level is replaced by ``...``. By default, there is no constraint on |
| 51 | the depth of the objects being formatted. The desired output width is |
| 52 | constrained using the *width* parameter; the default is 80 characters. If a |
| 53 | structure cannot be formatted within the constrained width, a best effort will |
Serhiy Storchaka | 7c411a4 | 2013-10-02 11:56:18 +0300 | [diff] [blame] | 54 | be made. If *compact* is false (the default) each item of a long sequence |
| 55 | will be formatted on a separate line. If *compact* is true, as many items |
Rémi Lapeyre | 96831c7 | 2019-03-22 18:22:20 +0100 | [diff] [blame] | 56 | as will fit within the *width* will be formatted on each output line. If |
| 57 | *sort_dicts* is true (the default), dictionaries will be formatted with their |
| 58 | keys sorted, otherwise they will display in insertion order. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 59 | |
Serhiy Storchaka | 09bb846 | 2013-10-02 21:40:21 +0300 | [diff] [blame] | 60 | .. versionchanged:: 3.4 |
| 61 | Added the *compact* parameter. |
| 62 | |
Rémi Lapeyre | 96831c7 | 2019-03-22 18:22:20 +0100 | [diff] [blame] | 63 | .. versionchanged:: 3.8 |
| 64 | Added the *sort_dicts* parameter. |
| 65 | |
| 66 | |
Christian Heimes | b9eccbf | 2007-12-05 20:18:38 +0000 | [diff] [blame] | 67 | >>> import pprint |
| 68 | >>> stuff = ['spam', 'eggs', 'lumberjack', 'knights', 'ni'] |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 69 | >>> stuff.insert(0, stuff[:]) |
| 70 | >>> pp = pprint.PrettyPrinter(indent=4) |
| 71 | >>> pp.pprint(stuff) |
Georg Brandl | 3ccb787 | 2008-07-16 03:00:45 +0000 | [diff] [blame] | 72 | [ ['spam', 'eggs', 'lumberjack', 'knights', 'ni'], |
Christian Heimes | b9eccbf | 2007-12-05 20:18:38 +0000 | [diff] [blame] | 73 | 'spam', |
| 74 | 'eggs', |
| 75 | 'lumberjack', |
| 76 | 'knights', |
| 77 | 'ni'] |
Serhiy Storchaka | 7c411a4 | 2013-10-02 11:56:18 +0300 | [diff] [blame] | 78 | >>> pp = pprint.PrettyPrinter(width=41, compact=True) |
| 79 | >>> pp.pprint(stuff) |
| 80 | [['spam', 'eggs', 'lumberjack', |
| 81 | 'knights', 'ni'], |
| 82 | 'spam', 'eggs', 'lumberjack', 'knights', |
| 83 | 'ni'] |
Christian Heimes | b9eccbf | 2007-12-05 20:18:38 +0000 | [diff] [blame] | 84 | >>> tup = ('spam', ('eggs', ('lumberjack', ('knights', ('ni', ('dead', |
| 85 | ... ('parrot', ('fresh fruit',)))))))) |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 86 | >>> pp = pprint.PrettyPrinter(depth=6) |
| 87 | >>> pp.pprint(tup) |
Alexandre Vassalotti | eca20b6 | 2008-05-16 02:54:33 +0000 | [diff] [blame] | 88 | ('spam', ('eggs', ('lumberjack', ('knights', ('ni', ('dead', (...))))))) |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 89 | |
Georg Brandl | 1824415 | 2009-09-02 20:34:52 +0000 | [diff] [blame] | 90 | |
Antoine Pitrou | 64c16c3 | 2013-03-23 20:30:39 +0100 | [diff] [blame] | 91 | The :mod:`pprint` module also provides several shortcut functions: |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 92 | |
Rémi Lapeyre | 96831c7 | 2019-03-22 18:22:20 +0100 | [diff] [blame] | 93 | .. function:: pformat(object, indent=1, width=80, depth=None, *, \ |
| 94 | compact=False, sort_dicts=True) |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 95 | |
Serhiy Storchaka | 7c411a4 | 2013-10-02 11:56:18 +0300 | [diff] [blame] | 96 | Return the formatted representation of *object* as a string. *indent*, |
Rémi Lapeyre | 96831c7 | 2019-03-22 18:22:20 +0100 | [diff] [blame] | 97 | *width*, *depth*, *compact* and *sort_dicts* will be passed to the |
| 98 | :class:`PrettyPrinter` constructor as formatting parameters. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 99 | |
Serhiy Storchaka | 09bb846 | 2013-10-02 21:40:21 +0300 | [diff] [blame] | 100 | .. versionchanged:: 3.4 |
| 101 | Added the *compact* parameter. |
| 102 | |
Rémi Lapeyre | 96831c7 | 2019-03-22 18:22:20 +0100 | [diff] [blame] | 103 | .. versionchanged:: 3.8 |
| 104 | Added the *sort_dicts* parameter. |
| 105 | |
| 106 | |
| 107 | .. function:: pp(object, *args, sort_dicts=False, **kwargs) |
| 108 | |
| 109 | Prints the formatted representation of *object* followed by a newline. |
| 110 | If *sort_dicts* is false (the default), dictionaries will be displayed with |
| 111 | their keys in insertion order, otherwise the dict keys will be sorted. |
Xavier GUIHOT | 7c822e5 | 2019-03-23 01:17:29 +0000 | [diff] [blame] | 112 | *args* and *kwargs* will be passed to :func:`pprint` as formatting |
Rémi Lapeyre | 96831c7 | 2019-03-22 18:22:20 +0100 | [diff] [blame] | 113 | parameters. |
| 114 | |
| 115 | .. versionadded:: 3.8 |
| 116 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 117 | |
Serhiy Storchaka | 7c411a4 | 2013-10-02 11:56:18 +0300 | [diff] [blame] | 118 | .. function:: pprint(object, stream=None, indent=1, width=80, depth=None, *, \ |
Rémi Lapeyre | 96831c7 | 2019-03-22 18:22:20 +0100 | [diff] [blame] | 119 | compact=False, sort_dicts=True) |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 120 | |
| 121 | Prints the formatted representation of *object* on *stream*, followed by a |
Georg Brandl | 1824415 | 2009-09-02 20:34:52 +0000 | [diff] [blame] | 122 | newline. If *stream* is ``None``, ``sys.stdout`` is used. This may be used |
Georg Brandl | 6911e3c | 2007-09-04 07:15:32 +0000 | [diff] [blame] | 123 | in the interactive interpreter instead of the :func:`print` function for |
| 124 | inspecting values (you can even reassign ``print = pprint.pprint`` for use |
Rémi Lapeyre | 96831c7 | 2019-03-22 18:22:20 +0100 | [diff] [blame] | 125 | within a scope). *indent*, *width*, *depth*, *compact* and *sort_dicts* will |
| 126 | be passed to the :class:`PrettyPrinter` constructor as formatting parameters. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 127 | |
Serhiy Storchaka | 09bb846 | 2013-10-02 21:40:21 +0300 | [diff] [blame] | 128 | .. versionchanged:: 3.4 |
| 129 | Added the *compact* parameter. |
| 130 | |
Rémi Lapeyre | 96831c7 | 2019-03-22 18:22:20 +0100 | [diff] [blame] | 131 | .. versionchanged:: 3.8 |
| 132 | Added the *sort_dicts* parameter. |
| 133 | |
Christian Heimes | b9eccbf | 2007-12-05 20:18:38 +0000 | [diff] [blame] | 134 | >>> import pprint |
| 135 | >>> stuff = ['spam', 'eggs', 'lumberjack', 'knights', 'ni'] |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 136 | >>> stuff.insert(0, stuff) |
| 137 | >>> pprint.pprint(stuff) |
Christian Heimes | fe337bf | 2008-03-23 21:54:12 +0000 | [diff] [blame] | 138 | [<Recursion on list with id=...>, |
| 139 | 'spam', |
| 140 | 'eggs', |
| 141 | 'lumberjack', |
| 142 | 'knights', |
| 143 | 'ni'] |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 144 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 145 | |
| 146 | .. function:: isreadable(object) |
| 147 | |
| 148 | .. index:: builtin: eval |
| 149 | |
| 150 | Determine if the formatted representation of *object* is "readable," or can be |
| 151 | used to reconstruct the value using :func:`eval`. This always returns ``False`` |
Christian Heimes | fe337bf | 2008-03-23 21:54:12 +0000 | [diff] [blame] | 152 | for recursive objects. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 153 | |
| 154 | >>> pprint.isreadable(stuff) |
| 155 | False |
| 156 | |
| 157 | |
| 158 | .. function:: isrecursive(object) |
| 159 | |
| 160 | Determine if *object* requires a recursive representation. |
| 161 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 162 | |
Christian Heimes | fe337bf | 2008-03-23 21:54:12 +0000 | [diff] [blame] | 163 | One more support function is also defined: |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 164 | |
| 165 | .. function:: saferepr(object) |
| 166 | |
| 167 | Return a string representation of *object*, protected against recursive data |
| 168 | structures. If the representation of *object* exposes a recursive entry, the |
| 169 | recursive reference will be represented as ``<Recursion on typename with |
| 170 | id=number>``. The representation is not otherwise formatted. |
| 171 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 172 | >>> pprint.saferepr(stuff) |
Christian Heimes | fe337bf | 2008-03-23 21:54:12 +0000 | [diff] [blame] | 173 | "[<Recursion on list with id=...>, 'spam', 'eggs', 'lumberjack', 'knights', 'ni']" |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 174 | |
| 175 | |
| 176 | .. _prettyprinter-objects: |
| 177 | |
| 178 | PrettyPrinter Objects |
| 179 | --------------------- |
| 180 | |
| 181 | :class:`PrettyPrinter` instances have the following methods: |
| 182 | |
| 183 | |
| 184 | .. method:: PrettyPrinter.pformat(object) |
| 185 | |
| 186 | Return the formatted representation of *object*. This takes into account the |
| 187 | options passed to the :class:`PrettyPrinter` constructor. |
| 188 | |
| 189 | |
| 190 | .. method:: PrettyPrinter.pprint(object) |
| 191 | |
| 192 | Print the formatted representation of *object* on the configured stream, |
| 193 | followed by a newline. |
| 194 | |
| 195 | The following methods provide the implementations for the corresponding |
| 196 | functions of the same names. Using these methods on an instance is slightly |
| 197 | more efficient since new :class:`PrettyPrinter` objects don't need to be |
| 198 | created. |
| 199 | |
| 200 | |
| 201 | .. method:: PrettyPrinter.isreadable(object) |
| 202 | |
| 203 | .. index:: builtin: eval |
| 204 | |
| 205 | Determine if the formatted representation of the object is "readable," or can be |
| 206 | used to reconstruct the value using :func:`eval`. Note that this returns |
| 207 | ``False`` for recursive objects. If the *depth* parameter of the |
| 208 | :class:`PrettyPrinter` is set and the object is deeper than allowed, this |
| 209 | returns ``False``. |
| 210 | |
| 211 | |
| 212 | .. method:: PrettyPrinter.isrecursive(object) |
| 213 | |
| 214 | Determine if the object requires a recursive representation. |
| 215 | |
| 216 | This method is provided as a hook to allow subclasses to modify the way objects |
| 217 | are converted to strings. The default implementation uses the internals of the |
| 218 | :func:`saferepr` implementation. |
| 219 | |
| 220 | |
| 221 | .. method:: PrettyPrinter.format(object, context, maxlevels, level) |
| 222 | |
| 223 | Returns three values: the formatted version of *object* as a string, a flag |
| 224 | indicating whether the result is readable, and a flag indicating whether |
| 225 | recursion was detected. The first argument is the object to be presented. The |
| 226 | second is a dictionary which contains the :func:`id` of objects that are part of |
| 227 | the current presentation context (direct and indirect containers for *object* |
| 228 | that are affecting the presentation) as the keys; if an object needs to be |
| 229 | presented which is already represented in *context*, the third return value |
Martin Panter | d5db147 | 2016-02-08 01:34:09 +0000 | [diff] [blame] | 230 | should be ``True``. Recursive calls to the :meth:`.format` method should add |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 231 | additional entries for containers to this dictionary. The third argument, |
| 232 | *maxlevels*, gives the requested limit to recursion; this will be ``0`` if there |
| 233 | is no requested limit. This argument should be passed unmodified to recursive |
| 234 | calls. The fourth argument, *level*, gives the current level; recursive calls |
| 235 | should be passed a value less than that of the current call. |
Christian Heimes | b9eccbf | 2007-12-05 20:18:38 +0000 | [diff] [blame] | 236 | |
| 237 | |
| 238 | .. _pprint-example: |
| 239 | |
Łukasz Langa | 4ad78ab | 2011-05-14 22:43:44 +0200 | [diff] [blame] | 240 | Example |
| 241 | ------- |
Christian Heimes | b9eccbf | 2007-12-05 20:18:38 +0000 | [diff] [blame] | 242 | |
Łukasz Langa | 4ad78ab | 2011-05-14 22:43:44 +0200 | [diff] [blame] | 243 | To demonstrate several uses of the :func:`pprint` function and its parameters, |
Stéphane Wirtel | 19177fb | 2018-05-15 20:58:35 +0200 | [diff] [blame] | 244 | let's fetch information about a project from `PyPI <https://pypi.org>`_:: |
Christian Heimes | b9eccbf | 2007-12-05 20:18:38 +0000 | [diff] [blame] | 245 | |
Łukasz Langa | 4ad78ab | 2011-05-14 22:43:44 +0200 | [diff] [blame] | 246 | >>> import json |
Christian Heimes | b9eccbf | 2007-12-05 20:18:38 +0000 | [diff] [blame] | 247 | >>> import pprint |
Łukasz Langa | 4ad78ab | 2011-05-14 22:43:44 +0200 | [diff] [blame] | 248 | >>> from urllib.request import urlopen |
Pablo Galindo | bf46a09 | 2018-11-01 08:29:38 -0400 | [diff] [blame] | 249 | >>> with urlopen('https://pypi.org/pypi/sampleproject/json') as resp: |
| 250 | ... project_info = json.load(resp)['info'] |
Christian Heimes | b9eccbf | 2007-12-05 20:18:38 +0000 | [diff] [blame] | 251 | |
Łukasz Langa | 4ad78ab | 2011-05-14 22:43:44 +0200 | [diff] [blame] | 252 | In its basic form, :func:`pprint` shows the whole object:: |
| 253 | |
Antoine Pitrou | 64c16c3 | 2013-03-23 20:30:39 +0100 | [diff] [blame] | 254 | >>> pprint.pprint(project_info) |
Pablo Galindo | bf46a09 | 2018-11-01 08:29:38 -0400 | [diff] [blame] | 255 | {'author': 'The Python Packaging Authority', |
| 256 | 'author_email': 'pypa-dev@googlegroups.com', |
| 257 | 'bugtrack_url': None, |
| 258 | 'classifiers': ['Development Status :: 3 - Alpha', |
| 259 | 'Intended Audience :: Developers', |
| 260 | 'License :: OSI Approved :: MIT License', |
| 261 | 'Programming Language :: Python :: 2', |
| 262 | 'Programming Language :: Python :: 2.6', |
| 263 | 'Programming Language :: Python :: 2.7', |
| 264 | 'Programming Language :: Python :: 3', |
| 265 | 'Programming Language :: Python :: 3.2', |
| 266 | 'Programming Language :: Python :: 3.3', |
| 267 | 'Programming Language :: Python :: 3.4', |
| 268 | 'Topic :: Software Development :: Build Tools'], |
| 269 | 'description': 'A sample Python project\n' |
| 270 | '=======================\n' |
| 271 | '\n' |
| 272 | 'This is the description file for the project.\n' |
| 273 | '\n' |
| 274 | 'The file should use UTF-8 encoding and be written using ' |
| 275 | 'ReStructured Text. It\n' |
| 276 | 'will be used to generate the project webpage on PyPI, and ' |
| 277 | 'should be written for\n' |
| 278 | 'that purpose.\n' |
| 279 | '\n' |
| 280 | 'Typical contents for this file would include an overview of ' |
| 281 | 'the project, basic\n' |
| 282 | 'usage examples, etc. Generally, including the project ' |
| 283 | 'changelog in here is not\n' |
| 284 | 'a good idea, although a simple "What\'s New" section for the ' |
| 285 | 'most recent version\n' |
| 286 | 'may be appropriate.', |
| 287 | 'description_content_type': None, |
| 288 | 'docs_url': None, |
| 289 | 'download_url': 'UNKNOWN', |
| 290 | 'downloads': {'last_day': -1, 'last_month': -1, 'last_week': -1}, |
| 291 | 'home_page': 'https://github.com/pypa/sampleproject', |
| 292 | 'keywords': 'sample setuptools development', |
| 293 | 'license': 'MIT', |
| 294 | 'maintainer': None, |
| 295 | 'maintainer_email': None, |
| 296 | 'name': 'sampleproject', |
| 297 | 'package_url': 'https://pypi.org/project/sampleproject/', |
| 298 | 'platform': 'UNKNOWN', |
| 299 | 'project_url': 'https://pypi.org/project/sampleproject/', |
| 300 | 'project_urls': {'Download': 'UNKNOWN', |
| 301 | 'Homepage': 'https://github.com/pypa/sampleproject'}, |
| 302 | 'release_url': 'https://pypi.org/project/sampleproject/1.2.0/', |
| 303 | 'requires_dist': None, |
| 304 | 'requires_python': None, |
| 305 | 'summary': 'A sample Python project', |
| 306 | 'version': '1.2.0'} |
Łukasz Langa | 4ad78ab | 2011-05-14 22:43:44 +0200 | [diff] [blame] | 307 | |
| 308 | The result can be limited to a certain *depth* (ellipsis is used for deeper |
| 309 | contents):: |
| 310 | |
Pablo Galindo | bf46a09 | 2018-11-01 08:29:38 -0400 | [diff] [blame] | 311 | >>> pprint.pprint(project_info, depth=1) |
| 312 | {'author': 'The Python Packaging Authority', |
| 313 | 'author_email': 'pypa-dev@googlegroups.com', |
| 314 | 'bugtrack_url': None, |
| 315 | 'classifiers': [...], |
| 316 | 'description': 'A sample Python project\n' |
| 317 | '=======================\n' |
| 318 | '\n' |
| 319 | 'This is the description file for the project.\n' |
| 320 | '\n' |
| 321 | 'The file should use UTF-8 encoding and be written using ' |
| 322 | 'ReStructured Text. It\n' |
| 323 | 'will be used to generate the project webpage on PyPI, and ' |
| 324 | 'should be written for\n' |
| 325 | 'that purpose.\n' |
| 326 | '\n' |
| 327 | 'Typical contents for this file would include an overview of ' |
| 328 | 'the project, basic\n' |
| 329 | 'usage examples, etc. Generally, including the project ' |
| 330 | 'changelog in here is not\n' |
| 331 | 'a good idea, although a simple "What\'s New" section for the ' |
| 332 | 'most recent version\n' |
| 333 | 'may be appropriate.', |
| 334 | 'description_content_type': None, |
| 335 | 'docs_url': None, |
| 336 | 'download_url': 'UNKNOWN', |
| 337 | 'downloads': {...}, |
| 338 | 'home_page': 'https://github.com/pypa/sampleproject', |
| 339 | 'keywords': 'sample setuptools development', |
| 340 | 'license': 'MIT', |
| 341 | 'maintainer': None, |
| 342 | 'maintainer_email': None, |
| 343 | 'name': 'sampleproject', |
| 344 | 'package_url': 'https://pypi.org/project/sampleproject/', |
| 345 | 'platform': 'UNKNOWN', |
| 346 | 'project_url': 'https://pypi.org/project/sampleproject/', |
| 347 | 'project_urls': {...}, |
| 348 | 'release_url': 'https://pypi.org/project/sampleproject/1.2.0/', |
| 349 | 'requires_dist': None, |
| 350 | 'requires_python': None, |
| 351 | 'summary': 'A sample Python project', |
| 352 | 'version': '1.2.0'} |
Łukasz Langa | 4ad78ab | 2011-05-14 22:43:44 +0200 | [diff] [blame] | 353 | |
Antoine Pitrou | 64c16c3 | 2013-03-23 20:30:39 +0100 | [diff] [blame] | 354 | Additionally, maximum character *width* can be suggested. If a long object |
| 355 | cannot be split, the specified width will be exceeded:: |
Łukasz Langa | 4ad78ab | 2011-05-14 22:43:44 +0200 | [diff] [blame] | 356 | |
Pablo Galindo | bf46a09 | 2018-11-01 08:29:38 -0400 | [diff] [blame] | 357 | >>> pprint.pprint(project_info, depth=1, width=60) |
| 358 | {'author': 'The Python Packaging Authority', |
| 359 | 'author_email': 'pypa-dev@googlegroups.com', |
| 360 | 'bugtrack_url': None, |
| 361 | 'classifiers': [...], |
| 362 | 'description': 'A sample Python project\n' |
| 363 | '=======================\n' |
| 364 | '\n' |
| 365 | 'This is the description file for the ' |
| 366 | 'project.\n' |
| 367 | '\n' |
| 368 | 'The file should use UTF-8 encoding and be ' |
| 369 | 'written using ReStructured Text. It\n' |
| 370 | 'will be used to generate the project ' |
| 371 | 'webpage on PyPI, and should be written ' |
| 372 | 'for\n' |
| 373 | 'that purpose.\n' |
| 374 | '\n' |
| 375 | 'Typical contents for this file would ' |
| 376 | 'include an overview of the project, ' |
| 377 | 'basic\n' |
| 378 | 'usage examples, etc. Generally, including ' |
| 379 | 'the project changelog in here is not\n' |
| 380 | 'a good idea, although a simple "What\'s ' |
| 381 | 'New" section for the most recent version\n' |
| 382 | 'may be appropriate.', |
| 383 | 'description_content_type': None, |
| 384 | 'docs_url': None, |
| 385 | 'download_url': 'UNKNOWN', |
| 386 | 'downloads': {...}, |
| 387 | 'home_page': 'https://github.com/pypa/sampleproject', |
| 388 | 'keywords': 'sample setuptools development', |
| 389 | 'license': 'MIT', |
| 390 | 'maintainer': None, |
| 391 | 'maintainer_email': None, |
| 392 | 'name': 'sampleproject', |
| 393 | 'package_url': 'https://pypi.org/project/sampleproject/', |
| 394 | 'platform': 'UNKNOWN', |
| 395 | 'project_url': 'https://pypi.org/project/sampleproject/', |
| 396 | 'project_urls': {...}, |
| 397 | 'release_url': 'https://pypi.org/project/sampleproject/1.2.0/', |
| 398 | 'requires_dist': None, |
| 399 | 'requires_python': None, |
| 400 | 'summary': 'A sample Python project', |
| 401 | 'version': '1.2.0'} |