{"id":23440857,"url":"https://github.com/living-with-machines/gh_orgstats","last_synced_at":"2026-02-24T01:11:14.293Z","repository":{"id":38312643,"uuid":"317568391","full_name":"Living-with-machines/gh_orgstats","owner":"Living-with-machines","description":"GitHub stats for Github Organizations","archived":false,"fork":false,"pushed_at":"2024-10-28T18:55:44.000Z","size":1162,"stargazers_count":3,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-27T12:33:35.029Z","etag":null,"topics":["github","github-api"],"latest_commit_sha":null,"homepage":"https://living-with-machines.github.io/gh_orgstats/","language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Living-with-machines.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-12-01T14:32:39.000Z","updated_at":"2025-09-30T03:18:05.000Z","dependencies_parsed_at":"2025-02-15T12:44:44.777Z","dependency_job_id":"9019785d-6074-4601-a561-e67824706717","html_url":"https://github.com/Living-with-machines/gh_orgstats","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":"fastai/nbdev_template","purl":"pkg:github/Living-with-machines/gh_orgstats","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Living-with-machines%2Fgh_orgstats","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Living-with-machines%2Fgh_orgstats/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Living-with-machines%2Fgh_orgstats/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Living-with-machines%2Fgh_orgstats/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Living-with-machines","download_url":"https://codeload.github.com/Living-with-machines/gh_orgstats/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Living-with-machines%2Fgh_orgstats/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29765745,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-23T21:02:23.375Z","status":"ssl_error","status_checked_at":"2026-02-23T20:58:31.539Z","response_time":90,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["github","github-api"],"created_at":"2024-12-23T16:19:22.696Z","updated_at":"2026-02-24T01:11:14.264Z","avatar_url":"https://github.com/Living-with-machines.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Github OrgStats\n\n\n\n![CI](https://github.com/Living-with-machines/gh_orgstats/workflows/CI/badge.svg)\n\n`gh_orgstats` is intended to provide some easy ways of getting stats for a GitHub org. `gh_orgstats` does this by wrapping some functions around [PyGithub](https://github.com/PyGithub/PyGithub). This code is mainly intended to help generate reports as part of a GitHub actions pipeline to update stats for a funder. For an example of this being used for generating a weekly report see the [Living with Machines Github stats report](https://github.com/Living-with-machines/github_stats_report)\n\nTo use `PyGithub` we need to authenticate with GitHub this is done via a token. This token is used to authenticate access and requires at least scope for public repos. See https://github.com/settings/tokens to register a token. \n\n```\nfrom dotenv import load_dotenv\nimport os\n```\n\nIn this case we use `dotenv` to load the token from a `.env` files. \n\n```\nload_dotenv()\nGH_TOKEN = os.getenv(\"GH_TOKEN\")\n```\n\nCurrently all functionality is contained within the `stats` module. \n\n```\nfrom gh_orgstats.stats import *\n```\n\nThe `OrgStats` class is used to get stats for a GitHub organization. To create an instance of this class we need to pass a GitHub token to authenticate and the name of the Organization you want stats for. \n\n```\ntest_org = OrgStats(GH_TOKEN, \"ghorgstatstestorg\")\ntest_org\n```\n\n\n\n\n    OrgStats: ghorgstatstestorg \n\n\n\n### Organization repositories \nAs a start we can grab the repositories for an organization via the `repos` attribute of our OrgStats instance\n\n```\ntest_org.repos\n```\n\n\n\n\n    [Repository(full_name=\"ghorgstatstestorg/repo1\"),\n     Repository(full_name=\"ghorgstatstestorg/repo2\"),\n     Repository(full_name=\"ghorgstatstestorg/private_repo_1\")]\n\n\n\nWe can also get a sense of what is in the repository by looking at the file extensions for each repository. \n\n### Repository file types\n\n```\ntest_org.get_org_file_ext_frequency()\n```\n\n\n\n\n    {'repo1': {'.md': 1},\n     'repo2': {'.md': 1, '.py': 1},\n     'private_repo_1': {'.md': 1}}\n\n\n\n#### Filtering by publication status \n\nWe can also filter this by publication status\n\n```\ntest_org.get_org_file_ext_frequency(pub_status='public')\n```\n\n\n\n\n    {'repo1': {'.md': 1}, 'repo2': {'.md': 1, '.py': 1}}\n\n\n\n### Snapshot stats\nSnapshot stats are captured based on the current view and aren't updated. These include forks and clones\n\n```\ntest_org.snapshot_stats.to_dict()\n```\n\n\n\n\n    {'stars': {'repo1': 1, 'repo2': 0}, 'forks': {'repo1': 0, 'repo2': 0}}\n\n\n\n### Traffic stats\nWe can also get a longer view by using traffic stats for views and clones\n\n```\ntest_org.get_org_views_traffic(save_dir='readme_dir')\n```\n\n`get_org_views_traffic` will grab data via the GitHub api and update a CSV for each repository under the organization (by default only public) with views counts. This is largely intended to be used to semi-regularly update these stats by running this code as part of a GitHub Action or cron job.\n\n\nIf you want to load a DataFrame of traffic you can pass `load=True`\n\n```\ntest_org.get_org_views_traffic(save_dir='readme_dir', load=True).to_dict()\n```\n\n\n\n\n    {('repo1', 'total_views'): {Timestamp('2020-11-30 00:00:00'): 2,\n      Timestamp('2020-12-01 00:00:00'): 1},\n     ('repo1', 'unique_views'): {Timestamp('2020-11-30 00:00:00'): 1,\n      Timestamp('2020-12-01 00:00:00'): 1},\n     ('repo2', 'total_views'): {Timestamp('2020-11-30 00:00:00'): 8.0,\n      Timestamp('2020-12-01 00:00:00'): nan},\n     ('repo2', 'unique_views'): {Timestamp('2020-11-30 00:00:00'): 1.0,\n      Timestamp('2020-12-01 00:00:00'): nan}}\n\n\n\nSimilarly the same can be done for clones\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fliving-with-machines%2Fgh_orgstats","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fliving-with-machines%2Fgh_orgstats","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fliving-with-machines%2Fgh_orgstats/lists"}