Created
February 7, 2017 17:50
-
-
Save trinitronx/026574839d96a0c0efe1e9f2fd300f03 to your computer and use it in GitHub Desktop.
Pip list all versions of a package that are available
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import urllib2 | |
from distutils.version import StrictVersion | |
from distutils.version import LooseVersion | |
def versions(package_name): | |
url = "https://pypi.python.org/pypi/%s/json" % (package_name,) | |
data = json.load(urllib2.urlopen(urllib2.Request(url))) | |
versions = data["releases"].keys() | |
try: | |
versions.sort(key=StrictVersion) | |
except ValueError as e: | |
if 'invalid version number' in str(e): | |
versions.sort(key=LooseVersion) | |
else: | |
raise e | |
return versions | |
print "\n".join(versions("Jinja2")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks!
Also for python3 version.