Explain Codes LogoExplain Codes Logo

Python and pip, list all versions of a package that's available?

python
pip
package-management
version-control
Nikita BarsukovbyNikita Barsukov·Mar 3, 2025
TLDR

Instantly fetch all versions of a Python package using:

pip install yolk3k && yolk -V <package_name>

This command installs yolk3k (a pretty handy tool), then retrieves the version list for the specified <package_name>.

Different beats for different pip's versions

Depending on your pip version, different commands are used to display available versions of a package without installing them:

For pip >= 21.2, let's go modern:

pip index versions <package_name> # Feel the rhythm of modern pip

For pip >= 9.0 and <= 21.1, keep it classic:

pip install <package_name>==  # Classic always has its charm...

For pip versions around 20.3, vintage style:

pip install --use-deprecated=legacy-resolver <package_name>==  # Vintage? No problem

Each command retrieves a list of all available versions for a given package from our dear friend, PyPI.

More than one way to list versions

Listing version information is not restricted to simple command-line usage. Here are some additional tools in the toolbox:

Python's requests to the rescue

Use Python's requests module to get version details from PyPI's JSON API:

  1. Fetch from PyPI's JSON API:

    import requests def fetch_versions(package_name): url = f"https://pypi.org/pypi/{package_name}/json" response = requests.get(url) # Send "a friend" to visit the url return response.json()['releases'].keys() # Pick up "souvenirs" - the keys of 'releases'
  2. Sort and display fetched versions data:

    from distutils.version import StrictVersion # The "judge" for sorting versions versions = fetch_versions('your-package-name') # Time to make a new friend sorted_versions = sorted(versions, key=StrictVersion) # Let the judge decide the ranking print(sorted_versions) # Show off your "competitors"

Bash scripting with the crew: curl and jq

Use a bash script along with curl and jq to wrangle version data from the pypi.org API:

#!/bin/bash set -e # Gear up for action package_name=$1 # Choose your "package_name" weapon curl -L "https://pypi.org/pypi/${package_name}/json" | jq '.releases | keys | .[]' # Bash away version-finding strategy

Don't forget to pass the package name as an argument, and remember that the -L flag is there to redirect URLs. Because we hate dead-ends, don't we?

Verbose mode: When the quiet gets too loud

Sometimes, using verbose mode -v with pip can help you sneak peak on available versions during installation attempts:

pip install -v <package_name>  # Like a backstage pass

This is more like a spy tool rather than a norm. Use it for problem diagnosing.

Watchouts and pointers

While you're busy with Python packages and versions, keep an eye out for these:

Deprecated options and removals

  • Be careful with deprecated options or those removed. They're like outdated fashion trends.
  • The --no-install flag is one of those old-fashioned trends. Instead, put on the --no-deps --no-install outfit.

Reliability concerns

  • Don't trust any stranger scripts that often appear on public forums like pastebin. Treat them like urban myths - fun to talk about but not trustworthy.

Regular updates and code maintenance

  • Keep your scripts and methods fresh and updated. Don't let them get dusty and rusty.

More than one way to skin a cat

  • Always open to alternative methods, just like that one called Chris's alternative method. Learning never ends.