进阶 docs.pypi.org 2026-10-20 06:39:13 · 25 阅读

第25章 Index API 详解:PyPI 的 PEP 503 与 PEP 691 实现

Index API 本页介绍了 PyPI 对 PEP 503(HTML)和 PEP 691(JSON)Index API 的实现。请查阅 Simple Repository API 以获取该 API 的官方实时规范。 注 Index API 有时也被称为“遗留 API(legacy API)”,因为它与 PyPI 遗留代码库功能保持一致。 注 该 API 支持 HTML 和 JSON 两种格式。建议新集成使用 JSON 版本。 路由 列出所有项目 路由:GET /simple/ 返回所有已注册的项目。 响应头: X-PyPI-Last-Serial - 任何项目的最新序列号。 状态码: 200 OK - 无错误 HTML HTML 请求示例(如果未传递 Accept 头,则默认使用此格式): GET /simple/ HTTP/1.1 Host: pypi.org Accept: application/vnd.pypi.simple.v1+html HTML 响应示例 HTTP/1.0 200 OK Content-Type: application/vnd.pypi.simple.v1+html X-PyPI-Last-Serial: 24888689 Simple index 0 0-._.-._.-._.-._.-._.-._.-0 JSON JSON 请求示例: GET /simple/ HTTP/1.1 Host: pypi.org Accept: application/vnd.pypi.simple.v1+json JSON 响应示例 HTTP/1.1 200 OK Content-Type: application/vnd.pypi.simple.v1+json X-PyPI-Last-Serial: 24888689 { "meta": { "_last-serial": 24888689, "api-version": "1.4" }, "projects": [ { "_last-serial": 3075854, "name": "0" }, { "_last-serial": 1448421, "name": "0-._.-._.-._.-._.-._.-._.-0" }, "更多项目..." ] } 获取项目分发版本 路由:GET /simple/<project>/ 获取项目可用发行版(wheel 包和源码分发)的所有分发下载 URL。项目名称匹配不区分大小写,且 `_`、`-` 和 `.` 被视为等同。链接中可选地包含使用 URL 片段(fragment)表示的哈希值。该片段格式为 `#<hashname>=<hexdigest>`。如果存在,下载的必须对该哈希值进行验证。有效的哈希值包括 `md5`、`sha1`、`sha224`、`sha256`、`sha384` 和 `sha512`。 如果 PyPI 中存在分发文件的 PGP/GPG 签名,它将与文件位于相同的 URL 下,只是添加了 `.asc` 后缀。但上述 URL 列表中不会提供指向该签名的链接。因此,一旦你拥有了 wheel 或 sdist 文件名(例如 `https://file.pythonhosted.org/.../foo-1.0.tar.gz`),就可以通过单独的 GET 请求检查 `https://file.pythonhosted.org/.../foo-1.0.tar.gz.asc` 是否存在。 响应头: X-PyPI-Last-Serial - 该项目的最新序列号。 状态码: 200 OK - 无错误 HTML HTML 请求示例(如果未传递 Accept 头,则默认使用此格式): GET /simple/beautifulsoup4/ HTTP/1.1 Host: pypi.org Accept: application/vnd.pypi.simple.v1+html HTML 响应示例 HTTP/2 200 OK Content-Type: application/vnd.pypi.simple.v1+html Etag: "q4SqZutq1tfRDqhh3zQ4gQ" X-PyPI-Last-Serial: 2857110 <!DOCTYPE html> <html> <head> <meta name="pypi:repository-version" content="1.4"> <meta name="pypi:project-status" content="active"> <title>Links for beautifulsoup4</title> </head> <body> <a href="https://files.pythonhosted.org/packages/6f/be/99dcf74d947cc1e7abef5d0c4572abcb479c33ef791d94453a8fd7987d8f/beautifulsoup4-4.0.1.tar.gz#sha256=dc6bc8e8851a1c590c8cc8f25915180fdcce116e268d1f37fa991d2686ea38de" >beautifulsoup4-4.0.1.tar.gz</a>
beautifulsoup4-4.0.2.tar.gz
beautifulsoup4-4.13.0b2-py3-none-any.whl
beautifulsoup4-4.13.0b2.tar.gz
JSON JSON 请求示例: GET /simple/beautifulsoup4/ HTTP/1.1 Host: pypi.org Accept: application/vnd.pypi.simple.v1+json JSON 响应示例 HTTP/2 200 OK Content-Type: application/vnd.pypi.simple.v1+json Etag: "hVGQAYl/eoNrx2H5FmPuXw" X-PyPI-Last-Serial: 22406780 { "files": [ { "core-metadata": false, "data-dist-info-metadata": false, "filename": "beautifulsoup4-4.0.1.tar.gz", "hashes": { "sha256": "dc6bc8e8851a1c590c8cc8f25915180fdcce116e268d1f37fa991d2686ea38de" }, "requires-python": null, "size": 51024, "upload-time": "2014-01-21T05:35:05.558877Z", "url": "https://files.pythonhosted.org/packages/6f/be/99dcf74d947cc1e7abef5d0c4572abcb479c33ef791d94453a8fd7987d8f/beautifulsoup4-4.0.1.tar.gz", "yanked": false }, { "core-metadata": false, "data-dist-info-metadata": false, "filename": "beautifulsoup4-4.0.2.tar.gz", "hashes": { "sha256": "353792f8246a9551b232949fb14dce21d9b6ced9207bf9f4a69a4c4eb46c8127" }, "requires-python": null, "size": 51240, "upload-time": "2014-01-21T05:35:09.581933Z", "url": "https://files.pythonhosted.org/packages/a0/75/db36172ea767dd2f0c9817a99e24f7e9b79c2ce63eb2f8b867284cc60daf/beautifulsoup4-4.0.2.tar.gz", "yanked": false }, "...More files...", { "core-metadata": { "sha256": "524392d64a088e56a4232f50d6edb208dc03105394652acb72c6d5fa64c89f3e" }, "data-dist-info-metadata": { "sha256": "524392d64a088e56a4232f50d6edb208dc03105394652acb72c6d5fa64c89f3e" }, "filename": "beautifulsoup4-4.12.3-py3-none-any.whl", "hashes": { "sha256": "b80878c9f40111313e55da8ba20bdba06d8fa3969fc68304167741bbf9e082ed" }, "requires-python": ">=3.6.0", "size": 147925, "upload-time": "2024-01-17T16:53:12.779164Z", "url": "https://files.pythonhosted.org/packages/b1/fe/e8c672695b37eecc5cbf43e1d0638d88d66ba3a44c4d321c796f4e59167f/beautifulsoup4-4.12.3-py3-none-any.whl", "yanked": false }, { "core-metadata": false, "data-dist-info-metadata": false, "filename": "beautifulsoup4-4.12.3.tar.gz", "hashes": { "sha256": "74e3d1928edc070d21748185c46e3fb33490f22f52a3addee9aee0f4f7781051" }, "requires-python": ">=3.6.0", "size": 581181, "upload-time": "2024-01-17T16:53:17.902970Z", "url": "https://files.pythonhosted.org/packages/b3/ca/824b1195773ce6166d388573fc106ce56d4a805bd7427b624e063596ec58/beautifulsoup4-4.12.3.tar.gz", "yanked": false }, { "core-metadata": { "sha256": "d0aa787c2b55e5b0b3aff66f137cf33341c5e781cb87b4dc184cbb25c7ac0ab5" }, "data-dist-info-metadata": { "sha256": "d0aa787c2b55e5b0b3aff66f137cf33341c5e781cb87b4dc184cbb25c7ac0ab5" }, "filename": "beautifulsoup4-4.13.0b2-py3-none-any.whl", "hashes": { "sha256": "7e05ad0b6c26108d9990e2235e8a9b4e2c03ead6f391ceb60347f8ebea6b80ba" }, "requires-python": ">=3.6.0", "size": 179607, "upload-time": "2024-03-20T13:00:33.355932Z", "url": "https://files.pythonhosted.org/packages/14/7e/e4313dad823c3a0751c99b9bc0182b1dd19aea164ce7445e9a70429b9e92/beautifulsoup4-4.13.0b2-py3-none-any.whl", "yanked": false }, { "core-metadata": false, "data-dist-info-metadata": false, "filename": "beautifulsoup4-4.13.0b2.tar.gz", "hashes": { "sha256": "c684ddec071aa120819889aa9e8940f85c3f3cdaa08e23b9fa26510387897bd5" }, "requires-python": ">=3.6.0", "size": 550258, "upload-time": "2024-03-20T13:00:31.245327Z", "url": "https://files.pythonhosted.org/packages/81/bd/c97d94e2b96f03d1c50bc9de04130e014eda89322ba604923e0c251eb02e/beautifulsoup4-4.13.0b2.tar.gz", "yanked": false } ], "meta": { "_last-serial": 22406780, "api-version": "1.4" }, "name": "beautifulsoup4", "project-status": { "status": "active" }, "versions": [ "4.0.1", "4.0.2", "...More versions...", "4.12.3", "4.13.0b2" ] }

评论 (0)