Skip to main content

从 PyPI 检索每月包下载统计信息

项目描述

概要

pypstats用于检索通过PyPI分发的包的每月和每个版本的下载统计信息。它可用于编写.csv文件、绘制每月统计数据以及检索最新版本的信息。从 2010 年 6 月开始,每月统计信息存储在 http://pypi.python.org/stats/months/压缩文件中。这些文件包含有关从 PyPI 中删除的版本的信息,因此pypstats提供了之后发布的软件包的完整统计信息2010 年 6 月。

安装

从http://pypi.python.org/pypi/pypstats下载一个包文件。提取其内容并运行setup.py,如下所示:

$ tar -xzf pypstats-1.x.tar.gz
$ cd pypstats-1.x
$ python setup.py install

或者,如果您安装了Easy Install ,请键入以下内容:

$ easy_install -U pypstats

用法

首次使用

在打印或绘制统计信息之前,您需要使用pypstats update命令检索统计信息并将其保存在本地:

$ pypstats update ProDy
Fetching content from 'http://pypi.python.org/stats/months/'.
Parsing monthly statistics file details.
Updating statistics for 2010-06.
...
Updating statistics for 2012-01.
Package statistics are updated (ProDy_stats.pkl).

首次使用时检索统计数据需要一些时间,因为所有月度统计文件都已下载。请注意,下载的文件将保存在临时文件夹中,除非传递了--nocache选项。保存下载的文件将使构建多个包的统计文件更快。

每月统计

可以使用pypstats 每月命令打印每月统计信息:

$ pypstats monthly ProDy_stats.pkl
Loading statistics from 'ProDy_stats.pkl'.
Month Downloads
2010-11       286
...
2012-01       1041
Total   10664

此信息也可以绘制并保存在.csv文件中,如下所示:

$ pypstats monthly -o monthly.csv -p monthly.png ProDy_stats.pkl
Loading statistics from 'ProDy_stats.pkl'.
Monthly statistics are written in 'monthly.csv'.
Monthly downloads plot is saved as 'monthly.png'.

发布统计

可以使用pypstats release命令打印发布统计信息:

$ pypstats release ProDy_stats.pkl
Loading statistics from 'ProDy_stats.pkl'.
Release       Downloads
0.1.0 397
...
0.9.2 328
Total 10664

同样,可以将输出写入.csv文件,如下所示:

$ pypstats release -o release_stats.csv -q ProDy_stats.pkl

请注意,-q参数禁止写入stderr的消息。

总下载量

可以使用pypstats total命令打印下载总数:

$ pypstats total -q ProDy_stats.pkl
10664

最新发布的

可以使用pypstats latest 命令检索最新版本信息:

$ pypstats latest -q ProDy
File  URL     md5     Type    Py Version      Size    Downloads
ProDy-0.9.2.tar.gz    http://pypi.python.org/packages/source/P/ProDy/ProDy-0.9.2.tar.gz       9ad6f6e6012f824ea5e7acb344607eae        Source          711KB   119
ProDy-0.9.2.win32-py2.6.exe   http://pypi.python.org/packages/2.6/P/ProDy/ProDy-0.9.2.win32-py2.6.exe 51f8587dcc8fe6d0355327d811ea71c3        MS Windows installer    2.6     455KB   47
ProDy-0.9.2.win32-py2.7.exe   http://pypi.python.org/packages/2.7/P/ProDy/ProDy-0.9.2.win32-py2.7.exe 68ba279f3d9e02b38e4f3e6339b41b26        MS Windows installer    2.7     909KB   53
ProDy-0.9.2.zip       http://pypi.python.org/packages/source/P/ProDy/ProDy-0.9.2.zip  b447f8b607defd5cda65163e43b32150        Source          744KB   109

可以使用 reStructured Text 样式将此信息写入 CSV 文件:

$ pypstats latest -q -o latest_release.csv --rst ProDy

此文件可用于使用Sphinx准备的页面,例如:http ://www.csb.pitt.edu/ProDy/getprody.html

更新

可以使用pypstats update命令更新本地统计信息文件:

$ pypstats update -s ProDy_stats.pkl ProDy
Fetching content from 'http://pypi.python.org/stats/months/'.
Parsing monthly statistics file details.
Nothing to update.

此命令将通过下载自上次更新以来更改的文件进行增量更新。

帮助

要获得帮助,请输入带有-h参数的命令名称:

$ pypstats -h
usage: pypstats.py [-h] {latest,monthly,total,update,release} ...

Fetch package download statistics from Python Package Index (PyPI). Package
needs to be distributed via PyPI.

optional arguments:
  -h, --help            show this help message and exit

subcommands:
  {latest,monthly,total,update,release}
    update              retrieve or update download statistics
    latest              retrieve and output latest release information
    monthly             output/plot monthly download statistics
    release             output download statistics by release
    total               output total number of downloads

See 'pypstats <command> -h' for more information on a specific command.
$ pypstats monthly -h
usage: pypstats.py monthly [-h] [-q] [-o FILENAME] [-d DELIMITER]
                           [-p FILENAME] [--dpi INT] [--mlabelstep INT]
                           pkl

positional arguments:
  pkl               package statistics filename

optional arguments:
  -h, --help        show this help message and exit
  -q, --quiet       suppress stderr log messages
  -o FILENAME       output CSV filename, if not provided print to stdout
  -d DELIMITER      output column delimiter (default: ' ')
  -p FILENAME       figure filename, requires Matplotlib
  --dpi INT         figure resolution (default: '72')
  --mlabelstep INT  figure month label step (default: '2')

功能

from pypstats import *导入以下可直接在 Python 代码中使用的函数:

  • pyps_update(package, pkl, cache) - 更新包统计信息

  • pyps_monthly(pkl) - 返回每月下载统计信息

  • pyps_release(pkl) - 返回发布下载统计信息

  • pyps_total(pkl) - 返回下载总数

执照

pypstats在 GNU 通用公共许可证版本 3 下可用。有关详细信息,请参阅 LICENSE.rst。

变化

v1.3

  • 添加了可直接在 Python 代码中使用的新函数。请参阅上面的使用部分。

  • 在保存下载的统计文件时使用时间戳,这样时区差异就不会导致问题。

v1.2.1

  • 修复了一个安装问题。

v1.2

  • 将脚本pypstats重命名为pyps

  • 下载的统计文件保存到临时文件夹。因此,当多个包统计信息更新时,将从该文件夹中读取内容。

v1.1

  • 将命令current重命名为latest

资源

http://github.com/abakan/pypstats

报告问题

https://github.com/abakan/pypstats/issues

项目详情


下载文件

下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。

源分布

pypstats-1.4.zip (12.2 kB 查看哈希

已上传 source

pypstats-1.4.tar.gz (8.7 kB 查看哈希

已上传 source