Skip to content

Instantly share code, notes, and snippets.

@cgoldberg
Last active September 15, 2020 21:53
Show Gist options
  • Save cgoldberg/5909944 to your computer and use it in GitHub Desktop.
Save cgoldberg/5909944 to your computer and use it in GitHub Desktop.
lookup PyPI packages by author or maintainer
#!/usr/bin/env python
# Corey Goldberg, 2013
import argparse
import pkgtools.pypi
"""
Command line script to lookup packages on Python Package Index (PyPI).
Lookup is done by author 'or' maintainer.
Takes a single positional argument: `name` (author or maintainer name on PyPI)
Finds packages on PyPI authored or maintained by the supplied `name`.
Prints each package name, latest version, and homepage url.
Example Usage:
$ python lookup_pypi_packages.py "corey goldberg"
(not case sensitive)
Output:
-------------------------------------------------------------------------------
Found 7 packages for 'corey goldberg':
* concurrencytest : 0.1.2 : https://github.com/cgoldberg/concurrencytest
* linux-metrics : 0.1.4 : https://github.com/cgoldberg/linux-metrics
* multi-mechanize : 1.2.0 : http://multimechanize.com
* sauceclient : 0.1.0 : http://cgoldberg.github.com/sauceclient/
* sst : 0.2.3 : http://testutils.org/sst
* xvfbwrapper : 0.2.2 : https://github.com/cgoldberg/xvfbwrapper
* ystockquote : 0.2.3 : https://github.com/cgoldberg/ystockquote
-------------------------------------------------------------------------------
"""
def find_packages(author):
pypi = pkgtools.pypi.pypi_client()
results = pypi.search({'author': author, 'maintainer': author}, 'or')
package_names = sorted(set(package['name'] for package in results))
return package_names
def get_latest_version(package_name):
pypi = pkgtools.pypi.pypi_client()
version = pypi.package_releases(package)[0]
return version
def get_home_page(package_name, version):
pypi = pkgtools.pypi.pypi_client()
release_data = pypi.release_data(package, version)
home_page_url = release_data['home_page']
return home_page_url
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('name', help='author or maintainer name on PyPI')
args = parser.parse_args()
packages = find_packages(args.name)
print('Found %d packages for %r:' % (len(packages), args.name))
for package in packages:
version = get_latest_version(package)
home_page_url = get_home_page(package, version)
print(' * %s : %s : %s' % (package, version, home_page_url))
@aclark4life
Copy link

Nice! Can I add this to vanity? https://github.com/aclark4life/vanity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment