Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to get the release date of pip packages programatically?

Tags:

python

pip

There are various tools like pip-date but I am looking for something that lists installed python packages like pip list does but with the release dates (not the install dates). It is just convenience scraping the site or the repo.

like image 579
mathtick Avatar asked Sep 14 '25 12:09

mathtick


2 Answers

I'm not sure how reliable it is, but you can try to call pypi.org for every installed package and extract the release date there.

Something like this:

import pkg_resources
import requests

for package in pkg_resources.working_set:
  (package_name, package_version) = str(package).split(' ')
  url = "https://pypi.org/project/{}/{}/".format(package_name, package_version)
  response = requests.get(url)
  
  # TODO find release date with re / beautiful soup / etree etc.
  package_date = 'TODO extract release date from response.text with re / beautifulsoup / etree etc.'
  
  print ("{} ({}): {}".format(package_name, package_version, package_date))
like image 71
DerMaddi Avatar answered Sep 16 '25 01:09

DerMaddi


Thanks to @DerMaddi and @astrochun have found a json api for pypi that has upload_time.

In [28]: res = requests.get('https://pypi.org/pypi/pandas/json')                                                                                                                                                   

In [29]: d = res.json()                                                                                                                                                                                            

In [30]: d.keys()                                                                                                                                                                                                  
Out[30]: dict_keys(['info', 'last_serial', 'releases', 'urls'])

In [31]: d['releases']['0.7.3'][0]                                                                                                                                                                                 
Out[31]: 
{'comment_text': '',
 'digests': {'md5': 'e4876ea5882accce15f6f37750f3ffec',
  'sha256': 'b770599f37fe7ee3d30755c48c8a0916e7cc4e04fbb8d531eb2536b408b05d0d'},
 'downloads': -1,
 'filename': 'pandas-0.7.3.tar.gz',
 'has_sig': False,
 'md5_digest': 'e4876ea5882accce15f6f37750f3ffec',
 'packagetype': 'sdist',
 'python_version': 'source',
 'requires_python': None,
 'size': 1446120,
 'upload_time': '2012-04-12T19:36:20',
 'upload_time_iso_8601': '2012-04-12T19:36:20.081721Z',
 'url': 'https://files.pythonhosted.org/packages/e8/77/b1bd481bd6b271004ebada46baeaae0b1f892999af5290a24196604266ea/pandas-0.7.3.tar.gz',
 'yanked': False,
 'yanked_reason': None}

In [32]: d['releases']['0.7.3'][1]                                                                                                                                                                                 
Out[32]: 
{'comment_text': '',
 'digests': {'md5': 'cf566a4cc2f19e27e02360ba55f1d8d3',
  'sha256': '77c650b7d5a7e3e227c3e47dcfbebdbe76fd97562da616d0de849b75a1b5a2fc'},
 'downloads': -1,
 'filename': 'pandas-0.7.3.win32-py2.5.exe',
 'has_sig': False,
 'md5_digest': 'cf566a4cc2f19e27e02360ba55f1d8d3',
 'packagetype': 'bdist_wininst',
 'python_version': '2.5',
 'requires_python': None,
 'size': 919743,
 'upload_time': '2012-04-12T19:40:30',
 'upload_time_iso_8601': '2012-04-12T19:40:30.681458Z',
 'url': 'https://files.pythonhosted.org/packages/cc/dc/a6ae8f182b2285a4528560179f99e5d90d3d68df277e39d5110c5d26d7db/pandas-0.7.3.win32-py2.5.exe',
 'yanked': False,
 'yanked_reason': None}

like image 34
mathtick Avatar answered Sep 16 '25 02:09

mathtick