Dec 3, 2024 · Snippets

Get the Last PyPI Package - Quick Snippet

This is one of the most useful and most used aliases in my setup.

devpython

This is one of the most useful and most used aliases in my setup.

function last-py() {
    package_name=${1}
    n_versions=${2:-5}
    echo "Last ${n_versions} versions of ${package_name} <https://pypi.org/project/${package_name}/>"
    echo
    curl -Ls "https://pypi.org/pypi/${package_name}/json" |
        jq -r '
            .releases |
            to_entries |
            map(.key as $version |
            .value[] |
            {version: $version, upload_time: .upload_time_iso_8601}) |
            sort_by(.upload_time) |
            group_by(.version) |
            map(max_by(.upload_time)) |
            reverse |
            .[:'$n_versions'] |
            map([.version, .upload_time]) |
            (["Version", "Upload Time"] | (., map(length*"-"))), .[] | @tsv
        ' |
        column -t -s $'\t'
}

A lot of times when working on python, I want to know the last version of a particular dependency. This bash function give us a table with the latest uploaded versions of a package.

❯ last-py pandas 10
Last 10 versions of pandas <https://pypi.org/project/pandas/>

Version   Upload Time
-------   -----------
2.2.3     2024-09-20T19:02:26.247347Z
2.2.2     2024-04-15T13:26:40.761074Z
2.2.1     2024-02-23T15:32:10.410704Z
2.2.0rc0  2023-12-22T20:24:55.802599Z
2.2.0     2024-01-20T02:53:59.362940Z
2.1.4     2023-12-08T15:38:29.713155Z
2.1.3     2023-11-10T19:19:47.654074Z
2.1.2     2023-10-26T19:24:28.300130Z
2.1.1     2023-09-20T21:05:19.391878Z
2.1.0rc0  2023-08-11T18:32:00.107462Z