209

In Github, is there a way I can see the number of downloads for a repo?

Kols
  • 3,641
  • 2
  • 34
  • 42
dhulihan
  • 11,053
  • 9
  • 40
  • 45
  • Clone counts are available to authorized users by [scraping with a Github username/password](http://stackoverflow.com/a/35997928/4258430) as are counts of downloads of *asset files* within [releases](https://developer.github.com/v3/repos/releases/). It doesn't seem possible to get clone counts from public repos or download stats on non-asset files (i.e. repo `tar.gz` and `zip` files). – Allen Luce Mar 14 '16 at 22:16
  • 2
    To anyone reading the answers, all scripts given below providing release download_count are wrong, as they do not take into account GitHub's pagination system, and only give the total for the most recent 30 releases, – Qiri Jan 16 '19 at 21:53
  • Yes @Qiri, you're right, I found an alternative answer, I post it here – Edison Pebojot Mar 23 '21 at 08:30
  • @Qiri Check out [my answer](https://stackoverflow.com/a/33454540/2004438) – three solutions (Web, Node.js, Python) with the pagination support. – kefir500 Aug 11 '21 at 08:20

21 Answers21

150

Update 2019:

Ustin's answer points to:


Update 2017

You still can use the GitHub API to get the download count for your releases (which is not exactly what was asked)
See "Get a single release", the download_count field.

There is no longer a traffic screen mentioning the number of repo clones.
Instead, you have to rely on third-party services like:

Git 2.14.2 release


Update August 2014

GitHub also proposes the number of clones for repo in its Traffic Graph:
See "Clone Graphs"

https://i.stack.imgur.com/uycEZ.png


Update October 2013

As mentioned below by andyberry88, and as I detailed last July, GitHub now proposes releases (see its API), which has a download_count field.

Michele Milidoni, in his (upvoted) answer, does use that field in his python script.
(very small extract)

c.setopt(c.URL, 'https://api.github.com/repos/' + full_name + '/releases')
for p in myobj:
    if "assets" in p:
        for asset in p['assets']:
            print (asset['name'] + ": " + str(asset['download_count']) +
                   " downloads")

Original answer (December 2010)

I am not sure you can see that information (if it is recorded at all), because I don't see it in the GitHub Repository API:

$ curl http://github.com/api/v2/yaml/repos/show/schacon/grit
---
repository:
  :name: grit
  :owner: schacon
  :source: mojombo/grit # The original repo at top of the pyramid
  :parent: defunkt/grit # This repo's direct parent
  :description: Grit is a Ruby library for extracting information from a
  git repository in an object oriented manner - this fork tries to
  intergrate as much pure-ruby functionality as possible
  :forks: 4
  :watchers: 67
  :private: false
  :url: http://github.com/schacon/grit
  :fork: true
  :homepage: http://grit.rubyforge.org/
  :has_wiki: true
  :has_issues: false
  :has_downloads: true

You can only see if it has downloads or not.


Adam Jagosz reports in the comments:

I got it to work with

 curl -H "Accept: application/vnd.github.v3+json"   https://api.github.com/repos/:user/:repo/releases

A couple of things that I had wrong:

  • I needed an actual Github release (not just git tag, even though Github does display those under releases, ugh).
  • And the release needs an asset file other than the zipped source that is added automatically in order to get the download count.
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 2
    Does this include ZIP downloads or just clones? – MarzSocks Dec 29 '15 at 07:55
  • 1
    @MarzSocks if you are talking about the `download_count` field of the release API, that should include the number of release downloads (which are not always zip, and are not clones) – VonC Dec 29 '15 at 07:58
  • @MarzSocks if you are talking about "number of clones", that should not include the zip downloads. Only the `git clone` instances. Check with GitHub support for confirmation. – VonC Dec 29 '15 at 07:59
  • 1
    @danielsp yet, it is still officially documented: https://help.github.com/articles/viewing-traffic-to-a-repository/. But yes, I don't see it anymore either: https://github.com/docker/docker/graphs/contributors – VonC Jan 18 '17 at 13:46
  • The autogenerated source archive files are apparently *not* assets.. ([see this comment](https://stackoverflow.com/questions/22180185/github-api-returns-empty-assets-for-release-array#comment33686689_22180185)) – olejorgenb Jan 19 '20 at 08:25
  • @truf Thank you. I have updated the link accordingly. – VonC Feb 06 '21 at 12:56
  • I'm getting ```{ "message": "Not Found", "documentation_url": "https://docs.github.com/rest/reference/repos#get-a-release" }``` – Adam Jagosz Feb 16 '21 at 17:55
  • @AdamJagosz What command did you type? Is it possible the release_id is the wrong one? – VonC Feb 16 '21 at 17:58
  • @VonC I got it to work with `curl -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/:user/:repo/releases`. A couple of things that I had wrong: I needed an actual Github release (not just git tag, even though Github does display those under releases, ugh). And the release needs an asset file other than the zipped source that is added automatically in order to get the download count. – Adam Jagosz Feb 21 '21 at 08:38
  • @AdamJagosz Thank you for this feedback. I have included your comment in the answer for more visibility. – VonC Feb 21 '21 at 08:41
  • it works to ` /repos/:owner/:repo/releases/:release_id`, however, when i used /repos/:owner/:repo/traffic/clones`, it always shows me the error message: **Must have push access to repository** – Edison Pebojot Mar 23 '21 at 08:20
  • @EdisonPebojot Indeed. I suppose it is reserved to repository owner only. I look forward to your alternative solution taking into account pagination. – VonC Mar 23 '21 at 08:55
109

I have written a small web application in javascript for showing count of the number of downloads of all the assets in the available releases of any project on Github. You can try out the application over here: http://somsubhra.github.io/github-release-stats/

Somsubhra
  • 1,149
  • 1
  • 8
  • 3
  • 5
    I keep getting 'There are no releases for this project' or 'The project doesn't exist' messages. What am I dong wrong? – Alex Jun 25 '15 at 09:58
  • I am getting the same message. That can't be right. – cryptic0 Jan 24 '16 at 14:43
  • 3
    Yep. Me too. Seems this app stopped working a long time ago. – Daan van den Bergh Sep 26 '18 at 07:05
  • 2
    This application is not correct, as it only includes the 30 most recent releases given by GitHub in an API response, as detailed here: https://developer.github.com/v3/guides/traversing-with-pagination/ It's necessary to iterate through the pages from the "next" link given in the header to caculate the correct total. An example repo is slamdata/quasar, where this method gives a wildly incorrect total. – Qiri Jan 16 '19 at 21:56
  • Application counts only repos with releases – S.M. Pat Jul 16 '20 at 06:19
  • 1
    It worked for quite a while (contrary to the comments here), but stopped working again. Any chance to see this working again? – hugo der hungrige Feb 08 '21 at 11:05
  • currently working for me..obviously you put the username of the repo's author in the `Github username` field, and not necessarily your own – velkoon Jun 29 '21 at 17:51
  • @hugoderhungrige https://hanadigital.github.io/grev/ – dr_nyt Nov 28 '21 at 04:24
  • Seems to be working again for now! – DyedPurple Aug 09 '23 at 13:33
13

GitHub has deprecated the download support and now supports 'Releases' - https://github.com/blog/1547-release-your-software. To create a release either use the GitHub UI or create an annotated tag (http:// git-scm.com/book/ch2-6.html) and add release notes to it in GitHub. You can then upload binaries, or 'assets', to each release.

Once you have some releases, the GitHub API supports getting information about them, and their assets.

curl -i \
https://api.github.com/repos/:owner/:repo/releases \
-H "Accept: application/vnd.github.manifold-preview+json"

Look for the 'download_count' entry. Theres more info at http://developer.github.com/v3/repos/releases/. This part of the API is still in the preview period ATM so it may change.

Update Nov 2013:

GitHub's releases API is now out of the preview period so the 'Accept' header is no longer needed - http://developer.github.com/changes/2013-11-04-releases-api-is-official/

It won't do any harm to continue to add the 'Accept' header though.

andyberry88
  • 2,244
  • 20
  • 17
  • Am I wrong to think that github does not currently show a `downloads` field in the assets any more (at least using this technique)? – Demis Nov 29 '15 at 04:28
  • This method still seems to be working for me. `download_count` is the field that indicates the number of downloads - for example in https://api.github.com/repos/twbs/bootstrap/releases. It's worth noting that only 'releases' will show up in this list, tags that show up in the releases page of a repo don't appear in the API listing, see https://developer.github.com/v3/repos/releases/. For example https://github.com/jquery/jquery/releases lists several tags under the releases section but an empty list is returned for https://api.github.com/repos/jquery/jquery/releases. – andyberry88 Nov 30 '15 at 09:18
  • Thanks! My Repo's don't appear to have such a field, even with some tags set as "releases" - this does not count the downloads of the zipped/tarballed releases (or the field is omitted if `count=0`)? Or only shows the field for Clone requests? See this, with no `download_count`: https://api.github.com/repos/demisjohn/pytrimsetup/releases . The github page for that is here: https://github.com/demisjohn/pyTRIMSetup/releases – Demis Nov 30 '15 at 15:34
  • Download counts are only available for release assets, not for the source code archives for the tag. If you look at the bootstrap URLs I provided above they have a `bootstrap-XYZ-dist.zip` asset which is what the `download_count` field relates to. If you want to see how many people are downloading a release you need to upload a release zip. As far as I know there is no way to see how many people have cloned/downloaded an archive via the API. The graphs view (from http://stackoverflow.com/a/4339085/2634854 above) may give you what you're after though. – andyberry88 Dec 01 '15 at 15:46
  • Thanks for clarifying. The graphs are indeed helpful. – Demis Dec 01 '15 at 21:20
13

VISITOR count should be available under your dashboard > Traffic (or stats or insights):

enter image description here

T.Todua
  • 53,146
  • 19
  • 236
  • 237
9

I had made a web app that shows GitHub release statistics in a clean format: https://hanadigital.github.io/grev/

dr_nyt
  • 323
  • 4
  • 10
8

As mentioned, GitHub API returns downloads count of binary file releases. I developed a little script to easly get downloads count by command line.

Michele
  • 653
  • 8
  • 13
  • Anywhere I can see an example of this in use? Can it be added to a Github badge? If not would it be possible to use google analytics to get download count to Github badge somehow? – Sentry.co Apr 07 '17 at 14:58
7

Formerly, there was two methods of download code in Github: clone or download as zip a .git repo, or upload a file (for example, a binary) for later download.

When download a repo (clone or download as zip), Github doesn't count the number of downloads for technical limitations. Clone a repository is a read-only operation. There is no authentication required. This operation can be done via many protocols, including HTTPS, the same protocol that the web page uses to show the repo in the browser. It's very difficult to count it.

See: http://git-scm.com/book/en/Git-on-the-Server-The-Protocols

Recently, Github deprecate the download functionality. This was because they understand that Github is focused in building software, and not in distribute binaries.

See: https://github.com/blog/1302-goodbye-uploads

7

Very late, but here is the answer you want:

https://api.github.com/repos/ [git username] / [git project] /releases

Next, find the id of the project you are looking for in the data. It should be near the top, next to the urls. Then, navigate to

https://api.github.com/repos/ [git username] / [git project] /releases/ [id] / assets

The field named download_count is your answer.

EDIT: Capitals matter in your username and project name

voice
  • 1,326
  • 1
  • 11
  • 16
7

To check the number of times a release file/package was downloaded you can go to https://githubstats0.firebaseapp.com

It gives you a total download count and a break up of of total downloads per release tag.

Aveek Saha
  • 111
  • 2
  • 5
  • Note that this only works for binary files in release, not source code itself, which means that if you don't upload any other files to be downloaded that it won't count. It's probably using the Github API from LeChosenOne's answer. – JoniVR Feb 11 '19 at 13:00
  • Also it doesn't count ghcr.io images. – akostadinov May 10 '22 at 17:41
5

The Github API does not provide the needed information anymore. Take a look at the releases page, mentioned in Stan Towianski's answer. As we discussed in the comments to that answer, the Github API only reports the downloads of 1 of the three files he offers per release.

I have checked the solutions, provided in some other answers to this questions. Vonc's answer presents the essential part of Michele Milidoni's solution. I installed his gdc script with the following result

# ./gdc stant
mdcsvimporter.mxt: 37 downloads
mdcsvimporter.mxt: 80 downloads
How-to-use-mdcsvimporter-beta-16.zip: 12 downloads

As you can clearly see, gdc does not report the download count of the tar.gz and zip files.

If you want to check without installing anything, try the web page where Somsubhra has installed the solution, mentioned in his answer. Fill in 'stant' as Github username and 'mdcsvimporter2015' as Repository name and you will see things like:

Download Info:
mdcsvimporter.mxt(0.20MB) - Downloaded 37 times.
Last updated on 2015-03-26

Alas, once again only a report without the downloads of the tar.gz and zip files. I have carefully examined the information that Github's API returns, but it is not provided anywhere. The download_count that the API does return is far from complete nowadays.

Community
  • 1
  • 1
Jan Ehrhardt
  • 395
  • 1
  • 8
  • 20
3

I ended up writing a scraper script to find my clone count:

#!/bin/sh
#
# This script requires:
#   apt-get install html-xml-utils
#   apt-get install jq
#
USERNAME=dougluce
PASSWORD="PASSWORD GOES HERE, BE CAREFUL!"
REPO="dougluce/node-autovivify"

TOKEN=`curl https://github.com/login -s -c /tmp/cookies.txt | \
     hxnormalize | \
     hxselect 'input[name=authenticity_token]' 2>/dev/null | \
     perl -lne 'print $1 if /value=\"(\S+)\"/'`

curl -X POST https://github.com/session \
     -s -b /tmp/cookies.txt -c /tmp/cookies2.txt \
     --data-urlencode commit="Sign in" \
     --data-urlencode authenticity_token="$TOKEN" \
     --data-urlencode login="$USERNAME" \
     --data-urlencode password="$PASSWORD" > /dev/null

curl "https://github.com/$REPO/graphs/clone-activity-data" \
     -s -b /tmp/cookies2.txt \
     -H "x-requested-with: XMLHttpRequest" | jq '.summary'

This'll grab the data from the same endpoint that Github's clone graph uses and spit out the totals from it. The data also includes per-day counts, replace .summary with just . to see those pretty-printed.

Allen Luce
  • 7,859
  • 3
  • 40
  • 53
2

To try to make this more clear:
for this github project: stant/mdcsvimporter2015
https://github.com/stant/mdcsvimporter2015
with releases at
https://github.com/stant/mdcsvimporter2015/releases

go to http or https: (note added "api." and "/repos")
https://api.github.com/repos/stant/mdcsvimporter2015/releases

you will get this json output and you can search for "download_count":

    "download_count": 2,
    "created_at": "2015-02-24T18:20:06Z",
    "updated_at": "2015-02-24T18:20:07Z",
    "browser_download_url": "https://github.com/stant/mdcsvimporter2015/releases/download/v18/mdcsvimporter-beta-18.zip"

or on command line do:
wget --no-check-certificate https://api.github.com/repos/stant/mdcsvimporter2015/releases

Stan Towianski
  • 411
  • 2
  • 6
  • As far as I can see github only counts the first of the three files you offer for downloading, like mdcsvimporter-beta-18.zip. Did you ever fiind a way to get a download_count of things like v19.zip? – Jan Ehrhardt May 08 '15 at 22:09
  • I only have 3 releases for md2015, and v19 is the first one that shows. v19 came after this post so it's not shown here. Did you go to the url :-) ? "download_count": 31, "created_at": "2015-03-26T04:22:13Z", "updated_at": "2015-03-26T04:22:13Z", "browser_download_url": – Stan Towianski May 10 '15 at 13:28
  • But as far as I can see Github does not count the downloads of https://github.com/stant/mdcsvimporter2015/archive/v19.zip and https://github.com/stant/mdcsvimporter2015/archive/v18-alpha.tar.gz – Jan Ehrhardt May 11 '15 at 14:46
  • Hi. I'm not even sure where you came up with those download url's, but that is a question for github. It does only seem to count the files I release (3), and not even the source zip files that it creates (another 2 per my release). I wrote a java app for myself that I run to make this call, get the json back, and parse out and show just the download count. – Stan Towianski May 13 '15 at 05:12
  • Too bad. Apparently Github is not providing the info we need (anymore?). Of the 3*3 files you have at https://github.com/stant/mdcsvimporter2015/releases it only reports the doenload_count of the release file it self, not of the *.tar.gz and the *.zip files. I will make the a separate answer as it affects all the other solutions. – Jan Ehrhardt May 14 '15 at 09:43
2

I have created three solutions to fetch the download count and other statistics for GitHub releases. Each of these implementations are able to accumulate the GitHub API pagination results, which means that calculating the total number of downloads won't be an issue.

Web Application

Node.js Implementation

Python Implementation

kefir500
  • 4,184
  • 6
  • 42
  • 48
2

11 years later...
Here's a small python3 snippet to retrieve the download count of the last 100 release assets:

import requests

owner = "twbs"
repo = "bootstrap"
h = {"Accept": "application/vnd.github.v3+json"}
u = f"https://api.github.com/repos/{owner}/{repo}/releases?per_page=100"
r = requests.get(u, headers=h).json()
r.reverse() # older tags first
for rel in r:
  if rel['assets']:
    tag = rel['tag_name']
    dls = rel['assets'][0]['download_count']
    pub = rel['published_at']
    print(f"Pub: {pub} | Tag: {tag} | Dls: {dls} ")

Pub: 2013-07-18T00:03:17Z | Tag: v1.2.0 | Dls: 1193 
Pub: 2013-08-19T21:20:59Z | Tag: v3.0.0 | Dls: 387786 
Pub: 2013-10-30T17:07:16Z | Tag: v3.0.1 | Dls: 102278 
Pub: 2013-11-06T21:58:55Z | Tag: v3.0.2 | Dls: 381136 
...
Pub: 2020-12-07T16:24:37Z | Tag: v5.0.0-beta1 | Dls: 93943 

Demo

Pedro Lobito
  • 94,083
  • 31
  • 258
  • 268
2

New implementation:

Port into GitHub composite action to reuse workflow code base.

https://github.com/andry81-devops/github-accum-stats

With additional features:

  1. Can count traffic clones or/and views.
  2. Can use GitHub composite action to reuse workflow code base: https://docs.github.com/en/actions/creating-actions/creating-a-composite-action

GitHub workflow file example:

.github/workflows/accum-gh-clone-stats.yml


Previous implementation (marked as obsolete):

This implementation based on GitHub Actions + statistic accumulation into separate repository: https://github.com/andry81-devops/github-clone-count-badge

based on: https://github.com/MShawon/github-clone-count-badge

With some advantages:

  1. Repository to track and repository to store traffic statistic are different, and you may directly point the statistic as commits list: https://github.com/{{REPO_OWNER}}/{{REPO}}--gh-stats/commits/master/traffic/clones
  2. Workflow is used accum-traffic-clones.sh bash script to accumulate traffic clones
  3. The script accumulates statistic both into a single file and into a set of files grouped by year and allocated per day: traffic/clones/by_year/YYYY/YYYY-MM-DD.json

GitHub workflow file example:

.github/workflows/myrepo-gh-clone-stats.yml

Andry
  • 2,273
  • 29
  • 28
1

Based on VonC and Michele Milidoni answers I've created this bookmarklet which displays downloads statistics of github hosted released binaries.

Note: Because of issues with browsers related to Content Security Policy implementation, bookmarklets can temporarily violate some CSP directives and basically may not function properly when running on github while CSP is enabled.

Though its highly discouraged, you can disable CSP in Firefox as a temporary workaround. Open up about:config and set security.csp.enable to false.

jwaliszko
  • 16,942
  • 22
  • 92
  • 158
1

As already stated, you can get information about your Releases via the API.

For those using WordPress, I developed this plugin: GitHub Release Downloads. It allows you to get the download count, links and more information for releases of GitHub repositories.

To address the original question, the shortcode [grd_count user="User" repo="MyRepo"] will return the number of downloads for a repository. This number corresponds to the sum of all download count values of all releases for one GitHub repository.

Example: Example

IvanRF
  • 7,115
  • 5
  • 47
  • 71
1

Answer from 2019:

  1. For number of clones you can use https://developer.github.com/v3/repos/traffic/#clones (but be aware that it returns count only for last 14 days)
  2. For get downloads number of your assets (files attached to the release), you can use https://developer.github.com/v3/repos/releases/#get-a-single-release (exactly "download_count" property of the items of assets list in response)
Ahmed Ashour
  • 5,179
  • 10
  • 35
  • 56
Ustin
  • 568
  • 6
  • 19
1

There's a nice Chrome extension that does exactly what you want: GitHub Release Downloads

enter image description here

Max_Payne
  • 142
  • 1
  • 1
  • 12
  • That's only for the latest release? – SBF Jan 21 '23 at 16:50
  • @SBF idr, as this extension died after a couple of days when GH did some modifications to the template. At the moment I'm directly fetching GH API via console. Here's the parser: https://gist.github.com/iusmac/77066a9ea6829b3b6c0e4005868c8d50 – Max_Payne Jan 21 '23 at 18:25
0

Here is a python solution using the pip install PyGithub package

from github import Github
g = Github("youroauth key") #create token from settings page


for repo in g.get_user().get_repos():
    if repo.name == "yourreponame":
        releases = repo.get_releases()
        for i in releases:
            if i.tag_name == "yourtagname":
                for j in i.get_assets():
                    print("{} date: {} download count: {}".format(j.name, j.updated_at, j._download_count.value))
user1767754
  • 23,311
  • 18
  • 141
  • 164
0

Yes, on GitHub Cloud a traffic option is added under insight section where we could find the repository clone and download information. Here is the link of official doc> https://docs.github.com/en/repositories/viewing-activity-and-data-for-your-repository/viewing-traffic-to-a-repository

Rashid
  • 343
  • 4
  • 14