github.com/replit/upm@v0.0.0-20240423230255-9ce4fc3ea24c/resources/python/pypi-search.py (about)

     1  # This is a Python script that does a PyPI search using the XMLRPC
     2  # API. It takes one argument, the search query (which may contain
     3  # spaces), and outputs the results in JSON format (a list of
     4  # pypiXMLRPCEntry maps). The script works on both Python 2 and Python
     5  # 3.
     6  
     7  from __future__ import print_function
     8  import json
     9  import sys
    10  
    11  try:
    12      from xmlrpc import client as xmlrpc
    13  except ImportError:
    14      import xmlrpclib as xmlrpc
    15  
    16  query = sys.argv[1]
    17  pypi = xmlrpc.ServerProxy("https://pypi.org/pypi")
    18  results = pypi.search({"name": query})
    19  json.dump(results, sys.stdout)
    20  print()