Skip to content

Instantly share code, notes, and snippets.

@nikhilkumarsingh
Created July 3, 2019 19:27
Show Gist options
  • Save nikhilkumarsingh/f233ba969e89808c77852fa30074492f to your computer and use it in GitHub Desktop.
Save nikhilkumarsingh/f233ba969e89808c77852fa30074492f to your computer and use it in GitHub Desktop.
pprint Tutorial
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import requests"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"url = \"https://pypi.org/pypi/sampleproject/json\""
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"r = requests.get(url)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"scrolled": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'info': {'author': 'The Python Packaging Authority', 'author_email': '[email protected]', 'bugtrack_url': None, 'classifiers': ['Development Status :: 3 - Alpha', 'Intended Audience :: Developers', 'License :: OSI Approved :: MIT License', 'Programming Language :: Python :: 2', 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3', 'Programming Language :: Python :: 3.4', 'Programming Language :: Python :: 3.5', 'Programming Language :: Python :: 3.6', 'Programming Language :: Python :: 3.7', 'Topic :: Software Development :: Build Tools'], 'description': '# A sample Python project\\n\\nA sample project that exists as an aid to the [Python Packaging User\\nGuide][packaging guide]\\'s [Tutorial on Packaging and Distributing\\nProjects][distribution tutorial].\\n\\nThis project does not aim to cover best practices for Python project\\ndevelopment as a whole. For example, it does not provide guidance or tool\\nrecommendations for version control, documentation, or testing.\\n\\n[The source for this project is available here][src].\\n\\nMost of the configuration for a Python project is done in the `setup.py` file,\\nan example of which is included in this project. You should edit this file\\naccordingly to adapt this sample project to your needs.\\n\\n----\\n\\nThis is the README file for the project.\\n\\nThe file should use UTF-8 encoding and can be written using\\n[reStructuredText][rst] or [markdown][md use] with the appropriate [key set][md\\nuse]. It will be used to generate the project webpage on PyPI and will be\\ndisplayed as the project homepage on common code-hosting services, and should be\\nwritten for that purpose.\\n\\nTypical contents for this file would include an overview of the project, basic\\nusage examples, etc. Generally, including the project changelog in here is not a\\ngood idea, although a simple “What\\'s New” section for the most recent version\\nmay be appropriate.\\n\\n[packaging guide]: https://packaging.python.org\\n[distribution tutorial]: https://packaging.python.org/tutorials/packaging-projects/\\n[src]: https://github.com/pypa/sampleproject\\n[rst]: http://docutils.sourceforge.net/rst.html\\n[md]: https://tools.ietf.org/html/rfc7764#section-3.5 \"CommonMark variant\"\\n[md use]: https://packaging.python.org/specifications/core-metadata/#description-content-type-optional\\n\\n\\n', 'description_content_type': 'text/markdown', 'docs_url': None, 'download_url': '', 'downloads': {'last_day': -1, 'last_month': -1, 'last_week': -1}, 'home_page': 'https://github.com/pypa/sampleproject', 'keywords': 'sample setuptools development', 'license': '', 'maintainer': '', 'maintainer_email': '', 'name': 'sampleproject', 'package_url': 'https://pypi.org/project/sampleproject/', 'platform': '', 'project_url': 'https://pypi.org/project/sampleproject/', 'project_urls': {'Bug Reports': 'https://github.com/pypa/sampleproject/issues', 'Funding': 'https://donate.pypi.org', 'Homepage': 'https://github.com/pypa/sampleproject', 'Say Thanks!': 'http://saythanks.io/to/example', 'Source': 'https://github.com/pypa/sampleproject/'}, 'release_url': 'https://pypi.org/project/sampleproject/1.3.0/', 'requires_dist': ['peppercorn', \"check-manifest ; extra == 'dev'\", \"coverage ; extra == 'test'\"], 'requires_python': '>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, <4', 'summary': 'A sample Python project', 'version': '1.3.0'}, 'last_serial': 5328881, 'releases': {'1.0': [], '1.2.0': [{'comment_text': '', 'digests': {'md5': 'bab8eb22e6710eddae3c6c7ac3453bd9', 'sha256': '7a7a8b91086deccc54cac8d631e33f6a0e232ce5775c6be3dc44f86c2154019d'}, 'downloads': -1, 'filename': 'sampleproject-1.2.0-py2.py3-none-any.whl', 'has_sig': False, 'md5_digest': 'bab8eb22e6710eddae3c6c7ac3453bd9', 'packagetype': 'bdist_wheel', 'python_version': '2.7', 'requires_python': None, 'size': 3795, 'upload_time': '2015-06-14T14:38:05', 'url': 'https://files.pythonhosted.org/packages/30/52/547eb3719d0e872bdd6fe3ab60cef92596f95262e925e1943f68f840df88/sampleproject-1.2.0-py2.py3-none-any.whl'}, {'comment_text': '', 'digests': {'md5': 'd3bd605f932b3fb6e91f49be2d6f9479', 'sha256': '3427a8a5dd0c1e176da48a44efb410875b3973bd9843403a0997e4187c408dc1'}, 'downloads': -1, 'filename': 'sampleproject-1.2.0.tar.gz', 'has_sig': False, 'md5_digest': 'd3bd605f932b3fb6e91f49be2d6f9479', 'packagetype': 'sdist', 'python_version': 'source', 'requires_python': None, 'size': 3148, 'upload_time': '2015-06-14T14:37:56', 'url': 'https://files.pythonhosted.org/packages/eb/45/79be82bdeafcecb9dca474cad4003e32ef8e4a0dec6abbd4145ccb02abe1/sampleproject-1.2.0.tar.gz'}], '1.3.0': [{'comment_text': '', 'digests': {'md5': 'de98c6cdd6962d67e7368d2f9d9fa934', 'sha256': 'ab855ea282734dd216e8be4a42899a6fa8d2ce8f65b41c6379b69c1f804d6b1c'}, 'downloads': -1, 'filename': 'sampleproject-1.3.0-py2.py3-none-any.whl', 'has_sig': False, 'md5_digest': 'de98c6cdd6962d67e7368d2f9d9fa934', 'packagetype': 'bdist_wheel', 'python_version': 'py2.py3', 'requires_python': '>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, <4', 'size': 3988, 'upload_time': '2019-05-28T20:23:12', 'url': 'https://files.pythonhosted.org/packages/a1/fd/3564a5176430eac106c27eff4de50b58fc916f5083782062cea3141acfaa/sampleproject-1.3.0-py2.py3-none-any.whl'}, {'comment_text': '', 'digests': {'md5': '3dd8fce5e4e2726f343de4385ec8d479', 'sha256': 'ee67ab9c8b445767203e7d9523d029287f737c60524a3c0e0c36cc504e0f24d7'}, 'downloads': -1, 'filename': 'sampleproject-1.3.0.tar.gz', 'has_sig': False, 'md5_digest': '3dd8fce5e4e2726f343de4385ec8d479', 'packagetype': 'sdist', 'python_version': 'source', 'requires_python': '>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, <4', 'size': 5913, 'upload_time': '2019-05-28T20:23:13', 'url': 'https://files.pythonhosted.org/packages/a6/aa/0090d487d204f5de30035c00f6c71b53ec7f613138d8653eebac50f47f45/sampleproject-1.3.0.tar.gz'}]}, 'urls': [{'comment_text': '', 'digests': {'md5': 'de98c6cdd6962d67e7368d2f9d9fa934', 'sha256': 'ab855ea282734dd216e8be4a42899a6fa8d2ce8f65b41c6379b69c1f804d6b1c'}, 'downloads': -1, 'filename': 'sampleproject-1.3.0-py2.py3-none-any.whl', 'has_sig': False, 'md5_digest': 'de98c6cdd6962d67e7368d2f9d9fa934', 'packagetype': 'bdist_wheel', 'python_version': 'py2.py3', 'requires_python': '>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, <4', 'size': 3988, 'upload_time': '2019-05-28T20:23:12', 'url': 'https://files.pythonhosted.org/packages/a1/fd/3564a5176430eac106c27eff4de50b58fc916f5083782062cea3141acfaa/sampleproject-1.3.0-py2.py3-none-any.whl'}, {'comment_text': '', 'digests': {'md5': '3dd8fce5e4e2726f343de4385ec8d479', 'sha256': 'ee67ab9c8b445767203e7d9523d029287f737c60524a3c0e0c36cc504e0f24d7'}, 'downloads': -1, 'filename': 'sampleproject-1.3.0.tar.gz', 'has_sig': False, 'md5_digest': '3dd8fce5e4e2726f343de4385ec8d479', 'packagetype': 'sdist', 'python_version': 'source', 'requires_python': '>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, <4', 'size': 5913, 'upload_time': '2019-05-28T20:23:13', 'url': 'https://files.pythonhosted.org/packages/a6/aa/0090d487d204f5de30035c00f6c71b53ec7f613138d8653eebac50f47f45/sampleproject-1.3.0.tar.gz'}]}\n"
]
}
],
"source": [
"print(r.json())"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"from pprint import pprint"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"scrolled": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'info': {'author': 'The Python Packaging Authority',\n",
" 'author_email': '[email protected]',\n",
" 'bugtrack_url': None,\n",
" 'classifiers': ['Development Status :: 3 - Alpha',\n",
" 'Intended Audience :: Developers',\n",
" 'License :: OSI Approved :: MIT License',\n",
" 'Programming Language :: Python :: 2',\n",
" 'Programming Language :: Python :: 2.7',\n",
" 'Programming Language :: Python :: 3',\n",
" 'Programming Language :: Python :: 3.4',\n",
" 'Programming Language :: Python :: 3.5',\n",
" 'Programming Language :: Python :: 3.6',\n",
" 'Programming Language :: Python :: 3.7',\n",
" 'Topic :: Software Development :: Build Tools'],\n",
" 'description': '# A sample Python project\\n'\n",
" '\\n'\n",
" 'A sample project that exists as an aid to the '\n",
" '[Python Packaging User\\n'\n",
" \"Guide][packaging guide]'s [Tutorial on Packaging and \"\n",
" 'Distributing\\n'\n",
" 'Projects][distribution tutorial].\\n'\n",
" '\\n'\n",
" 'This project does not aim to cover best practices '\n",
" 'for Python project\\n'\n",
" 'development as a whole. For example, it does not '\n",
" 'provide guidance or tool\\n'\n",
" 'recommendations for version control, documentation, '\n",
" 'or testing.\\n'\n",
" '\\n'\n",
" '[The source for this project is available '\n",
" 'here][src].\\n'\n",
" '\\n'\n",
" 'Most of the configuration for a Python project is '\n",
" 'done in the `setup.py` file,\\n'\n",
" 'an example of which is included in this project. You '\n",
" 'should edit this file\\n'\n",
" 'accordingly to adapt this sample project to your '\n",
" 'needs.\\n'\n",
" '\\n'\n",
" '----\\n'\n",
" '\\n'\n",
" 'This is the README file for the project.\\n'\n",
" '\\n'\n",
" 'The file should use UTF-8 encoding and can be '\n",
" 'written using\\n'\n",
" '[reStructuredText][rst] or [markdown][md use] with '\n",
" 'the appropriate [key set][md\\n'\n",
" 'use]. It will be used to generate the project '\n",
" 'webpage on PyPI and will be\\n'\n",
" 'displayed as the project homepage on common '\n",
" 'code-hosting services, and should be\\n'\n",
" 'written for that purpose.\\n'\n",
" '\\n'\n",
" 'Typical contents for this file would include an '\n",
" 'overview of the project, basic\\n'\n",
" 'usage examples, etc. Generally, including the '\n",
" 'project changelog in here is not a\\n'\n",
" \"good idea, although a simple “What's New” section \"\n",
" 'for the most recent version\\n'\n",
" 'may be appropriate.\\n'\n",
" '\\n'\n",
" '[packaging guide]: https://packaging.python.org\\n'\n",
" '[distribution tutorial]: '\n",
" 'https://packaging.python.org/tutorials/packaging-projects/\\n'\n",
" '[src]: https://github.com/pypa/sampleproject\\n'\n",
" '[rst]: http://docutils.sourceforge.net/rst.html\\n'\n",
" '[md]: '\n",
" 'https://tools.ietf.org/html/rfc7764#section-3.5 '\n",
" '\"CommonMark variant\"\\n'\n",
" '[md use]: '\n",
" 'https://packaging.python.org/specifications/core-metadata/#description-content-type-optional\\n'\n",
" '\\n'\n",
" '\\n',\n",
" 'description_content_type': 'text/markdown',\n",
" 'docs_url': None,\n",
" 'download_url': '',\n",
" 'downloads': {'last_day': -1, 'last_month': -1, 'last_week': -1},\n",
" 'home_page': 'https://github.com/pypa/sampleproject',\n",
" 'keywords': 'sample setuptools development',\n",
" 'license': '',\n",
" 'maintainer': '',\n",
" 'maintainer_email': '',\n",
" 'name': 'sampleproject',\n",
" 'package_url': 'https://pypi.org/project/sampleproject/',\n",
" 'platform': '',\n",
" 'project_url': 'https://pypi.org/project/sampleproject/',\n",
" 'project_urls': {'Bug Reports': 'https://github.com/pypa/sampleproject/issues',\n",
" 'Funding': 'https://donate.pypi.org',\n",
" 'Homepage': 'https://github.com/pypa/sampleproject',\n",
" 'Say Thanks!': 'http://saythanks.io/to/example',\n",
" 'Source': 'https://github.com/pypa/sampleproject/'},\n",
" 'release_url': 'https://pypi.org/project/sampleproject/1.3.0/',\n",
" 'requires_dist': ['peppercorn',\n",
" \"check-manifest ; extra == 'dev'\",\n",
" \"coverage ; extra == 'test'\"],\n",
" 'requires_python': '>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, <4',\n",
" 'summary': 'A sample Python project',\n",
" 'version': '1.3.0'},\n",
" 'last_serial': 5328881,\n",
" 'releases': {'1.0': [],\n",
" '1.2.0': [{'comment_text': '',\n",
" 'digests': {'md5': 'bab8eb22e6710eddae3c6c7ac3453bd9',\n",
" 'sha256': '7a7a8b91086deccc54cac8d631e33f6a0e232ce5775c6be3dc44f86c2154019d'},\n",
" 'downloads': -1,\n",
" 'filename': 'sampleproject-1.2.0-py2.py3-none-any.whl',\n",
" 'has_sig': False,\n",
" 'md5_digest': 'bab8eb22e6710eddae3c6c7ac3453bd9',\n",
" 'packagetype': 'bdist_wheel',\n",
" 'python_version': '2.7',\n",
" 'requires_python': None,\n",
" 'size': 3795,\n",
" 'upload_time': '2015-06-14T14:38:05',\n",
" 'url': 'https://files.pythonhosted.org/packages/30/52/547eb3719d0e872bdd6fe3ab60cef92596f95262e925e1943f68f840df88/sampleproject-1.2.0-py2.py3-none-any.whl'},\n",
" {'comment_text': '',\n",
" 'digests': {'md5': 'd3bd605f932b3fb6e91f49be2d6f9479',\n",
" 'sha256': '3427a8a5dd0c1e176da48a44efb410875b3973bd9843403a0997e4187c408dc1'},\n",
" 'downloads': -1,\n",
" 'filename': 'sampleproject-1.2.0.tar.gz',\n",
" 'has_sig': False,\n",
" 'md5_digest': 'd3bd605f932b3fb6e91f49be2d6f9479',\n",
" 'packagetype': 'sdist',\n",
" 'python_version': 'source',\n",
" 'requires_python': None,\n",
" 'size': 3148,\n",
" 'upload_time': '2015-06-14T14:37:56',\n",
" 'url': 'https://files.pythonhosted.org/packages/eb/45/79be82bdeafcecb9dca474cad4003e32ef8e4a0dec6abbd4145ccb02abe1/sampleproject-1.2.0.tar.gz'}],\n",
" '1.3.0': [{'comment_text': '',\n",
" 'digests': {'md5': 'de98c6cdd6962d67e7368d2f9d9fa934',\n",
" 'sha256': 'ab855ea282734dd216e8be4a42899a6fa8d2ce8f65b41c6379b69c1f804d6b1c'},\n",
" 'downloads': -1,\n",
" 'filename': 'sampleproject-1.3.0-py2.py3-none-any.whl',\n",
" 'has_sig': False,\n",
" 'md5_digest': 'de98c6cdd6962d67e7368d2f9d9fa934',\n",
" 'packagetype': 'bdist_wheel',\n",
" 'python_version': 'py2.py3',\n",
" 'requires_python': '>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, '\n",
" '!=3.3.*, <4',\n",
" 'size': 3988,\n",
" 'upload_time': '2019-05-28T20:23:12',\n",
" 'url': 'https://files.pythonhosted.org/packages/a1/fd/3564a5176430eac106c27eff4de50b58fc916f5083782062cea3141acfaa/sampleproject-1.3.0-py2.py3-none-any.whl'},\n",
" {'comment_text': '',\n",
" 'digests': {'md5': '3dd8fce5e4e2726f343de4385ec8d479',\n",
" 'sha256': 'ee67ab9c8b445767203e7d9523d029287f737c60524a3c0e0c36cc504e0f24d7'},\n",
" 'downloads': -1,\n",
" 'filename': 'sampleproject-1.3.0.tar.gz',\n",
" 'has_sig': False,\n",
" 'md5_digest': '3dd8fce5e4e2726f343de4385ec8d479',\n",
" 'packagetype': 'sdist',\n",
" 'python_version': 'source',\n",
" 'requires_python': '>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, '\n",
" '!=3.3.*, <4',\n",
" 'size': 5913,\n",
" 'upload_time': '2019-05-28T20:23:13',\n",
" 'url': 'https://files.pythonhosted.org/packages/a6/aa/0090d487d204f5de30035c00f6c71b53ec7f613138d8653eebac50f47f45/sampleproject-1.3.0.tar.gz'}]},\n",
" 'urls': [{'comment_text': '',\n",
" 'digests': {'md5': 'de98c6cdd6962d67e7368d2f9d9fa934',\n",
" 'sha256': 'ab855ea282734dd216e8be4a42899a6fa8d2ce8f65b41c6379b69c1f804d6b1c'},\n",
" 'downloads': -1,\n",
" 'filename': 'sampleproject-1.3.0-py2.py3-none-any.whl',\n",
" 'has_sig': False,\n",
" 'md5_digest': 'de98c6cdd6962d67e7368d2f9d9fa934',\n",
" 'packagetype': 'bdist_wheel',\n",
" 'python_version': 'py2.py3',\n",
" 'requires_python': '>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, <4',\n",
" 'size': 3988,\n",
" 'upload_time': '2019-05-28T20:23:12',\n",
" 'url': 'https://files.pythonhosted.org/packages/a1/fd/3564a5176430eac106c27eff4de50b58fc916f5083782062cea3141acfaa/sampleproject-1.3.0-py2.py3-none-any.whl'},\n",
" {'comment_text': '',\n",
" 'digests': {'md5': '3dd8fce5e4e2726f343de4385ec8d479',\n",
" 'sha256': 'ee67ab9c8b445767203e7d9523d029287f737c60524a3c0e0c36cc504e0f24d7'},\n",
" 'downloads': -1,\n",
" 'filename': 'sampleproject-1.3.0.tar.gz',\n",
" 'has_sig': False,\n",
" 'md5_digest': '3dd8fce5e4e2726f343de4385ec8d479',\n",
" 'packagetype': 'sdist',\n",
" 'python_version': 'source',\n",
" 'requires_python': '>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, <4',\n",
" 'size': 5913,\n",
" 'upload_time': '2019-05-28T20:23:13',\n",
" 'url': 'https://files.pythonhosted.org/packages/a6/aa/0090d487d204f5de30035c00f6c71b53ec7f613138d8653eebac50f47f45/sampleproject-1.3.0.tar.gz'}]}\n"
]
}
],
"source": [
"pprint(r.json())"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.8"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment