python / pythondotorg

Source code for python.org
https://www.python.org
Apache License 2.0
1.5k stars 594 forks source link

API to check for releases by major/minor version #1352

Open uranusjr opened 5 years ago

uranusjr commented 5 years ago

Is your feature request related to a problem? Please describe.

The question I want to answer is e.g. “what is the latest release for a given Python version X.Y”?

I build a CPython installation automation tool for Windows. It can be used to install a Python directly from the command line, e.g. pythonup install 3.6. Currently I maintain a hard-coded mapping file to point 3.6 to 3.6.7, but this means I need to release a new version every time CPython does.

I wish to automate the process by asking the python.org API for this information, but the current API design makes it very awkward. From what I can tell, I need to

  1. Request /downloads/release/ to get a long list of available releases.
  2. Parse the name manually to find releases starting with 3.6., and choose the latest.
  3. Parse the URI to get the release ID.
  4. Request /downloads/release_file/ with the request ID to get a list of files for that release.
  5. Parse the file names to find what I want.

Describe the solution you'd like

There are several things I would like to have to make the process more robust, but things that would benefit my workflow most would be

berkerpeksag commented 5 years ago

Thanks for the report. Yes, we can definitely improve the API. However, the API v1 is sort of deprecated. There is a new API at https://staging.python.org/api/v2/ (not deployed on production yet) but I don't think its behavior is any better than the current one (my goal was to make it backwards compatible with v1) We can definitely add a name__startswith filter at https://github.com/python/pythondotorg/blob/master/downloads/api.py#L73 and make getting files for a specific release easier.

uranusjr commented 5 years ago

On a related note, v2’s ALL_WITH_RELATIONS filters don’t seem to work correctly (probably because of some Tastypie-DRF implementation details). I could do

/api/v1/downloads/release_file/?os=1&release__name=Python%203.6.4

but not

/api/v2/downloads/release_file/?os=1&release__name=Python%203.6.4
sparrowt commented 7 months ago

Interestingly once you have found the release it appears you can use the ID from its resource_uri e.g. https://www.python.org/api/v2/downloads/release/?slug=python-3115 finds a release with resource_uri = https://www.python.org/api/v2/downloads/release/827/

Then filtering release_file using the ID from the end of the release resource_uri like this: https://www.python.org/api/v2/downloads/release_file/?release=827 seems to work, returning only relevant files for that release.

hugovk commented 3 weeks ago

The question I want to answer is e.g. “what is the latest release for a given Python version X.Y”?

This can be answered by the API for https://endoflife.date/python, which is updated by automation, not immediately, but quite soon after each release:

https://endoflife.date/api/python.json

Currently it looks like:

JSON ```json [ { "cycle": "3.12", "releaseDate": "2023-10-02", "eol": "2028-10-31", "latest": "3.12.6", "latestReleaseDate": "2024-09-06", "lts": false, "support": "2025-04-02" }, { "cycle": "3.11", "releaseDate": "2022-10-24", "eol": "2027-10-31", "latest": "3.11.10", "latestReleaseDate": "2024-09-07", "lts": false, "support": "2024-04-01" }, { "cycle": "3.10", "releaseDate": "2021-10-04", "eol": "2026-10-31", "latest": "3.10.15", "latestReleaseDate": "2024-09-07", "lts": false, "support": "2023-04-05" }, { "cycle": "3.9", "releaseDate": "2020-10-05", "eol": "2025-10-31", "latest": "3.9.20", "latestReleaseDate": "2024-09-06", "lts": false, "support": "2022-05-17" }, { "cycle": "3.8", "releaseDate": "2019-10-14", "eol": "2024-10-31", "latest": "3.8.20", "latestReleaseDate": "2024-09-06", "lts": false, "support": "2021-05-03" }, { "cycle": "3.7", "releaseDate": "2018-06-27", "eol": "2023-06-27", "latest": "3.7.17", "latestReleaseDate": "2023-06-05", "lts": false, "support": "2020-06-27" }, { "cycle": "3.6", "releaseDate": "2016-12-23", "eol": "2021-12-23", "latest": "3.6.15", "latestReleaseDate": "2021-09-03", "lts": false, "support": "2018-12-24" }, { "cycle": "3.5", "releaseDate": "2015-09-13", "eol": "2020-09-30", "latest": "3.5.10", "latestReleaseDate": "2020-09-05", "lts": false, "support": false }, { "cycle": "3.4", "releaseDate": "2014-03-16", "eol": "2019-03-18", "latest": "3.4.10", "latestReleaseDate": "2019-03-18", "lts": false, "support": false }, { "cycle": "3.3", "releaseDate": "2012-09-29", "eol": "2017-09-29", "latest": "3.3.7", "latestReleaseDate": "2017-09-19", "lts": false, "support": false }, { "cycle": "3.2", "releaseDate": "2011-02-20", "eol": "2016-02-20", "latest": "3.2.6", "latestReleaseDate": "2014-10-12", "lts": false, "support": false }, { "cycle": "2.7", "releaseDate": "2010-07-03", "eol": "2020-01-01", "latest": "2.7.18", "latestReleaseDate": "2020-04-19", "lts": false, "support": false }, { "cycle": "3.1", "releaseDate": "2009-06-27", "eol": "2012-04-09", "latest": "3.1.5", "latestReleaseDate": "2012-04-06", "lts": false, "support": false }, { "cycle": "3.0", "releaseDate": "2008-12-03", "eol": "2009-06-27", "latest": "3.0.1", "latestReleaseDate": "2009-02-12", "lts": false, "support": false }, { "cycle": "2.6", "releaseDate": "2008-10-01", "eol": "2013-10-29", "latest": "2.6.9", "latestReleaseDate": "2013-10-29", "lts": false, "support": false } ] ```