gelonida
gelonida

Reputation: 5630

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.

Upvotes: 3

Views: 957

Answers (2)

Spaceghost
Spaceghost

Reputation: 6995

PEP 691 was added in 2022 (two years after the question was asked). Listing it here to help seekers of the truth travelling here from the future.

https://peps.python.org/pep-0691/

Or this may help:

https://packaging.python.org/en/latest/specifications/simple-repository-api/

Upvotes: 1

Dustin Ingram
Dustin Ingram

Reputation: 21550

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.

Upvotes: 1

Related Questions