yarg: PyPI Client
Yarg is a Python client library designed for programmatically querying the Python Package Index (PyPI). Built on top of the `requests` library, it offers a straightforward interface to retrieve package metadata, including release details, and interact with PyPI's RSS feeds for discovering new and recently updated packages. The current version, 0.1.10, was released in August 2024 primarily for Python 3.12 compatibility, indicating an infrequent release cadence focused on maintenance.
Warnings
- gotcha PyPI package names are case-sensitive. `yarg.get()` will return a 404 Not Found error if the casing doesn't match the official PyPI registration.
- deprecated The PyPI domain transitioned from `pypi.python.org` to `pypi.org`. While `yarg` might handle redirects, older clients or custom `pypi_server` configurations might encounter issues if they hardcode the old domain.
- gotcha Older versions (pre-0.1.2) could raise `KeyError` if certain metadata fields like `home_page`, `bugtrack_url`, or `docs_url` were missing from PyPI's response for a package. This was fixed in 0.1.2.
- gotcha The `docs` attribute of a `Package` object is typically only populated for packages hosted on `pythonhosted.org`. Also, PyPI itself sometimes returns `docs_url` with an extra slash.
Install
-
pip install yarg
Imports
- yarg
import yarg
- yarg.get
package = yarg.get('package_name') - yarg.newest_packages
new_packages = yarg.newest_packages()
- yarg.latest_updated_packages
updated_packages = yarg.latest_updated_packages()
- yarg.exceptions.HTTPError
from yarg.exceptions import HTTPError
Quickstart
import yarg
try:
package = yarg.get("requests")
print(f"Package Name: {package.name}")
print(f"Author: {package.author.name} ({package.author.email})")
print(f"Latest Version: {package.latest_release.version}")
except yarg.exceptions.HTTPError as e:
print(f"Error fetching package: {e}")
print("\n--- Newest Packages ---")
newest = yarg.newest_packages()
for p in newest[:3]:
print(f"- {p.name} ({p.version})")