dependabot / dependabot/dependabot-core
Switch Python `/simple` and `/<project>/` APIs to using the JSON-based format (PEP-691)
- Dominant language
- Ruby
- Stars
- 5.8k
- Forks
- 1.5k
- Avg merge
- 2d 14h
- Merged PRs (30d)
- 156
Description
### Code improvement description
This is mostly a brain dump of a bunch of research I did this evening around the current state of PyPI APIs as part of https://github.com/dependabot/dependabot-core/issues/5723 and whether any changes can/should be made in :dependabot: :
Warehouse / PyPI exposes several JSON-based APIs:
### `/simple`
* Provides an index of all packages.
* Defaults to HTML
* Can be requested in JSON format, as codified in [PEP-691](https://peps.python.org/pep-0691/).
* The HTML version is currently used by Dependabot for fetching available versions: https://github.com/dependabot/dependabot-core/blob/efc538ce5f1b424c20b30083875d426b61aaa4b7/python/lib/dependabot/python/update_checker/latest_version_finder.rb#L141-L231
* Would be nice to migrate to the JSON variant as parsing static HTML is never fun
* Probably blocked by lack of support in private registry implementations:
- https://github.com/pypiserver/pypiserver/issues/508
- https://github.com/devpi/devpi/issues/986
- Artifactory: unknown
- GitLab's pypi implementation: unknown
- Cloudsmith: unknown
- GemFury: unknown
- Sonatype Nexus: unknown
- Others??
### `//`
* Provides some version details about the package
* Can be requested in JSON format, as codified in [PEP-691](https://peps.python.org/pep-0691/).
* Used by Dependabot here: https://github.com/dependabot/dependabot-core/blob/efc538ce5f1b424c20b30083875d426b61aaa4b7/python/lib/dependabot/python/update_checker/latest_version_finder.rb#L219-L224
* Like `/simple` probably we can't migrate this to using the JSON API until/unless private registries support this.
### `/pypi//json`
* A per-project JSON API: https://warehouse.pypa.io/api-reference/json.html#project.
* This has not yet been codified into a standard and per the comments on https://github.com/pypa/packaging-problems/issues/367 is heavily affected by PyPI implementation details, so may never get codified into a standard.
* Today we use this in Dependabot for Metadata fetching for Python packages: https://github.com/dependabot/dependabot-core/blob/efc538ce5f1b424c20b30083875d426b61aaa4b7/python/lib/dependabot/python/metadata_finder.rb#L165
* Not supported by most private registry implementations:
* https://github.com/devpi/devpi/issues/801
* https://github.com/pypiserver/pypiserver/issues/437
* I'd be surprised if any of the hosted providers support this endpoint
### Conclusion:
1. The one JSON API that's non-standard is the one we use in Dependabot, because that's the only way to retrieve the metadata information.
2. The other APIs for fetching available versions now have a PEP standardizing how they should expose their data via JSON in addition to static HTML.
3. Today Dependabot fetches these via static HTML.
4. We are probably blocked for the foreseeable future from migrating those APIs to use JSON because it'd break all the private registries.
5. And running both JSON and HTML parsing paths doesn't make a lot of sense, at least right now, because it adds complexity with no real benefit.
Contributor guide
Assessment
This issue has not been assessed yet.