Reputation: 43
I'm working on a script that needs to download the latest binary version of the Python interpreter from the python.org website.
How do I get the version number of the latest stable release of Python?
Unfortunately, the CPython repository on Github is not using Releases, so I can't get the latest version via releases/latest, and the only option I currently see is parsing the python.org website, which isn't a good one since it depends on the future python.org redesigns.
I'd like to be able to get the version number via a single HTTP request if it's possible.
Upvotes: 4
Views: 1224
Reputation: 375
Although a bit hacky, I found that the website https://endoflife.date/python has the list of stable releases (along with its end of life dates) and it also provides an API for it.
Reading the documentation for the API given here https://endoflife.date/docs/api/, it looks like the first element of the json list is always the latest stable version. Therefore you can get the latest stable version string by using
import requests
result = requests.get("https://endoflife.date/api/python.json")
parsed_result = result.json()
version_string = parsed_result[0]["latest"]
Note that they've mentioned that the API is currently in Alpha.
Upvotes: 5