Skip to content
David Vegh edited this page May 2, 2022 · 23 revisions

Tutorial

write-pypistat makes it easy to collect, filter and save pypi statistics to csv files.

Visit our documentation site for code reference.

Initilaize a new WritePypiStat class

In these examples we initilaize a WritePypiStat class in order to collect statistics about pypistats pypi package.

Parameters:

  • package_name: name of the target pypi package
  • outdir: path of the directory where the gathered data will be saved into csv files

Example - Initilaize without outdir

Because outdir is None the gathered statistics will be only printed to the console.

from writepypistat import WritePypiStat

write_pypistat = WritePypiStat("pypistats")

Example - Initilaize with outdir

Because outdir is not None the gathered statistics will be saved into csv files too.

from writepypistat import WritePypiStat

write_pypistat = WritePypiStat("pypistats", "stats/pypistat")

Properties of the WritePypiStat class

Properties:

  • outdir: path of the directory where the gathered data will be saved into csv files
  • date_period: grouping of the statistics
  • write_package_name: flag used to write the name of the package into a csv column
  • merge_stored_data: flag used to merge actual pypi statistics with previously stored
  • fill_no_data: flag used to create empty lines with 0 download when data is not available
  • drop_percent_column: flag used to drop percent column from pypi statistics
  • drop_total_row: flag used to drop total row from pypi statistics

Example - Change outdir

outdir can be changed or set at anytime.

from writepypistat import WritePypiStat

write_pypistat = WritePypiStat("pypistats")

write_pypistat.outdir = "stats/pypistat"

Example - Change date_period

from writepypistat import WritePypiStat

write_pypistat = WritePypiStat("pypistats")

write_pypistat.date_period= "month"

Example - Change write_package_name

from writepypistat import WritePypiStat

write_pypistat = WritePypiStat("pypistats")

write_pypistat.write_package_name = True

Example - Change merge_stored_data

from writepypistat import WritePypiStat

write_pypistat = WritePypiStat("pypistats")

write_pypistat.merge_stored_data = False

Example - Change fill_no_data

from writepypistat import WritePypiStat

write_pypistat = WritePypiStat("pypistats")

write_pypistat.fill_no_data = False

Example - Change drop_percent_column

from writepypistat import WritePypiStat

write_pypistat = WritePypiStat("pypistats")

write_pypistat.drop_percent_column= False

Example - Change drop_total_row

from writepypistat import WritePypiStat

write_pypistat = WritePypiStat("pypistats")

write_pypistat.drop_total_row= False

Methods of the WritePypiStat class

get_pypistat

Parameters:

  • stat_type: type of the statistics
  • start_date: start date of the statistics
  • end_date: end date of the statistics

Example - Get pypi overall statistics between 2022-03-01 and 2022-04-10

from writepypistat import WritePypiStat

write_pypistat = WritePypiStat("pypistats")

stats = write_pypistat.get_pypistat("overall", "2022-03", "2022-04-10")

write_pypistat

Parameters:

  • stat_type: type of the statistics
  • start_date: start date of the statistics
  • end_date: end date of the statistics
  • postfix: postfix of the csv file

Example - Write pypi system statistics between 2022-01-01 and 2022-03-31, grouped by month

from writepypistat import WritePypiStat

write_pypistat = WritePypiStat("pypistats")
write_pypistat.date_period = "month"

write_pypistat.write_pypistat("system", "2022", "2022-03")