jkpubsrc / python-module-jk-pypiorgapi

An API for accessing Python packet information hosted on pypi.org
5 stars 1 forks source link

Example of how to use iteratePackagesByClassifier #2

Closed bryanhanson closed 2 years ago

bryanhanson commented 2 years ago

Hello. I'm interested in searching PiPy.org for packages by keywords. I'm rather inexperienced with Python. I tried:

api = jk_pypiorgapi.PyPiOrgAPI()
jData = api.iteratePackagesByClassifier(searchTerm="nmr", classifiers=False)

and piped the result to a file, but the file is empty. Can you give an example of how to call this function? Or am I on the wrong track?

Background: I maintain FOSS4Spectroscopy and have automated ways to search Github, CRAN etc, and would like to develop an automated way to search PiPy.org. Found your answer on SO.

jkpubsrc commented 2 years ago

Sorry to answer that late but I didn't notice your question for a few weeks. My apologies. You're the very first to open an issue within two yeas, therefore I didn't expect that at all ;-)

And I just noticed that some methods lacked documentation. So I did three things right now so that you can use the API more easily:

For immediate use here is some example code:

import jk_pypiorgapi

api = jk_pypiorgapi.PyPiOrgAPI()
for jData in api.iteratePackagesByClassifier(
        searchTerm="jk_pypiorgapi",
        classifiers=[
            "Development Status :: 5 - Production/Stable",
            "Development Status :: 6 - Mature",
        ]
    ):

    print(jData)

This example uses jk_pypiorgapi as a search term and look for stable and mature packages. As the method iteratePackagesByClassifier() provides an iterator/generator you need to use for and loop through the results.

If you have any more questions please feel free to ask.

jkpubsrc commented 2 years ago

I'll close this issue now. Please feel free to reopen it/open an new one if required!