API to get latest version of a pypi package?

I want to get the latest version of a package. I found this API, for example for Django:


But the result is “heavy”. The JSON data is large: 300k.

Is there a way to get the latest version of a package with less network traffic?

Links for Django and find the newest version is an option.

See API for fetching latest and https://github.com/pypa/warehouse/pull/8615.


As far as I can tell PyPI supports returning 304 Not Modified if the response it would send matches the etag in the If-None-Match request header. If you’re polling PyPI periodically that’ll save duplicate downloads.


import requests

resp = requests.get("https://pypi.org/pypi/whey/json")
assert resp.status_code == 200
etag = resp.headers["Etag"]

resp2 = requests.get("https://pypi.org/pypi/whey/json", headers={"If-None-Match": etag})
assert resp2.status_code == 304, resp2.status_code

Thank you for your answer. Nevertheless it would be great to have an official solution.

See API for fetching latest and https://github.com/pypa/warehouse/pull/8615 .

Unfortunately, the current implementation just reuses the already-existing json_release function, so I don’t know how much reduction in payload size it will actually provide.

A modified implementation (e.g., one simply omitting the releases key in the payload, which is where I guess most of the bloat comes from), would be easy enough to craft, if this change were desired.

1 Like