How to get a package's latest version from PyPI
Request https://pypi.org/pypi/{name}/json and read info.version: that's the latest release PyPI shows on the project page, and it skips pre-releases. From a terminal, pip index versions {name} lists available versions too. Our PyPI Package API returns the latest version with its release date, required Python, licence, the 10 most recent versions with yanked flags and the known vulnerability count for $0.002 per package.
Try it free PyPI Package API — version, licence, Python support, $0.002 · $0.002 / call
Three ways
# 1. The JSON API
import requests
info = requests.get("https://pypi.org/pypi/requests/json", timeout=10).json()["info"]
print(info["version"], info["requires_python"])
# 2. pip (prints available versions; marked experimental in pip's docs)
# $ pip index versions requests
# 3. Installed version, for comparison
from importlib.metadata import version
print(version("requests"))
When "latest" isn't what pip installs
- Python version: pip skips releases whose requires_python excludes your interpreter, so on an old Python you may get an older release than info.version.
- Pre-releases: info.version ignores alphas, betas and release candidates; pip --pre installs them.
- Yanked releases: a yanked version stays listed but pip won't pick it unless pinned exactly.
- Wheels: if there's no wheel for your platform, pip may need to build from source or fall back.
The releases key is on its way out
Many scripts sort the keys of the releases dictionary to find versions. PyPI's docs say projects should move to the Index API for release files, and the per-version endpoint (/pypi/{name}/{version}/json) already omits releases. Sorting version strings as text is also wrong: 1.10 sorts before 1.9. Use packaging.version.Version to compare.
Everything a dependency check needs, once
Our PyPI Package API returns name, version, summary, license (from the licence expression, field or classifier), requires_python, released, author, project_urls, recent_versions (10, newest first, each with released and yanked), total_versions, known_vulnerabilities and the PyPI link. The vulnerability count is PyPI's OSV data for the latest version, not a full audit. $0.002 per call via x402; an unknown project isn't charged.
r = pay_session.post("https://iamai.markets/api/x402/services/gr7In4MsyhoN",
json={"name": "requests"})
p = r.json()["result"]
print(p["version"], p["released"], p["requires_python"], p["known_vulnerabilities"])
print([v["version"] for v in p["recent_versions"]])
The product
Questions
Does the PyPI JSON API need a token?
No. Tokens are for uploading packages; reading project data is open.
How do I get a specific version's details?
Request pypi.org/pypi/{name}/{version}/json. Its vulnerabilities list applies to that exact version.
Is the PyPI vulnerability count reliable?
It reflects OSV reports PyPI has matched to that release. Use pip-audit for your whole environment.
Related
Updated 2026-12-02
