2024-07-03
How to Check Latest Version of Python Package?
Recently, for pip >= 21.2 the syntax pip install pandas==
does not work anymore. There are several methods to get this information in a different way.
Use pip
There is a new experimental command:
pip index versions <package_name>
This command shows all available versions, with the latest at the top.
Use PyPI API and jq
Alternatively you can use PyPI API with curl and jq:
curl -s https://pypi.org/pypi/<package_name>/json | jq -r '.info.version'
This retrieves the latest version directly from PyPI.
curl -s https://pypi.org/pypi/<package_name>/json | jq -r 'releases | keys'
For convenience, you can use a shell function. Here's how you can do it:
- Open your shell configuration file (e.g.,
~/.bashrc
or~/.zshrc
) in a text editor. - Add the following function(s):
# display the latests version
pyversion() {
curl -s "https://pypi.org/pypi/$1/json" | jq -r '.info.version'
}
# display all versions
py-all-versions() {
curl -s "https://pypi.org/pypi/$1/json" | jq -r 'releases | keys'
}
NOTE: using PyPI API + jq is significantly faster than using
pip index versions
. using pypi API took ~0.4 s while pip index version took ~2 s.
Using the yolk
package:
First, install yolk3k:
pip install yolk3k
Then run:
yolk -V <package_name>