14

For apt-based operating systems, there is an apt-cache show subcommand which shows everything known about a particular package, including version, dependencies, and long description.

Although pip has a pip show subcommand as well, it only shows such information about installed packages. (I suppose this has to do with the "online" architecture of pip vs that of apt-cache.)

Does pip have a way to view more information about a package without going to PyPI in a web browser?

ioistired
  • 153
  • 1
  • 9

1 Answers1

10

pip does not provide this functionality. Hovewer, 1. there is a cool package named yolk that can query PyPI repositories for metadata of available packages. 2. PyPI offers a JSON API that can be queried with a tool of your choice.

1. yolk

Install it with

$ pip2 install yolk

or

$ pip3 install yolk3k

python2 users, beware:

Looks like the original yolk package has now an issue with querying the PyPI packages. It may be due to the recent move of the repository from https://pypi.python.org to https://pypi.org; unfortunately, yolk is pretty old and was not updated for several years now. If you happen to have python2.7, use yolk3k as it's compatible with python2.7:

$ pip2.7 uninstall -y yolk && pip2.7 install yolk3k

(Thanks to @AnneTheAgile for the hint, see this comment)


Query complete metadata of a package (no matter if installed or not):

$ yolk -M pytest
maintainer:
docs_url: None
requires_python: >=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*
maintainer_email:
cheesecake_code_kwalitee_id: None
keywords: test unittest
package_url: http://pypi.python.org/pypi/pytest
author: Holger Krekel, Bruno Oliveira, Ronny Pfannschmidt, Floris Bruynooghe, Brianna Laugher, Florian Bruhin and others
author_email:
download_url:
platform: unix
version: 3.5.0
cheesecake_documentation_id: None
_pypi_hidden: False
description:
    ... # here comes the long README contents
release_url: http://pypi.python.org/pypi/pytest/3.5.0
downloads: {'last_month': 0, 'last_week': 0, 'last_day': 0}
_pypi_ordering: 69
requires_dist: ['py (>=1.5.0)', 'six (>=1.10.0)', 'setuptools', 'attrs (>=17.4.0)', 'more-itertools (>=4.0.0)', 'pluggy (<0.7,>=0.5)', 'funcsigs; python_version < "3.0"', 'colorama; sys_platform == "win32"']
classifiers: ['Development Status :: 6 - Mature', 'Intended Audience :: Developers', 'License :: OSI Approved :: MIT License', 'Operating System :: MacOS :: MacOS X', 'Operating System :: Microsoft :: Windows', 'Operating System :: POSIX', '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 :: Libraries', 'Topic :: Software Development :: Testing', 'Topic :: Utilities']
name: pytest
bugtrack_url: https://github.com/pytest-dev/pytest/issues
license: MIT license
summary: pytest: simple powerful testing with Python
home_page: http://pytest.org
cheesecake_installability_id: None

Query only selected metadata fields:

$ yolk -M pytest -f author,requires_python
requires_python: >=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*
author: Holger Krekel, Bruno Oliveira, Ronny Pfannschmidt, Floris Bruynooghe, Brianna Laugher, Florian Bruhin and others

Now you know how to get the package description:

$ yolk -M pkgname -f long_description

2. Query PyPI's JSON API

The above example with curl + jq:

$ curl -sH "accept: application/json" https://pypi.org/pypi/pytest/json | jq -r '.info.author, .info.requires_python'
Holger Krekel, Bruno Oliveira, Ronny Pfannschmidt, Floris Bruynooghe, Brianna Laugher, Florian Bruhin and others
>=3.5

Print all package metadata:

$ curl -sH "accept: application/json" https://pypi.org/pypi/pytest/json | jq -r '.info | keys[] as $key | "\($key): \(.[$key])"'
author: Holger Krekel, Bruno Oliveira, Ronny Pfannschmidt, Floris Bruynooghe, Brianna Laugher, Florian Bruhin and others
author_email: 
bugtrack_url: null
...
hoefling
  • 598
  • 7
  • 16
  • Hmm, I cannot subset fields: I get return code 0 but no results from : yolk -M pytest -f author,requires_python – AnneTheAgile Apr 25 '18 at 01:24
  • @AnneTheAgile do you use `yolk` for `python2`? This could be indeed an issue since the original `yolk` package is pretty much outdated. If you happen to have `python2.7` or `python3`, I suggest to uninstall `yolk` and use `yolk3k` instead. – hoefling Apr 25 '18 at 08:03
  • I also updated the answer with a hint for `python2` users. – hoefling Apr 25 '18 at 08:15
  • 4
    It is pretty crazy to me that pip will show the name and description but if you want any other information you have to install the package first or go find the information on the website. All of the information is available in the PyPI API, which pip is already querying against, so there is no technical reason why it couldn't be done. – theferrit32 Nov 30 '18 at 01:43
  • @theferrit32, it's not crazy. It's just typical for the flaming mess that is the hellscape of partly-backwards-compatible-and-still-unfinished-but-already-abandoned installation and deployment options in Python since forever. – hmijail Jun 01 '20 at 08:57