What is an elegant way to find package versions in a pypi package index?

I am currently using a very ugly regex based approach for finding links and separating them.

I am not happy with the code, so I offer more pleasant solutions, preferably using only stdlib.

Edit

The task at hand consists of two parts:

  • Find all distributions that match certain criteria (e.g. name prefix).
  • Find all versions in each distribution found.

The expected result is a display of distributions -> versions -> files.

+4
source share
4 answers

its unfortunate, but due to the lack of xmlrpc on other indexes I need to save my solution

0
source

There is an XML-RPC interface. See the Python.org wiki page in the Cheese Shop API (old name for PyPi) .

Excerpt from this wiki:

>>> import xmlrpclib >>> server = xmlrpclib.Server('http://pypi.python.org/pypi') >>> server.package_releases('roundup') ['1.1.2'] >>> server.package_urls('roundup', '1.1.2') [{'has_sig': True, 'comment_text': '', 'python_version': 'source', 'url': 'http://pypi.python.org/packages/source/r/roundup/roundup-1.1.2.tar.gz', 'md5_digest': '7c395da56412e263d7600fa7f0afa2e5', 'downloads': 2989, 'filename': 'roundup-1.1.2.tar.gz', 'packagetype': 'sdist', 'size': 876455}, {'has_sig': True, 'comment_text': '', 'python_version': 'any', 'url': 'http://pypi.python.org/packages/any/r/roundup/roundup-1.1.2.win32.exe', 'md5_digest': '983d565b0b87f83f1b6460e54554a845', 'downloads': 2020, 'filename': 'roundup-1.1.2.win32.exe', 'packagetype': 'bdist_wininst', 'size': 614270}] 

list_packages and package_releases seem to be exactly what you are looking for.

Comment by @Ronny

You just need to write Python code to determine which of the following packages matches the criteria; that is, if the package name should start with foo :

 >>> packages = server.list_packages() >>> match_foo = [package for package in packages if package.startswith('foo')] >>> print len(match_foo) 2 
+2
source

We are going to release distutils2 in PyPI in the near future. It contains the distutils2.pypi module, which allows you to search for PyPI from Python code and the pysetup program, which is a command-line script to do the same (among others). The document still works, but there are a few examples and a link to the API:

+1
source

In the assembly in which pypi is available, I have pin versions, such as:

Products.PloneFormGen == 1.2.5

Here he searches for version 1.2.5 and uses this.

I don’t know if this is what you are looking for ...

-1
source

All Articles