• Stars
    star
    152
  • Rank 236,798 (Top 5 %)
  • Language
    Python
  • License
    MIT License
  • Created over 5 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Command-line interface to PyPI Stats API to get download stats for Python packages

pypistats

PyPI version Supported Python versions PyPI downloads Azure Pipelines status GitHub Actions status codecov Licence DOI Code style: Black

Python interface to PyPI Stats API to 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 the last 180 days. (For longer time periods, pypinfo can help, you'll need an API key and get free quota.)

Installation

From PyPI

python3 -m pip install --upgrade pypistats

From source

git clone https://github.com/hugovk/pypistats
cd pypistats
python3 -m pip install .

Example command-line use

Run pypistats with a subcommand (corresponding to PyPI Stats endpoints), then options for that subcommand.

Top-level help:

$ pypistats --help
usage: 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 exit

Help for a subcommand:

$ pypistats recent --help
usage: pypistats recent [-h] [-p {day,week,month}]
                        [-f {html,json,pretty,md,markdown,rich,rst,tsv}] [-j]
                        [-v]
                        package

Retrieve the aggregate download quantities for the last day/week/month

positional arguments:
  package

options:
  -h, --help            show this help message and exit
  -p {day,week,month}, --period {day,week,month}
  -f {html,json,pretty,md,markdown,rich,rst,tsv}, --format {html,json,pretty,md,markdown,rich,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:

$ pypistats recent pillow
┌───────────┬────────────┬────────────┐
│  last_day │ last_month │  last_week │
├───────────┼────────────┼────────────┤
│ 1,740,674 │ 50,722,906 │ 11,471,253 │
└───────────┴────────────┴────────────┘

Help for another subcommand:

$ pypistats python_minor --help
usage: pypistats python_minor [-h] [-V VERSION]
                              [-f {html,json,pretty,md,markdown,rich,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]
                              package

Retrieve the aggregate daily download time series by Python minor version
number

positional arguments:
  package

options:
  -h, --help            show this help message and exit
  -V VERSION, --version VERSION
                        eg. 2.7 or 3.6 (default: None)
  -f {html,json,pretty,md,markdown,rich,rst,tsv}, --format {html,json,pretty,md,markdown,rich,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]|name
                        Start date (default: None)
  -ed yyyy-mm[-dd]|name, --end-date yyyy-mm[-dd]|name
                        End date (default: None)
  -m yyyy-mm|name, --month yyyy-mm|name
                        Shortcut 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:

$ pypistats python_minor pillow --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-30

You can format in Markdown, ready for pasting in GitHub issues and PRs:

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-30

These are equivalent (in May 2019):

pypistats python_major pip --last-month
pypistats python_major pip --month april
pypistats python_major pip --month apr
pypistats python_major pip --month 2019-04

And:

pypistats python_major pip --start-date december --end-date january
pypistats python_major pip --start-date dec      --end-date jan
pypistats python_major pip --start-date 2018-12  --end-date 2019-01

Example programmatic use

Return values are from the JSON responses documented in the API: https://pypistats.org/api/

import pypistats
from pprint import pprint

# Call the API
print(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 pandas

To use with either NumPy or pandas, make sure they are first installed, or:

pip install --upgrade "pypistats[numpy]"
pip install --upgrade "pypistats[pandas]"
pip install --upgrade "pypistats[numpy,pandas]"

Return data in a NumPy array for further processing:

import pypistats
numpy_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:

import pypistats
pandas_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 mirrors
import pypistats
data = 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

overall.png

# Show Python 3 downloads over time
import pypistats
data = 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")  # alternatively

python3.png

See also

Related projects

More Repositories

1

em-keyboard

The CLI emoji keyboard
Python
308
star
2

top-pypi-packages

A regular dump of the most-downloaded packages from PyPI
HTML
169
star
3

meow.py

50,000 Meows: Replace all words with meows, preserving punctuation. For NaNoGenMo 2014.
Python
76
star
4

lastfm-tools

Some Python CLI tools for talking to the Last.fm API
Python
75
star
5

norwegianblue

CLI to show end-of-life dates for a number of products.
Python
37
star
6

gutenberg-metadata

Metadata from Project Gutenberg
Python
36
star
7

random-street-view

Street View images from random locations in a given country
Python
30
star
8

gutengrep

Find whole sentences matching a regex in Project Gutenberg
HTML
29
star
9

pixel-tools

Pixel-mangling scripts for the command line.
Python
29
star
10

everyfinnishword

Every Finnish word
27
star
11

twitter-tools

Command-line Python scripts to do things with Twitter.
Python
23
star
12

pypi-tools

Command-line Python scripts to do things with PyPI
Python
21
star
13

drop-python

It's about time to drop support for old Pythons
Python
18
star
14

strava-tools

Command-line scripts to do things with Strava
Python
17
star
15

tinytext

Convert your text ᶦᶰᵗᵒ ᵗᶦᶰᶦᵉʳ ᵗᵉˣᵗ
Python
15
star
16

python-logos

A selection of some of the best Python logos
HTML
14
star
17

pepotron

CLI to open PEPs in your browser
Python
12
star
18

osmviz

An OpenStreetMap Visualization Toolkit for Python
HTML
11
star
19

year-progress-bar

Nowadays everything needs a progress bar.
HTML
11
star
20

winamp

Python Winamp Controller
C++
8
star
21

dayssincelastjavascriptframework

Days since last JavaScript framework
HTML
8
star
22

chroniclingamerica.py

Python API to search Chronicling America newspaper pages
Python
8
star
23

word-tools

Three twitterbots that do things with words, and some tools to chart their output
Python
6
star
24

randomsentencebot

Tweet a random line from a text file.
Python
6
star
25

gutendelight

Tweeting a mix of hip hop (Rapper's Delight, Fight the Power, The Message, etc.) and classic literature from Project Gutenberg.
Python
5
star
26

randimgbot

Pick a random image and tweet it
Python
5
star
27

satellite-pies

Python version of Satellite Eyes for Windows
Python
4
star
28

fino

Output the Finnish word for a given integer.
Python
4
star
29

jargon-file

An archive of old Jargon Files
3
star
30

everyfinnishno

A bot to tweet every Finnish number
Python
3
star
31

fngbot

I am a bot that tweets one object from the collection of the Finnish National Gallery: Ateneum, Kiasma and Sinebrychoff art museums.
Python
3
star
32

helsinki-avoin-sans

Helsinki Avoin Sans font
3
star
33

wotdbot

Word of the day robot for tweeting a word of the day
Python
3
star
34

finnishnationalgallery

Dump of the Finnish National Gallery's complete data-package including all artwork information.
3
star
35

xdaysofxmas

The lesser-known verses of the misnamed Twelve Days of Christmas
HTML
3
star
36

bitsofpluto

Mastodonbot. Toots a different bit of Pluto every six hours.
Python
3
star
37

cheapbotsdonequick

Source code for bots hosted on Cheap Bots, Done Quick!
3
star
38

helloworld

Generate a poem, line by line, by changing one word at a time.
HTML
2
star
39

whatsonthemenu

Python interface to NYPL's What's on The Menu API
Python
2
star
40

botsummit

Archives from Bot Summit 2016
HTML
2
star
41

whyaretheflagsup

Why are the flags up in Finland?
HTML
2
star
42

tmrc-dictionary

Git-versioned 1959 and 1960 TMRC Dictionaries
2
star
43

thenewharperlee

Tweets hitherto-unpublished Harper Lee novels
Python
2
star
44

finland-emoji

Finland emoji
HTML
2
star
45

lolol

Replace every "lo" in Project Gutenberg with a "lol". For NaNoGenMo 2014.
Python
2
star
46

bbc-tools

Command-line Python scripts to do things with BBC data.
Python
2
star
47

github-tools

Command-line Python scripts to do things with GitHub.
Python
2
star
48

flickr-tools

Command-line Python scripts to do things with Flickr.
Python
2
star
49

helometer

How far to the nearest station?
JavaScript
2
star
50

slackabet

Convert text into Slack alphabet emoji
Python
1
star
51

python-0.9.1

Python 0.9.1p1 (1991-02-19)
C
1
star
52

hugovk

Python
1
star
53

project-gutenberg-august-2003-cd

"The August 2003 CD contains 600 of our best Ebooks."
HTML
1
star
54

hugovk.github.io

1
star
55

alcohol-tester

Am I safe to drive?
HTML
1
star
56

python2-progress-bar

Python 2.7 was released on 2010-07-03 and is EOL on 2020-01-01
HTML
1
star
57

bewithyoubot

X the Y be with you
Python
1
star
58

jifbot

Twitter bot fixing English by following the lead of GIF
Python
1
star
59

nodewegianblue

CLI to show end-of-life dates for a number of products.
JavaScript
1
star
60

pil-svn.effbot.org

Imported from SVN
C
1
star
61

scrapenfeed

Easily scrape web pages and turn them into RSS feeds
Python
1
star
62

fng-tools

Some tools to do stuff with https://github.com/hugovk/finnishnationalgallery data
Python
1
star
63

test-workflows

Demo repo for testing workflows
1
star
64

test

Repo for testing git, GitHub, Travis CI, and so on.
Shell
1
star
65

inXwords

Find a trending topic along the lines of #YinXwords and tweet a random X-word sentence from Project Gutenberg.
Python
1
star
66

viisikymmentatuhatta

50 000 Finnish Numbers. A catalogue for NaNoGenMo 2014.
Python
1
star
67

mucletters

An epistolary novel of love letters for NaNoGenMo 2015
HTML
1
star
68

lexiconstruct

Create a dictionary from archived tweets
HTML
1
star
69

lunchbot

Check what's for lunch at local restaurants and post to Slack
Python
1
star
70

python-steering-council

Members of the Python Steering Councils
HTML
1
star
71

happy_botday

Tweet birthday wishes for bots created today!
Python
1
star
72

blurb

Command-line tool to manage CPython Misc/NEWS.d entries
Python
1
star