How to keep Python Packages updated

I have a couple of servers that uses a lot the of the Python power. Actually, I use “pip” to manage all the Python packages. Browsing the web  I found an amazing scripting that can tell me all packages that is installed and which of them needs to be upgraded to a new version.

#!/usr/bin/env python
import xmlrpclib
import pip

pypi = xmlrpclib.ServerProxy('')
for dist in pip.get_installed_distributions():
    available = pypi.package_releases(dist.project_name)
    if not available:
        # Try to capitalize pkg name
        available = pypi.package_releases(dist.project_name.capitalize())

    if not available:
        msg = 'no releases at pypi'
    elif available[0] != dist.version:
        msg = '{} available'.format(available[0])
        msg = 'up to date'
    pkg_info = '{dist.project_name} {dist.version}'.format(dist=dist)
    print '{pkg_info:40} {msg}'.format(pkg_info=pkg_info, msg=msg)


Leave a Reply

Your email address will not be published. Required fields are marked *