PyPI JSON API client
pypi-json is a Python client library for accessing the PyPI JSON API. It allows programmatic retrieval of package metadata, including versions, summaries, dependencies, and more. The current version is 0.5.0.post1, and it has an infrequent but active release cadence, with the latest update in February 2026.
Common errors
-
httpx.HTTPStatusError: Client error '404 Not Found' for url 'https://pypi.org/pypi/nonexistent-package/json'
cause The package name provided to `get_package` does not exist on PyPI, or it is misspelled.fixVerify the package name for correctness. Implement `try...except httpx.HTTPStatusError` to handle non-existent packages gracefully. -
AttributeError: 'Package' object has no attribute 'some_nonexistent_field'
cause You are attempting to access an attribute on the `Package` object that does not exist in the PyPI JSON API response or is misspelled.fixCheck the available attributes of the `Package` object (e.g., by printing `dir(package)`) or consult the PyPI JSON API documentation to find the correct attribute name. -
httpx.ConnectError: [Errno 11001] getaddrinfo failed
cause The client could not establish a network connection to PyPI. This can be due to a lack of internet connectivity, DNS resolution issues, a firewall blocking access, or PyPI being temporarily unavailable.fixCheck your internet connection and DNS settings. Ensure no firewall is blocking access to `pypi.org`. If the issue persists, PyPI might be experiencing downtime, so try again later.
Warnings
- gotcha The `get_package` method raises an `httpx.HTTPStatusError` (specifically a 404 Not Found error) if the requested package does not exist on PyPI, rather than returning `None`. Users should implement error handling for this scenario.
- gotcha The attributes of the returned `Package` object (and its nested objects like `Release`) directly mirror the structure of the raw PyPI JSON API response. If the PyPI API changes its schema, or if you attempt to access an attribute not present for a specific package/version, an `AttributeError` will be raised.
Install
-
pip install pypi-json
Imports
- PyPIJSON
from pypi_json import PyPIJSON
Quickstart
from pypi_json import PyPIJSON
pypi = PyPIJSON()
try:
# Example: Get metadata for the 'requests' package
package = pypi.get_package("requests")
print(f"Package Name: {package.name}")
print(f"Latest Version: {package.version}")
print(f"Summary: {package.summary}")
# Accessing specific release information
if package.releases:
latest_release_info = package.releases[package.version]
print(f"Upload Time of latest version: {latest_release_info.upload_time_iso_8601}")
except Exception as e:
print(f"An error occurred: {e}")