nycynik
nycynik

Reputation: 7541

How can I get a list of package locations from a PIP requirements file?

Is there a way to generate a list from PIP, to the actual resources in the file? For instance, if I had a requirements file with

Flask
Flask-Login

I would like to get output something like:

Name: Flask
Version: 0.10.1
Summary: A microframework based on Werkzeug, Jinja2 and good intentions
Home-page: http://github.com/mitsuhiko/flask/

Name: Flask-Login
Version: 0.3.2
Summary: User session management for Flask
Home-page: https://github.com/maxcountryman/flask-login

I found that information from pip show, but would like it to run on all the requirements that I have in the requirements.txt file.

Upvotes: 2

Views: 61

Answers (1)

alecxe
alecxe

Reputation: 474191

You can look up packages in the PyPI using the XMLRPC API:

try:
    import xmlrpclib  # Python 2
except ImportError:
    import xmlrpc.client as xmlrpclib  # Python 3

pypi = xmlrpclib.ServerProxy('http://pypi.python.org/pypi')

package_name = "Flask-Login"

packages = pypi.search({"name": package_name})
package = next(package for package in packages if package["name"] == package_name)
release_data = pypi.release_data(package_name, package["version"])

print(package_name)
print(package["version"])
print(release_data["summary"])
print(release_data["home_page"])

Prints:

Flask-Login
0.3.0
User session management for Flask
https://github.com/maxcountryman/flask-login

Upvotes: 1

Related Questions