Searching PyPI by topic

我是研究僧i 提交于 2019-12-03 05:14:34

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!