question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`pip index show` command which fetches the package information via the JSON API

See original GitHub issue

What’s the problem this feature will solve?

Now that pip search is not working and would be removed in favour of pip index versions in #10431 , there is short description is not accessible from the command line. This is an opportunity to re-imagine the command.

Describe the solution you’d like

If numpy is installed in the environment, the following description is obtained

$ pip show numpy
Name: numpy
Version: 1.21.2
Summary: NumPy is the fundamental package for array computing with Python.
Home-page: https://www.numpy.org
Author: Travis E. Oliphant et al.
Author-email: 
License: BSD
Location: /home/avmo/.pyenv/versions/3.8.9/envs/snek/lib/python3.8/site-packages
Requires: 
Required-by: xarray, pandas, matplotlib, h5py

Say, numpy is not installed in the user environment.

$ pip show numpy
WARNING: Package(s) not found: numpy

The user would like to read the documentation, but only knows the name of the package. An output like this would be helpful

$ pip index show numpy
Name: numpy
Version: 1.21.2
Summary: NumPy is the fundamental package for array computing with Python.
Home-page: https://www.numpy.org
Author: Travis E. Oliphant et al.
Author-email: 
License: BSD
Location: < irrelevant >
Requires: 
Required-by:  < hard to deduce? >

Such an output can be populated from the JSON API

curl -s https://pypi.org/pypi/numpy/json | jq .info
{
  "author": "Travis E. Oliphant et al.",
  "author_email": "",
  "bugtrack_url": null,
  "classifiers": [
    "Development Status :: 5 - Production/Stable",
    "Intended Audience :: Developers",
    "Intended Audience :: Science/Research",
    "License :: OSI Approved :: BSD License",
    "Operating System :: MacOS",
    "Operating System :: Microsoft :: Windows",
    "Operating System :: POSIX",
    "Operating System :: Unix",
    "Programming Language :: C",
    "Programming Language :: Python",
    "Programming Language :: Python :: 3",
    "Programming Language :: Python :: 3 :: Only",
    "Programming Language :: Python :: 3.7",
    "Programming Language :: Python :: 3.8",
    "Programming Language :: Python :: 3.9",
    "Programming Language :: Python :: 3.10",
    "Programming Language :: Python :: Implementation :: CPython",
    "Topic :: Scientific/Engineering",
    "Topic :: Software Development",
    "Typing :: Typed"
  ],
  "description": "It provides:\n\n- a powerful N-dimensional array object\n- sophisticated (broadcasting) functions\n- tools for integrating C/C++ and Fortran code\n- useful linear algebra, Fourier transform, and random number capabilities\n- and much more\n\nBesides its obvious scientific uses, NumPy can also be used as an efficient\nmulti-dimensional container of generic data. Arbitrary data-types can be\ndefined. This allows NumPy to seamlessly and speedily integrate with a wide\nvariety of databases.\n\nAll NumPy wheels distributed on PyPI are BSD licensed.\n\n\n\n",
  "description_content_type": "",
  "docs_url": null,
  "download_url": "https://pypi.python.org/pypi/numpy",
  "downloads": {
    "last_day": -1,
    "last_month": -1,
    "last_week": -1
  },
  "home_page": "https://www.numpy.org",
  "keywords": "",
  "license": "BSD",
  "maintainer": "NumPy Developers",
  "maintainer_email": "numpy-discussion@python.org",
  "name": "numpy",
  "package_url": "https://pypi.org/project/numpy/",
  "platform": "Windows",
  "project_url": "https://pypi.org/project/numpy/",
  "project_urls": {
    "Bug Tracker": "https://github.com/numpy/numpy/issues",
    "Documentation": "https://numpy.org/doc/1.21",
    "Download": "https://pypi.python.org/pypi/numpy",
    "Homepage": "https://www.numpy.org",
    "Source Code": "https://github.com/numpy/numpy"
  },
  "release_url": "https://pypi.org/project/numpy/1.21.2/",
  "requires_dist": null,
  "requires_python": ">=3.7,<3.11",
  "summary": "NumPy is the fundamental package for array computing with Python.",
  "version": "1.21.2",
  "yanked": false,
  "yanked_reason": null
}

Alternative Solutions

Alternatively, simply pretty print the JSON after fetching it.

Right now I use https://github.com/jeffmm/pypi-simple-search/ to mimic the old pip search behaviour.

Additional context

The inspiration for this command is how pacman in ArchLinux works.

  • pacman -Qi <package>: to query an installed package for information
  • pacman -Si <package>: to query the package index for information

Code of Conduct

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
pfmoorecommented, Sep 14, 2021

I guess that begs the question of whether pip is a “package manager”. I’ve always thought of it as an “installer” rather than a broader tool. But I can see why framing it as a package manager makes sense.

2reactions
ashwinviscommented, Sep 14, 2021

@uranusjr Then we wait for the standard.

@pfmoore Displaying package description is a common feature of all package managers (not just pacman, but apt search, cargo search, and so on). I would assume others would like to have that information before they install the package. I don’t see the benefit of a third party tool just to query the JSON API.

Read more comments on GitHub >

github_iconTop Results From Across the Web

JSON API for PyPi - how to list packages? - Stack Overflow
The easiest way to do this is to use the simple index at PyPI which lists all packages without overhead. You can then...
Read more >
Finding and choosing files (index and PackageFinder)
The pip._internal.index sub-package in pip is responsible for deciding what file to download and from where, given a requirement for a project.
Read more >
Access Python package index JSON APIs with requests
PyPI, the Python package index, provides a JSON API for information about its packages. This is essentially a machine-readable source of the ...
Read more >
json — JSON encoder and decoder — Python 3.11.1 ...
Source code: Lib/json/__init__.py JSON (JavaScript Object Notation), specified by RFC 7159(which obsoletes RFC 4627) and by ECMA-404, is a lightweight data ...
Read more >
14 Must-Know pip Commands For Data Scientists and ...
These packages are usually uploaded on Python Package Index (PyPI). ... dependencies directly from that file using the command shown below.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found