{"id":15292776,"url":"https://github.com/soda480/github3api","last_synced_at":"2025-04-13T10:31:20.585Z","repository":{"id":45437445,"uuid":"292395132","full_name":"soda480/github3api","owner":"soda480","description":"An advanced REST and GraphQL client for the GitHub API.","archived":false,"fork":false,"pushed_at":"2024-03-22T21:22:07.000Z","size":75,"stargazers_count":15,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-27T01:51:33.059Z","etag":null,"topics":["docker","github","github-api","graphql","pybuilder","python","rest-api","rest-client"],"latest_commit_sha":null,"homepage":"","language":"Python","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/soda480.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"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-09-02T21:09:16.000Z","updated_at":"2025-02-01T18:57:19.000Z","dependencies_parsed_at":"2024-03-22T22:28:39.603Z","dependency_job_id":"673c002b-0447-489d-80e0-b41f60f77b93","html_url":"https://github.com/soda480/github3api","commit_stats":{"total_commits":31,"total_committers":2,"mean_commits":15.5,"dds":0.09677419354838712,"last_synced_commit":"d9950424a753f7e0f1bf6691618b0d46328199eb"},"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soda480%2Fgithub3api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soda480%2Fgithub3api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soda480%2Fgithub3api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soda480%2Fgithub3api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/soda480","download_url":"https://codeload.github.com/soda480/github3api/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248698855,"owners_count":21147543,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["docker","github","github-api","graphql","pybuilder","python","rest-api","rest-client"],"created_at":"2024-09-30T16:26:54.476Z","updated_at":"2025-04-13T10:31:20.355Z","avatar_url":"https://github.com/soda480.png","language":"Python","readme":"# github3api\n[![GitHub Workflow Status](https://github.com/soda480/github3api/workflows/build/badge.svg)](https://github.com/soda480/github3api/actions)\n[![coverage](https://img.shields.io/badge/coverage-100%25-brightgreen)](https://pybuilder.io/)\n[![complexity](https://img.shields.io/badge/complexity-A-brightgreen)](https://radon.readthedocs.io/en/latest/api.html#module-radon.complexity)\n[![vulnerabilities](https://img.shields.io/badge/vulnerabilities-None-brightgreen)](https://pypi.org/project/bandit/)\n[![PyPI version](https://badge.fury.io/py/github3api.svg)](https://app.codiga.io/public/project/13337/github3api/dashboard)\n[![python](https://img.shields.io/badge/python-3.7%20%7C%203.8%20%7C%203.9%20%7C%203.10-teal)](https://www.python.org/downloads/)\n\nAn advanced REST client for the GitHub API. It is a subclass of [rest3client](https://pypi.org/project/rest3client/) tailored for the GitHub API with special optional directives for GET requests that can return all pages from an endpoint or return a generator that can be iterated over (for paged requests). By default all requests will be retried if ratelimit request limit is reached.\n\nSupport for executing Graphql queries including paging; Graphql queries are also retried if Graphql rate limiting occurs.\n\n\n### Installation\n```bash\npip install github3api\n```\n\n### Example Usage\n\n```python\n\u003e\u003e\u003e from github3api import GitHubAPI\n```\n\n`GitHubAPI` instantiation\n```python\n# instantiate using no-auth\n\u003e\u003e\u003e client = GitHubAPI()\n\n# instantiate using a token\n\u003e\u003e\u003e client = GitHubAPI(bearer_token='****************')\n```\n\n`GET` request\n```python\n# GET request - return JSON response\n\u003e\u003e\u003e client.get('/rate_limit')['resources']['core']\n{'limit': 60, 'remaining': 37, 'reset': 1588898701}\n\n# GET request - return raw resonse\n\u003e\u003e\u003e client.get('/rate_limit', raw_response=True)\n\u003cResponse [200]\u003e\n```\n\n`POST` request\n```python\n\u003e\u003e\u003e client.post('/user/repos', json={'name': 'test-repo1'})['full_name']\n'soda480/test-repo1'\n\n\u003e\u003e\u003e client.post('/repos/soda480/test-repo1/labels', json={'name': 'label1'})['url']\n'https://api.github.com/repos/soda480/test-repo1/labels/label1'\n```\n\n`PATCH` request\n```python\n\u003e\u003e\u003e client.patch('/repos/soda480/test-repo1/labels/label1', json={'description': 'my label'})['url']\n'https://api.github.com/repos/soda480/test-repo1/labels/label1'\n```\n\n`DELETE` request\n```python \n\u003e\u003e\u003e client.delete('/repos/soda480/test-repo1')\n```\n\n`GET all` directive - Get all pages from an endpoint and return list containing only matching attributes\n```python\nfor repo in client.get('/orgs/edgexfoundry/repos', _get='all', _attributes=['full_name']):\n    print(repo['full_name'])\n```\n\n`GET page` directive - Yield a page from endpoint\n```python\nfor page in client.get('/user/repos', _get='page'):\n    for repo in page:\n        print(repo['full_name'])\n```\n\n`total` - Get total number of resources at given endpoint\n```python\nprint(client.total('/user/repos'))\n```\n\n`graphql` - execute graphql query\n```python\nquery = \"\"\"\n  query($query:String!, $page_size:Int!) {\n    search(query: $query, type: REPOSITORY, first: $page_size) {\n      repositoryCount\n      edges {\n        node {\n          ... on Repository {\n            nameWithOwner\n          }\n        }\n      }\n    }\n  }\n\"\"\"\nvariables = {\"query\": \"org:edgexfoundry\", \"page_size\":100}\nclient.graphql(query, variables)\n```\n\n`graphql paging` - execute paged graphql query\n```python\nquery = \"\"\"\n  query ($query: String!, $page_size: Int!, $cursor: String!) {\n    search(query: $query, type: REPOSITORY, first: $page_size, after: $cursor) {\n      repositoryCount\n      pageInfo {\n        endCursor\n        hasNextPage\n      }\n      edges {\n        cursor\n        node {\n          ... on Repository {\n            nameWithOwner\n          }\n        }\n      }\n    }\n  }\n\"\"\"\nvariables = {\"query\": \"org:edgexfoundry\", \"page_size\":100}\nfor page in client.graphql(query, variables, page=True, keys='data.search'):\n    for repo in page:\n        print(repo['node']['nameWithOwner'])\n```\n\nFor Graphql paged queries:\n- the query should include the necessary pageInfo and cursor attributes\n- the keys method argument is a dot annotated string that is used to access the resulting dictionary response object\n- the query is retried every 60 seconds (for up to an hour) if a ratelimit occur\n\n### Projects using `github3api`\n\n* [edgexfoundry/sync-github-labels](https://github.com/edgexfoundry/cd-management/tree/git-label-sync) A script that synchronizes GitHub labels and milestones\n\n* [edgexfoundry/prune-github-tags](https://github.com/edgexfoundry/cd-management/tree/prune-github-tags) A script that prunes GitHub pre-release tags\n\n* [edgexfoundry/create-github-release](https://github.com/edgexfoundry/cd-management/tree/create-github-release) A script to facilitate creation of GitHub releases\n\n* [soda480/prepbadge](https://github.com/soda480/prepbadge) A script that creates multiple pull request workflows to update a target organization repos with badges\n\n* [soda480/github-contributions](https://github.com/soda480/github-contributions) A script to get contribution metrics for all members of a GitHub organization using the GitHub GraphQL API\n\n* [edgexfoundry/edgex-dev-badge](https://github.com/edgexfoundry/edgex-dev-badge) Rules based GitHub badge scanner\n\n### Development\n\nEnsure the latest version of Docker is installed on your development server. Fork and clone the repository.\n\nBuild the Docker image:\n```sh\ndocker image build \\\n--target build-image \\\n--build-arg http_proxy \\\n--build-arg https_proxy \\\n-t \\\ngithub3api:latest .\n```\n\nRun the Docker container:\n```sh\ndocker container run \\\n--rm \\\n-it \\\n-e http_proxy \\\n-e https_proxy \\\n-v $PWD:/code \\\ngithub3api:latest \\\nbash\n```\n\nExecute the build:\n```sh\npyb -X\n```\n\nNOTE: commands above assume working behind a proxy, if not then the proxy arguments to both the docker build and run commands can be removed.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoda480%2Fgithub3api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsoda480%2Fgithub3api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoda480%2Fgithub3api/lists"}