Skip to main content

ghrepo-stats PyPI version

Have you ever wondered how the number of stargazers or the number of open issues has changed over time for your or any public GitHub repository? I did, so I wrote this small command line tool that will show this data.

ghrepo-stats uses pygithub to collect some statistics from a specific repository using a command line tool and show it using matplotlib or write it to a csv file.

Features

The following sub-commands are supported:

  • stars: shows the number of stargazers over time (caveat: stargazers that have removed their star are not shown, as the info is not available)
  • issues: shows the number of currently open issues over time
  • prs: shows the number of currently open pull requests over time
  • commits: shows the number of commits over the last year
  • codesize: shows the change of the code size over time measured by the number of added and deleted lines
  • issue-life: shows the average life time in days of issues over time (sampled once a week)
  • pr-life: shows the average life time in days of issues over time (sampled once a week)
  • dependents: show which repositories and packages depend on your repository as a list sorted by the number of stargazers

Runtime

Using sub-commands related to issues and PRs on repositories with many (open or close) issues may take a lot of time due to API access limitations the first time they are used on a given repository. Each subsequent call shall be much faster, as the results are cached in the file system (as json files in the subdirectory .ghrepo-stats in the home directory of the current user). Commands not related to issues/prs usually shall not take a long time, except for dependents - these are currently not cached and take a sufficient time (up to several minutes) if there are many of them (e.g. several thousands).

Installation

If you want to try it, you can install it from PyPi:

pip install ghrepo-stats

Or you can install the current main branch from GitHub:

pip install git+https://github.com/mrbean-bremen/ghrepo-stats

Usage

To use this, you need a GitHub account and a personal access token able to read public repositories for your GitHub account. The user name and token is expected to be found in the file ghrepo-stats.ini, either in the repository root, or in your home path.

The contents should be in the form:

[auth]
username = my-github-username
token = 123456789abcdef0123456789abcdef012345678

To get usage information you can now type:

$ show-ghstats -h
usage: show-ghstats [-h] [--verbose] [--csv CSV] sub_command repo_name

Shows GitHub repo statistics

positional arguments:
  sub_command    The kind of statistics to show. Possible values: 'issues',
                 'prs', 'stars', 'commits', 'codesize', 'issue-life', 'pr-
                 life', 'dependents'.
  repo_name      Full repository name in the form <repo_owner>/<repo_name>.

optional arguments:
  -h, --help     show this help message and exit
  --verbose, -v  Outputs diagnostic information
  --csv CSV      Write the output into a csv file with the given file path
  --packages     Only for dependents: get dependent packages instead of repositories
  --min-stars MIN_STARS
                 Only for dependents: limits the output to dependents with at least 
                 the given number of stargazers.

So, for example, to get a star plot of a specific repository, you can write:

$ show-ghstats stars "my-github-username/my-repo"

If you want to have the numbers saved in a csv file instead to play around with the numbers you can write:

$ show-ghstats stars "my-github-username/my-repo" --csv=my_repo-issues

This will write a file my_repo-issues.csv with the numbers (date+time / number of issues) in the current path.

Dependents

Getting dependent repositories is a bit different from the other commands, as dependent repositories are not available via the GitHub API, and there is no statistics to show. Instead, the data is collected using web scraping, and output into a CSV file if given or as lines on the standard output. There are also 2 specific parameters for this option (--packages and --min-stars) as shown above. Sorting by the number of stargazers is done to show the most known repositories first. No caching is done here (yet), so depending on the number of dependent repositories the call may take a long time.

Examples

Get some measure of popularity change by showing the number of stargazers over time (note: stars that have been retracted are not counted):

$ show-ghstats stars "pytest-dev/pyfakefs"

stars

Check how issues are handled over time. There are two possibilities:

  • Show the number of open issues at any point in time:
$ show-ghstats issues "svg-net/svg"

issues

  • Show the average lifetime of an issue as it changes over time. An increasing curve means ever more unresolved issues (also depends on the policies of the specific project - some projects leave issues open indefinitely, while others close outdated issues):
$ show-ghstats issue-life "pytest-dev/pyfakefs"

issue-lifetime

Get some measure of activity by checking how the code size changed over time (measured in code additions/deletions):

$ show-ghstats codesize "pytest-dev/pyfakefs"

codesize

Check which well-known packages depend on your repository:

$ show-ghstats dependents pydicom/pydicom --packages --min-stars=1000
fastai/fastai   23163
activeloopai/deeplake   5120
pypa/sampleproject      4500
openvinotoolkit/openvino        3890
Project-MONAI/MONAI     3675
Project-MONAI/MONAI     3675
microsoft/presidio      1906
Image-Py/imagepy        1209

Metadata

Release files for ghrepo-stats 0.5.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ghrepo-stats 0.5.5
File Size Uploaded
ghrepo_stats-0.5.5.tar.gz 14.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ghrepo-stats 0.5.5
File Interpreter ABI Platform
ghrepo_stats-0.5.5-py3-none-any.whl Python 3 none any Details

Total release size: 28.9 kB

Release files / ghrepo_stats-0.5.5.tar.gz

Download URL ghrepo_stats-0.5.5.tar.gz
Size 14.6 kB
Tags Source
SHA-256 checksum
How to use checksums
4d7757000a4943428823ade108e0e3fd3f1b62917668726b432801e6ba1c2014
BLAKE2b-256 checksum
How to use checksums
3986fd0bbab6d9fff765a4a814c415a1cd4293492edd2b613ef9652190e4767a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.12.8

Release files / ghrepo_stats-0.5.5-py3-none-any.whl

Download URL ghrepo_stats-0.5.5-py3-none-any.whl
Size 14.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6bad6224fdf5bee0d51999ce1fa96292d76e157d6d3b55a288914045f96606e3
BLAKE2b-256 checksum
How to use checksums
94339367f7e70156c420fb41bb40f45d822764e91a3e3ce4a3ec74517e19493f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.12.8

Release history Release notifications | RSS feed

This release

0.5.5 This release

2 release files

0.5.4

2 release files

0.5.3

2 release files

0.5.2

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page