Using PyPIstats

Not too long ago, I made a pull request to PyPIstats to be able to make Pandas DataFrame objects of the download stats for any given project on PyPI. It’s a nifty little tool!

This example is mostly so that I can remember how to use PyPIstats and to have a place where my favorite Python projects’ stats are reported whenever my website is automatically rebuilt.

Not much to see here unless you’re interested in how many downloads my favorite projects are getting lately.

# sphinx_gallery_thumbnail_number = 1
import pypistats
import matplotlib.pyplot as plt

def fetch_and_plot(name):
    """A little helper method to do it all and make it pretty."""
    data = pypistats.overall(name, total=True, format="pandas")
    data = data.groupby("category").get_group("without_mirrors").sort_values("date")

    data.plot(x="date", y="downloads", figsize=(15, 5), marker='o')
    plt.xticks(
        rotation=45,
        horizontalalignment='right',
        fontweight='light',
        fontsize='medium',
    )
    plt.title("Downloads for {}".format(name))
    plt.tight_layout()
    return plt.show()
fetch_and_plot("pyvista")
Downloads for pyvista

Out:

/home/travis/virtualenv/python3.6.7/lib/python3.6/site-packages/pandas/plotting/_matplotlib/core.py:1235: UserWarning: FixedFormatter should only be used together with FixedLocator
  ax.set_xticklabels(xticklabels)
fetch_and_plot("scooby")
Downloads for scooby

Out:

/home/travis/virtualenv/python3.6.7/lib/python3.6/site-packages/pandas/plotting/_matplotlib/core.py:1235: UserWarning: FixedFormatter should only be used together with FixedLocator
  ax.set_xticklabels(xticklabels)
fetch_and_plot("SimPEG")
Downloads for SimPEG

Out:

/home/travis/virtualenv/python3.6.7/lib/python3.6/site-packages/pandas/plotting/_matplotlib/core.py:1235: UserWarning: FixedFormatter should only be used together with FixedLocator
  ax.set_xticklabels(xticklabels)
fetch_and_plot("PVGeo")
Downloads for PVGeo

Out:

/home/travis/virtualenv/python3.6.7/lib/python3.6/site-packages/pandas/plotting/_matplotlib/core.py:1235: UserWarning: FixedFormatter should only be used together with FixedLocator
  ax.set_xticklabels(xticklabels)
fetch_and_plot("itkwidgets")
Downloads for itkwidgets

Out:

/home/travis/virtualenv/python3.6.7/lib/python3.6/site-packages/pandas/plotting/_matplotlib/core.py:1235: UserWarning: FixedFormatter should only be used together with FixedLocator
  ax.set_xticklabels(xticklabels)
fetch_and_plot("gempy")
Downloads for gempy

Out:

/home/travis/virtualenv/python3.6.7/lib/python3.6/site-packages/pandas/plotting/_matplotlib/core.py:1235: UserWarning: FixedFormatter should only be used together with FixedLocator
  ax.set_xticklabels(xticklabels)
fetch_and_plot("omf")
Downloads for omf

Out:

/home/travis/virtualenv/python3.6.7/lib/python3.6/site-packages/pandas/plotting/_matplotlib/core.py:1235: UserWarning: FixedFormatter should only be used together with FixedLocator
  ax.set_xticklabels(xticklabels)
fetch_and_plot("omfvista")
Downloads for omfvista

Out:

/home/travis/virtualenv/python3.6.7/lib/python3.6/site-packages/pandas/plotting/_matplotlib/core.py:1235: UserWarning: FixedFormatter should only be used together with FixedLocator
  ax.set_xticklabels(xticklabels)

Total running time of the script: ( 0 minutes 6.549 seconds)

Gallery generated by Sphinx-Gallery