@@ -217,135 +217,156 @@ let's fetch information about a project from `PyPI <https://pypi.org>`_::
217
217
>>> import json
218
218
>>> import pprint
219
219
>>> from urllib.request import urlopen
220
- >>> with urlopen('http://pypi.org/project/Twisted/json') as url:
221
- ... http_info = url.info()
222
- ... raw_data = url.read().decode(http_info.get_content_charset())
223
- >>> project_info = json.loads(raw_data)
220
+ >>> with urlopen('https://pypi.org/pypi/sampleproject/json') as resp:
221
+ ... project_info = json.load(resp)['info']
224
222
225
223
In its basic form, :func: `pprint ` shows the whole object::
226
224
227
225
>>> pprint.pprint(project_info)
228
- {'info': {'_pypi_hidden': False,
229
- '_pypi_ordering': 125,
230
- 'author': 'Glyph Lefkowitz',
231
- 'author_email': '[email protected] ',
232
- 'bugtrack_url': '',
233
- 'cheesecake_code_kwalitee_id': None,
234
- 'cheesecake_documentation_id': None,
235
- 'cheesecake_installability_id': None,
236
- 'classifiers': ['Programming Language :: Python :: 2.6',
237
- 'Programming Language :: Python :: 2.7',
238
- 'Programming Language :: Python :: 2 :: Only'],
239
- 'description': 'An extensible framework for Python programming, with '
240
- 'special focus\r\n'
241
- 'on event-based network programming and multiprotocol '
242
- 'integration.',
243
- 'docs_url': '',
244
- 'download_url': 'UNKNOWN',
245
- 'home_page': 'http://twistedmatrix.com/',
246
- 'keywords': '',
247
- 'license': 'MIT',
248
- 'maintainer': '',
249
- 'maintainer_email': '',
250
- 'name': 'Twisted',
251
- 'package_url': 'http://pypi.org/project/Twisted',
252
- 'platform': 'UNKNOWN',
253
- 'release_url': 'http://pypi.org/project/Twisted/12.3.0',
254
- 'requires_python': None,
255
- 'stable_version': None,
256
- 'summary': 'An asynchronous networking framework written in Python',
257
- 'version': '12.3.0'},
258
- 'urls': [{'comment_text': '',
259
- 'downloads': 71844,
260
- 'filename': 'Twisted-12.3.0.tar.bz2',
261
- 'has_sig': False,
262
- 'md5_digest': '6e289825f3bf5591cfd670874cc0862d',
263
- 'packagetype': 'sdist',
264
- 'python_version': 'source',
265
- 'size': 2615733,
266
- 'upload_time': '2012-12-26T12:47:03',
267
- 'url': 'https://pypi.org/packages/source/T/Twisted/Twisted-12.3.0.tar.bz2'},
268
- {'comment_text': '',
269
- 'downloads': 5224,
270
- 'filename': 'Twisted-12.3.0.win32-py2.7.msi',
271
- 'has_sig': False,
272
- 'md5_digest': '6b778f5201b622a5519a2aca1a2fe512',
273
- 'packagetype': 'bdist_msi',
274
- 'python_version': '2.7',
275
- 'size': 2916352,
276
- 'upload_time': '2012-12-26T12:48:15',
277
- 'url': 'https://pypi.org/packages/2.7/T/Twisted/Twisted-12.3.0.win32-py2.7.msi'}]}
226
+ {'author': 'The Python Packaging Authority',
227
+ 'author_email': '[email protected] ',
228
+ 'bugtrack_url': None,
229
+ 'classifiers': ['Development Status :: 3 - Alpha',
230
+ 'Intended Audience :: Developers',
231
+ 'License :: OSI Approved :: MIT License',
232
+ 'Programming Language :: Python :: 2',
233
+ 'Programming Language :: Python :: 2.6',
234
+ 'Programming Language :: Python :: 2.7',
235
+ 'Programming Language :: Python :: 3',
236
+ 'Programming Language :: Python :: 3.2',
237
+ 'Programming Language :: Python :: 3.3',
238
+ 'Programming Language :: Python :: 3.4',
239
+ 'Topic :: Software Development :: Build Tools'],
240
+ 'description': 'A sample Python project\n'
241
+ '=======================\n'
242
+ '\n'
243
+ 'This is the description file for the project.\n'
244
+ '\n'
245
+ 'The file should use UTF-8 encoding and be written using '
246
+ 'ReStructured Text. It\n'
247
+ 'will be used to generate the project webpage on PyPI, and '
248
+ 'should be written for\n'
249
+ 'that purpose.\n'
250
+ '\n'
251
+ 'Typical contents for this file would include an overview of '
252
+ 'the project, basic\n'
253
+ 'usage examples, etc. Generally, including the project '
254
+ 'changelog in here is not\n'
255
+ 'a good idea, although a simple "What\'s New" section for the '
256
+ 'most recent version\n'
257
+ 'may be appropriate.',
258
+ 'description_content_type': None,
259
+ 'docs_url': None,
260
+ 'download_url': 'UNKNOWN',
261
+ 'downloads': {'last_day': -1, 'last_month': -1, 'last_week': -1},
262
+ 'home_page': 'https://github.com/pypa/sampleproject',
263
+ 'keywords': 'sample setuptools development',
264
+ 'license': 'MIT',
265
+ 'maintainer': None,
266
+ 'maintainer_email': None,
267
+ 'name': 'sampleproject',
268
+ 'package_url': 'https://pypi.org/project/sampleproject/',
269
+ 'platform': 'UNKNOWN',
270
+ 'project_url': 'https://pypi.org/project/sampleproject/',
271
+ 'project_urls': {'Download': 'UNKNOWN',
272
+ 'Homepage': 'https://github.com/pypa/sampleproject'},
273
+ 'release_url': 'https://pypi.org/project/sampleproject/1.2.0/',
274
+ 'requires_dist': None,
275
+ 'requires_python': None,
276
+ 'summary': 'A sample Python project',
277
+ 'version': '1.2.0'}
278
278
279
279
The result can be limited to a certain *depth * (ellipsis is used for deeper
280
280
contents)::
281
281
282
- >>> pprint.pprint(project_info, depth=2)
283
- {'info': {'_pypi_hidden': False,
284
- '_pypi_ordering': 125,
285
- 'author': 'Glyph Lefkowitz',
286
- 'author_email': '[email protected] ',
287
- 'bugtrack_url': '',
288
- 'cheesecake_code_kwalitee_id': None,
289
- 'cheesecake_documentation_id': None,
290
- 'cheesecake_installability_id': None,
291
- 'classifiers': [...],
292
- 'description': 'An extensible framework for Python programming, with '
293
- 'special focus\r\n'
294
- 'on event-based network programming and multiprotocol '
295
- 'integration.',
296
- 'docs_url': '',
297
- 'download_url': 'UNKNOWN',
298
- 'home_page': 'http://twistedmatrix.com/',
299
- 'keywords': '',
300
- 'license': 'MIT',
301
- 'maintainer': '',
302
- 'maintainer_email': '',
303
- 'name': 'Twisted',
304
- 'package_url': 'http://pypi.org/project/Twisted',
305
- 'platform': 'UNKNOWN',
306
- 'release_url': 'http://pypi.org/project/Twisted/12.3.0',
307
- 'requires_python': None,
308
- 'stable_version': None,
309
- 'summary': 'An asynchronous networking framework written in Python',
310
- 'version': '12.3.0'},
311
- 'urls': [{...}, {...}]}
282
+ >>> pprint.pprint(project_info, depth=1)
283
+ {'author': 'The Python Packaging Authority',
284
+ 'author_email': '[email protected] ',
285
+ 'bugtrack_url': None,
286
+ 'classifiers': [...],
287
+ 'description': 'A sample Python project\n'
288
+ '=======================\n'
289
+ '\n'
290
+ 'This is the description file for the project.\n'
291
+ '\n'
292
+ 'The file should use UTF-8 encoding and be written using '
293
+ 'ReStructured Text. It\n'
294
+ 'will be used to generate the project webpage on PyPI, and '
295
+ 'should be written for\n'
296
+ 'that purpose.\n'
297
+ '\n'
298
+ 'Typical contents for this file would include an overview of '
299
+ 'the project, basic\n'
300
+ 'usage examples, etc. Generally, including the project '
301
+ 'changelog in here is not\n'
302
+ 'a good idea, although a simple "What\'s New" section for the '
303
+ 'most recent version\n'
304
+ 'may be appropriate.',
305
+ 'description_content_type': None,
306
+ 'docs_url': None,
307
+ 'download_url': 'UNKNOWN',
308
+ 'downloads': {...},
309
+ 'home_page': 'https://github.com/pypa/sampleproject',
310
+ 'keywords': 'sample setuptools development',
311
+ 'license': 'MIT',
312
+ 'maintainer': None,
313
+ 'maintainer_email': None,
314
+ 'name': 'sampleproject',
315
+ 'package_url': 'https://pypi.org/project/sampleproject/',
316
+ 'platform': 'UNKNOWN',
317
+ 'project_url': 'https://pypi.org/project/sampleproject/',
318
+ 'project_urls': {...},
319
+ 'release_url': 'https://pypi.org/project/sampleproject/1.2.0/',
320
+ 'requires_dist': None,
321
+ 'requires_python': None,
322
+ 'summary': 'A sample Python project',
323
+ 'version': '1.2.0'}
312
324
313
325
Additionally, maximum character *width * can be suggested. If a long object
314
326
cannot be split, the specified width will be exceeded::
315
327
316
- >>> pprint.pprint(project_info, depth=2, width=50)
317
- {'info': {'_pypi_hidden': False,
318
- '_pypi_ordering': 125,
319
- 'author': 'Glyph Lefkowitz',
320
- 'author_email': '[email protected] ',
321
- 'bugtrack_url': '',
322
- 'cheesecake_code_kwalitee_id': None,
323
- 'cheesecake_documentation_id': None,
324
- 'cheesecake_installability_id': None,
325
- 'classifiers': [...],
326
- 'description': 'An extensible '
327
- 'framework for Python '
328
- 'programming, with '
329
- 'special focus\r\n'
330
- 'on event-based network '
331
- 'programming and '
332
- 'multiprotocol '
333
- 'integration.',
334
- 'docs_url': '',
335
- 'download_url': 'UNKNOWN',
336
- 'home_page': 'http://twistedmatrix.com/',
337
- 'keywords': '',
338
- 'license': 'MIT',
339
- 'maintainer': '',
340
- 'maintainer_email': '',
341
- 'name': 'Twisted',
342
- 'package_url': 'http://pypi.org/project/Twisted',
343
- 'platform': 'UNKNOWN',
344
- 'release_url': 'http://pypi.org/project/Twisted/12.3.0',
345
- 'requires_python': None,
346
- 'stable_version': None,
347
- 'summary': 'An asynchronous networking '
348
- 'framework written in '
349
- 'Python',
350
- 'version': '12.3.0'},
351
- 'urls': [{...}, {...}]}
328
+ >>> pprint.pprint(project_info, depth=1, width=60)
329
+ {'author': 'The Python Packaging Authority',
330
+ 'author_email': '[email protected] ',
331
+ 'bugtrack_url': None,
332
+ 'classifiers': [...],
333
+ 'description': 'A sample Python project\n'
334
+ '=======================\n'
335
+ '\n'
336
+ 'This is the description file for the '
337
+ 'project.\n'
338
+ '\n'
339
+ 'The file should use UTF-8 encoding and be '
340
+ 'written using ReStructured Text. It\n'
341
+ 'will be used to generate the project '
342
+ 'webpage on PyPI, and should be written '
343
+ 'for\n'
344
+ 'that purpose.\n'
345
+ '\n'
346
+ 'Typical contents for this file would '
347
+ 'include an overview of the project, '
348
+ 'basic\n'
349
+ 'usage examples, etc. Generally, including '
350
+ 'the project changelog in here is not\n'
351
+ 'a good idea, although a simple "What\'s '
352
+ 'New" section for the most recent version\n'
353
+ 'may be appropriate.',
354
+ 'description_content_type': None,
355
+ 'docs_url': None,
356
+ 'download_url': 'UNKNOWN',
357
+ 'downloads': {...},
358
+ 'home_page': 'https://github.com/pypa/sampleproject',
359
+ 'keywords': 'sample setuptools development',
360
+ 'license': 'MIT',
361
+ 'maintainer': None,
362
+ 'maintainer_email': None,
363
+ 'name': 'sampleproject',
364
+ 'package_url': 'https://pypi.org/project/sampleproject/',
365
+ 'platform': 'UNKNOWN',
366
+ 'project_url': 'https://pypi.org/project/sampleproject/',
367
+ 'project_urls': {...},
368
+ 'release_url': 'https://pypi.org/project/sampleproject/1.2.0/',
369
+ 'requires_dist': None,
370
+ 'requires_python': None,
371
+ 'summary': 'A sample Python project',
372
+ 'version': '1.2.0'}
0 commit comments