PyPI Stats
raw JSON → 1.13.0 verified Fri May 01 auth: no python
Python interface to the PyPI Stats API (https://pypistats.org/api). Provides programmatic and CLI access to download statistics for Python packages. Current version 1.13.0, requires Python >=3.10. Releases approximately every few months.
pip install pypistats Common errors
error ModuleNotFoundError: No module named 'pypistats.recent' ↓
cause Attempting to import submodule as if it's a nested package; `recent` is a module inside `pypistats` but should be imported with `from pypistats import recent`.
fix
Use
from pypistats import recent or import pypistats; pypistats.recent(...). error AttributeError: module 'pypistats' has no attribute 'recent' ↓
cause Importing the package but forgetting to import the submodule.
fix
Explicitly
import pypistats.recent (though from pypistats import recent is cleaner). error ValueError: Unsupported format: json ↓
cause Passing invalid format string; valid values are 'json', 'csv', 'markdown', or None.
fix
Use one of the accepted formats: format='json' (or 'csv', 'markdown', None).
Warnings
breaking Dropped support for Python 3.9 in version 1.12.0. ↓
fix Upgrade to Python 3.10+ or pin pypistats<1.12.0.
breaking HTTP client changed from httpx to urllib3 in 1.12.0. Code relying on httpx internals will break. ↓
fix Use only the public API; do not depend on httpx-related behavior.
deprecated The 'format=None' option returns raw Python data structure (added in 1.8.0); not formally deprecated but may change. ↓
fix Specify format='json' or other explicit format.
gotcha Package name validation: CLI accepts directory containing pyproject.toml/setup.cfg to infer package name (since 1.11.0), but the library API expects a string. ↓
fix Ensure you pass a string package name to the Python functions.
gotcha The CLI table format changed from MARKDOWN/SINGLE_BORDER to TableStyle in 1.8.0 to fix DeprecationWarnings. ↓
fix If parsing output, update your regex or use format='json'.
Imports
- pypistats
import pypistats - recent wrong
import pypistats.recentcorrectfrom pypistats import recent
Quickstart
import pypistats
# Get recent downloads for a package
data = pypistats.recent('requests', format='json')
print(data[:200]) # first 200 characters
# CLI equivalent: pypistats recent requests