Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Searching PyPI by topic

For every python package you can specify a list of classifiers. Among others there is a Topic classifier, that puts the package in the specified categories that can be browsed on PyPI.

For example, numpy has the following topics:

Topic :: Software Development
Topic :: Scientific/Engineering

Is there a way to search by topic programmatically using pip search or other third-party libraries?

like image 449
alecxe Avatar asked Jun 18 '14 15:06

alecxe


1 Answers

You can search PyPI by classifier via the XMLRPC API, using the browse() method:

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

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

packages = pypi.browse([
    "Topic :: Software Development",
    "Topic :: Scientific/Engineering",
])

In the example above, packages contains a list of [package, version] lists for all packages which satisfy both the "Topic :: Software Development" and "Topic :: Scientific/Engineering" classifiers:

>>> {pkg: ver for pkg, ver in packages if "numpy" in pkg}
{
    'nose-numpyseterr': '0.1',
    'msgpack-numpy': '0.3.2',
    'numpy': '1.8.1',
    'idx2numpy': '1.0b'
}

From there, you can retrieve more information about a given release:

>>> release = pypi.release_data('numpy', '1.8.1')
>>> release['download_url']
'http://sourceforge.net/projects/numpy/files/NumPy/'
>>> release['platform']
'Windows,Linux,Solaris,Mac OS-X,Unix'
>>> release['downloads']
{
    'last_day': 5818,
    'last_month': 187688,
    'last_week': 44764
}

... etc.

like image 161
Zero Piraeus Avatar answered Oct 23 '22 10:10

Zero Piraeus