Search code examples
pythonpippypi

search pypi packages programatically (ideally sorted by relevance)


This question is related to another question, that I posted get last update of a pip package programatically

I'd like to search packages with a given name on pypi. The interactive web page uses: https://pypi.org/search/?q=<search_word>

but returns html.

Though I could use html parsers to extract information I wonder whether there is any other API to do this kind of search.

Skimming through https://warehouse.pypa.io/api-reference/ I found how to get information about a given package ( https://pypi.org/pypi//json ) and how to get a list of all packages ( https://pypi.org/simple/ ) but I didn't find the way to search.


Solution

  • PyPI offers the ability to search via the XML-RPC API, see the search method here: https://warehouse.pypa.io/api-reference/xml-rpc/. This is what the pip search command uses.

    Unfortunately this is pretty limited, unwieldy, and will eventually be deprecated. There's a feature request for a proper search API here: https://github.com/pypa/warehouse/issues/5231, feel free to add a comment describing your needs.