Package: pypistats
pypistatsPython interface toPyPI Stats APIto get aggregate
download statistics on Python packages on the Python Package Index without having to
execute queries directly against Google BigQuery.Data is available for thelast 180 days. (For longer
time periods,pypinfocan help, you'll need an API
key and get free quota.)InstallationFrom PyPIpython3-mpipinstall--upgradepypistatsFrom sourcegitclonehttps://github.com/hugovk/pypistatscdpypistats
python3-mpipinstall.Example command-line useRunpypistatswith a subcommand (corresponding toPyPI Stats endpoints), then options for that
subcommand.Top-level help:$pypistats--helpusage: pypistats [-h] [-V]{recent,overall,python_major,python_minor,system} ...positional arguments:{recent,overall,python_major,python_minor,system}options:-h, --help            show this help message and exit-V, --version         show program's version number and exitHelp for a subcommand:$pypistatsrecent--helpusage: pypistats recent [-h] [-p {day,week,month}][-f {html,json,pretty,md,markdown,rst,tsv}] [-j][-v]packageRetrieve the aggregate download quantities for the last day/week/monthpositional arguments:packageoptions:-h, --help            show this help message and exit-p {day,week,month}, --period {day,week,month}-f {html,json,pretty,md,markdown,rst,tsv}, --format {html,json,pretty,md,markdown,rst,tsv}The format of output (default: pretty)-j, --json            Shortcut for "-f json" (default: False)-v, --verbose         Print debug messages to stderr (default: False)Get recent downloads:$pypistatsrecentpillow┌───────────┬────────────┬────────────┐│  last_day │ last_month │  last_week │├───────────┼────────────┼────────────┤│ 1,740,674 │ 50,722,906 │ 11,471,253 │└───────────┴────────────┴────────────┘Help for another subcommand:$pypistatspython_minor--helpusage: pypistats python_minor [-h] [-V VERSION][-f {html,json,pretty,md,markdown,rst,tsv}][-j] [-sd yyyy-mm[-dd]|name][-ed yyyy-mm[-dd]|name] [-m yyyy-mm|name] [-l][-t] [-d] [--monthly] [-c {yes,no,auto}] [-v]packageRetrieve the aggregate daily download time series by Python minor versionnumberpositional arguments:packageoptions:-h, --help            show this help message and exit-V VERSION, --version VERSIONeg. 2.7 or 3.6 (default: None)-f {html,json,pretty,md,markdown,rst,tsv}, --format {html,json,pretty,md,markdown,rst,tsv}The format of output (default: pretty)-j, --json            Shortcut for "-f json" (default: False)-sd yyyy-mm[-dd]|name, --start-date yyyy-mm[-dd]|nameStart date (default: None)-ed yyyy-mm[-dd]|name, --end-date yyyy-mm[-dd]|nameEnd date (default: None)-m yyyy-mm|name, --month yyyy-mm|nameShortcut for -sd & -ed for a single month (default:None)-l, --last-month      Shortcut for -sd & -ed for last month (default: False)-t, --this-month      Shortcut for -sd for this month (default: False)-d, --daily           Show daily downloads (default: False)--monthly             Show monthly downloads (default: False)-c {yes,no,auto}, --color {yes,no,auto}Color terminal output (default: auto)-v, --verbose         Print debug messages to stderr (default: False)Get version downloads:$pypistatspython_minorpillow--last-month┌──────────┬─────────┬────────────┐│ category │ percent │  downloads │├──────────┼─────────┼────────────┤│ 3.7      │  36.58% │ 18,620,128 ││ 3.8      │  22.17% │ 11,285,248 ││ 3.9      │  13.83% │  7,041,419 ││ 3.6      │  10.72% │  5,454,315 ││ null     │   7.39% │  3,761,767 ││ 3.10     │   6.41% │  3,263,885 ││ 3.11     │   1.16% │    589,792 ││ 2.7      │   0.89% │    451,041 ││ 3.5      │   0.83% │    422,741 ││ 3.12     │   0.01% │      3,089 ││ 3.4      │   0.00% │      2,483 ││ 3.3      │   0.00% │        251 ││ 3.2      │   0.00% │         95 ││ 2.6      │   0.00% │          1 ││ Total    │         │ 50,896,255 │└──────────┴─────────┴────────────┘Date range: 2022-11-01 - 2022-11-30You can format in Markdown, ready for pasting in GitHub issues and PRs:categorypercentdownloads3.736.58%18,620,1283.822.17%11,285,2483.913.83%7,041,4193.610.72%5,454,315null7.39%3,761,7673.106.41%3,263,8853.111.16%589,7922.70.89%451,0413.50.83%422,7413.120.01%3,0893.40.00%2,4833.30.00%2513.20.00%952.60.00%1Total50,896,255Date range: 2022-11-01 - 2022-11-30These are equivalent (in May 2019):pypistatspython_majorpip--last-month
pypistatspython_majorpip--monthapril
pypistatspython_majorpip--monthapr
pypistatspython_majorpip--month2019-04And:pypistatspython_majorpip--start-datedecember--end-datejanuary
pypistatspython_majorpip--start-datedec--end-datejan
pypistatspython_majorpip--start-date2018-12--end-date2019-01Example programmatic useReturn values are from the JSON responses documented in the API:https://pypistats.org/api/importpypistatsfrompprintimportpprint# Call the APIprint(pypistats.recent("pillow"))print(pypistats.recent("pillow","day",format="markdown"))print(pypistats.recent("pillow","week",format="rst"))print(pypistats.recent("pillow","month",format="html"))pprint(pypistats.recent("pillow","week",format="json"))print(pypistats.recent("pillow","day"))print(pypistats.overall("pillow"))print(pypistats.overall("pillow",mirrors=True,format="markdown"))print(pypistats.overall("pillow",mirrors=False,format="rst"))print(pypistats.overall("pillow",mirrors=True,format="html"))pprint(pypistats.overall("pillow",mirrors=False,format="json"))print(pypistats.python_major("pillow"))print(pypistats.python_major("pillow",version=2,format="markdown"))print(pypistats.python_major("pillow",version=3,format="rst"))print(pypistats.python_major("pillow",version="2",format="html"))pprint(pypistats.python_major("pillow",version="3",format="json"))print(pypistats.python_minor("pillow"))print(pypistats.python_minor("pillow",version=2.7,format="markdown"))print(pypistats.python_minor("pillow",version="2.7",format="rst"))print(pypistats.python_minor("pillow",version=3.7,format="html"))pprint(pypistats.python_minor("pillow",version="3.7",format="json"))print(pypistats.system("pillow"))print(pypistats.system("pillow",os="darwin",format="markdown"))print(pypistats.system("pillow",os="linux",format="rst"))print(pypistats.system("pillow",os="darwin",format="html"))pprint(pypistats.system("pillow",os="linux",format="json"))NumPy and pandasTo use with either NumPy or pandas, make sure they are first installed, or:pipinstall--upgrade"pypistats[numpy]"pipinstall--upgrade"pypistats[pandas]"pipinstall--upgrade"pypistats[numpy,pandas]"Return data in a NumPy array for further processing:importpypistatsnumpy_array=pypistats.overall("pyvista",total=True,format="numpy")print(type(numpy_array))# <class 'numpy.ndarray'>print(numpy_array)# [['with_mirrors' '2019-09-20' '2.23%' 1204]#  ['without_mirrors' '2019-09-20' '2.08%' 1122]#  ['with_mirrors' '2019-09-19' '0.92%' 496]#  ...#  ['with_mirrors' '2019-10-26' '0.02%' 13]#  ['without_mirrors' '2019-10-26' '0.02%' 12]#  ['Total' None None 54041]]Or in a pandas DataFrame:importpypistatspandas_dataframe=pypistats.overall("pyvista",total=True,format="pandas")print(type(pandas_dataframe))# <class 'pandas.core.frame.DataFrame'>print(pandas_dataframe)#             category        date percent  downloads# 0       with_mirrors  2019-09-20   2.23%       1204# 1    without_mirrors  2019-09-20   2.08%       1122# 2       with_mirrors  2019-09-19   0.92%        496# 3       with_mirrors  2019-08-22   0.90%        489# 4    without_mirrors  2019-09-19   0.86%        466# ..               ...         ...     ...        ...# 354  without_mirrors  2019-11-03   0.03%         15# 355  without_mirrors  2019-11-16   0.03%         15# 356     with_mirrors  2019-10-26   0.02%         13# 357  without_mirrors  2019-10-26   0.02%         12# 358            Total        None    None      54041## [359 rows x 4 columns]For example, create charts with pandas:# Show overall downloads over time, excluding mirrorsimportpypistatsdata=pypistats.overall("pillow",total=True,format="pandas")data=data.groupby("category").get_group("without_mirrors").sort_values("date")chart=data.plot(x="date",y="downloads",figsize=(10,2))chart.figure.show()chart.figure.savefig("overall.png")# alternatively# Show Python 3 downloads over timeimportpypistatsdata=pypistats.python_major("pillow",total=True,format="pandas")data=data.groupby("category").get_group(3).sort_values("date")chart=data.plot(x="date",y="downloads",figsize=(10,2))chart.figure.show()chart.figure.savefig("python3.png")# alternativelySee alsoRelated projectshttps://github.com/ofek/pypinfohttps://github.com/scivision/pypistats-plots